< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-utils-paths
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-utils-paths.ipf
Tag: 74147b3
Line coverage
68%
Covered lines: 41
Uncovered lines: 19
Coverable lines: 60
Total lines: 112
Line coverage: 68.3%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/builds/mirror/igortest/procedures/igortest-utils-paths.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_Utils_Paths
 6
 7///@cond HIDDEN_SYMBOL
 8
 9/// @brief Clears the current stored home path. The next call to GetHomePath() will return the
 10// current home path.
 511static Function ClearHomePath()
 512  DFREF dfr = GetPackageFolder()
 513  KillStrings/Z dfr:homePath
 514End
 15
 16/// @brief Returns the home path at the start of the execution of RunTest. If this experiment wasn't
 17/// saved at this point it will return an empty string.
 1018static Function/S GetHomePath()
 1019  DFREF dfr = GetPackageFolder()
 1020  SVAR/Z/SDFR=dfr homePath
 21
 1022  if(SVAR_Exists(homePath))
 523    return homePath
 524  endif
 25
 526  PathInfo home
 527  if(V_flag)
 528    string/G dfr:homePath = S_path
 529    return S_path
 030  else
 031    string/G dfr:homePath = ""
 032    return ""
 033  endif
 1034End
 35
 36/// @brief Get the full path of a file at the cached home directory
 37///
 38/// @param fileName  The file name that need to be located in the home directory
 39/// @param unusedName  (optional, default 0=disabled) If set to 1 it will search for an unused file
 40///                    name in the home directory with the same pattern as fileName.
 41///                    If no unused file name could be found this function will abort the execution.
 42///
 43/// @returns The full file path
 544static Function/S AtHome(fileName, [unusedName])
 45  string   fileName
 46  variable unusedName
 47
 548  string result, msg
 49
 550  unusedName = ParamIsDefault(unusedName) ? 0 : !!unusedName
 51
 552  result = GetHomePath() + fileName
 53
 554  if(unusedName)
 555    result = getUnusedFileName(result)
 556    if(IUTF_Utils#IsEmpty(result))
 057      sprintf msg, "Cannot determine unused file for %s at home directory", fileName
 058      IUTF_Reporting#ReportErrorAndAbort(msg)
 559    endif
 560  endif
 61
 562  return result
 563End
 64
 65/// Returns 0 if the file exists, !0 otherwise
 566static Function FileNotExists(fname)
 67  string fname
 68
 569  GetFileFolderInfo/Q/Z fname
 570  return V_Flag
 571End
 72
 73/// returns a non existing file name an empty string
 574static Function/S getUnusedFileName(fname)
 75  string fname
 76
 577  variable count
 578  string fn, fnext, fnn
 79
 580  if(FileNotExists(fname))
 581    return fname
 082  endif
 083  fname = ParseFilePath(5, fname, "\\", 0, 0)
 084  fnext = "." + ParseFilePath(4, fname, "\\", 0, 0)
 085  fnn   = RemoveEnding(fname, fnext)
 86
 087  count = -1
 088  do
 089    count += 1
 090    sprintf fn, "%s_%03d%s", fnn, count, fnext
 091  while(!FileNotExists(fn) && count < 999)
 092  if(!FileNotExists(fn))
 093    return ""
 094  endif
 095  return fn
 596End
 97
 98// Get the directory part of a file with a trailing back-slash
 99//
 100// Examples:
 101// C:\foo\bar\baz.txt  ->  C:\foo\bar\
 102// C:\foo\bar\baz\     ->  C:\foo\bar\
 30103static Function/S GetDirPathOfFile(path)
 104  string path
 105
 30106  path = ParseFilePath(5, path, "\\", 0, 0)
 30107  path = ParseFilePath(1, path, "\\", 1, 0)
 108
 30109  return path
 30110End
 111
 112///@endcond // HIDDEN_SYMBOL