< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-autorun
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-autorun.ipf
Tag: 74147b3
Line coverage
22%
Covered lines: 22
Uncovered lines: 77
Coverable lines: 99
Total lines: 153
Line coverage: 22.2%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
CreateHistoryLog()100%1100%
GetAutorunMode()100%30%
IUTF_AutoRun#AfterFileOpenHook()100%90%
QuitOnAutoRunFull()100%20%
ClearBaseFilename()100%1100%
GetBaseFilename()100%577.78%
SaveHistoryLog()100%20%

File(s)

/builds/mirror/igortest/procedures/igortest-autorun.ipf

#LineLine coverage
 1#pragma rtGlobals=3
 2#pragma rtFunctionErrors=1
 3#pragma version=1.10
 4#pragma TextEncoding="UTF-8"
 5#pragma ModuleName=IUTF_AutoRun
 6
 7/// Creates a notebook with the special name "HistoryCarbonCopy"
 8/// which will hold a copy of the history
 59Function CreateHistoryLog()
 10
 511  DoWindow/K HistoryCarbonCopy
 512  NewNotebook/V=0/F=0/N=HistoryCarbonCopy
 513End
 14
 15/// Return the type of autorun mode we are in
 16///
 17/// @returns one of @ref AutorunModes
 018Function GetAutorunMode()
 019  string path
 20
 021  path = IUTF_Utils_Paths#AtHome("DO_AUTORUN.TXT")
 022  GetFileFolderInfo/Q/Z path
 23
 024  if(!V_flag)
 025    return AUTORUN_FULL
 026  endif
 27
 028  path = IUTF_Utils_Paths#AtHome("DO_AUTORUN_PLAIN.TXT")
 029  GetFileFolderInfo/Q/Z path
 30
 031  if(!V_flag)
 032    return AUTORUN_PLAIN
 033  endif
 34
 035  return AUTORUN_OFF
 036End
 37
 38/// Hook function which is executed after opening a file
 39///
 40/// This function calls the user supplied run routine if
 41/// - the opened file is an igor experiment
 42/// - the file DO_AUTORUN.TXT exists in the igor home path
 043static Function AfterFileOpenHook(refNum, file, pathName, type, creator, kind)
 44  variable refNum, kind
 45  string file, pathName, type, creator
 46
 047  string funcList, cmd
 048  variable autorunMode, err
 49
 050  string context = GetIndependentModuleName()
 51
 052  // do nothing if the opened file was not an Igor packed/unpacked experiment
 053  if(kind != 1 && kind != 2)
 054    return 0
 055  endif
 56
 057  // Clear previous stored home path before checking the autorun mode. The previous stored home
 058  // path is unlikely the current home path of this experiment and it won't hurt to clear it at
 059  // load time of this experiment.
 060  IUTF_Utils_Paths#ClearHomePath()
 61
 062  autorunMode = GetAutorunMode()
 63
 064  if(autorunMode == AUTORUN_OFF)
 065    return 0
 066  endif
 67
 068  if(autorunMode == AUTORUN_FULL)
 069    CreateHistoryLog()
 070  endif
 71
 072  if(CmpStr("ProcGlobal", context, 1))
 073    Execute "SetIgorOption IndependentModuleDev=1"
 074  endif
 75
 076  funcList = FunctionList("run", ";", "KIND:2,NPARAMS:0,WIN:[" + context + "]")
 077  if(ItemsInList(funcList) >= 1)
 078    FUNCREF AUTORUN_MODE_PROTO f = $StringFromList(0, funcList)
 79
 080    if(IUTF_FuncRefIsAssigned(FuncRefInfo(f)))
 081      try
 082        err = GetRTError(1)
 083        f(); AbortOnRTE
 084      catch
 085        err = GetRTError(1)
 086        print "The run() function aborted with an RTE and this can not be handled."
 087        QuitOnAutoRunFull()
 088      endtry
 089    else
 090      print "The run() function has an invalid signature."
 091    endif
 092  else
 093    print "The requested autorun mode is not possible because the function run() does not exist in " + context + " conte
 094  endif
 095End
 96
 097Function QuitOnAutoRunFull()
 98
 099  string tmpStr
 100
 0101  if(GetAutorunMode() == AUTORUN_FULL)
 0102    sprintf tmpStr, "%s#SaveHistoryLog(); Quit/N", GetIndependentModuleName()
 0103    Execute/P tmpStr
 0104  endif
 0105End
 106
 107/// resets a global filename template string for output
 11108Function ClearBaseFilename()
 11109  DFREF    dfr              = GetPackageFolder()
 11110  string/G dfr:baseFilename = ""
 11111End
 112
 113/// creates a new filename template, if template already present return current
 5114Function/S GetBaseFilename()
 5115  DFREF dfr = GetPackageFolder()
 5116  SVAR/Z/SDFR=dfr baseFilename
 5117  SVAR/Z/SDFR=dfr baseFilenameOverwrite
 118
 5119  if(!SVAR_Exists(baseFilename))
 0120    string/G dfr:baseFilename = ""
 0121    SVAR/SDFR=dfr baseFilename
 5122  endif
 123
 5124  if(!IUTF_Utils#IsEmpty(baseFilename))
 0125    return baseFilename
 5126  endif
 127
 5128  if(SVAR_Exists(baseFilenameOverwrite) && !IUTF_Utils#IsEmpty(baseFilenameOverwrite))
 0129    baseFilename = baseFilenameOverwrite
 5130  else
 5131    sprintf baseFilename, "%s_%s_%s", IgorInfo(1), Secs2Date(DateTime, -2), ReplaceString(":", Secs2Time(DateTime, 3), "
 5132  endif
 133
 5134  return baseFilename
 5135End
 136
 137/// Save the contents of the history notebook on disk
 138/// in the same folder as this experiment as timestamped file "run_*_*.log"
 0139Function SaveHistoryLog()
 140
 0141  string historyLog, msg
 0142  historyLog = GetBaseFilename() + ".log"
 143
 0144  DoWindow HistoryCarbonCopy
 0145  if(V_flag == 0)
 0146    IUTF_Reporting#IUTF_PrintStatusMessage("No log notebook found, please call CreateHistoryLog() before.")
 0147    return NaN
 0148  endif
 149
 0150  historyLog = IUTF_Utils_Paths#AtHome(historyLog, unusedName = 1)
 151
 0152  SaveNoteBook/S=3 HistoryCarbonCopy as historyLog
 0153End