< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-functiontags
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-functiontags.ipf
Tag: 74147b3
Line coverage
64%
Covered lines: 92
Uncovered lines: 51
Coverable lines: 143
Total lines: 239
Line coverage: 64.3%
Branch coverage
66%
Covered branches: 12
Total branches: 18
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/builds/mirror/igortest/procedures/igortest-functiontags.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_FunctionTags
 6
 7/// @brief Returns a global wave that stores the Function Tag Waves of this testrun
 848static Function/WAVE GetFunctionTagWaves()
 9
 8410  string name = "FunctionTagWaves"
 11
 8412  DFREF       dfr = GetPackageFolder()
 8413  WAVE/Z/WAVE wv  = dfr:$name
 8414  if(WaveExists(wv))
 7815    return wv
 616  endif
 17
 618  Make/WAVE/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv
 619  IUTF_Utils_Vector#SetLength(wv, 0)
 20
 621  return wv
 8422End
 23
 24/// @brief Returns a global wave that stores the full function names at the same position as their
 25/// tag waves. This is used to find the references easier.
 40626static Function/WAVE GetFunctionTagRefs()
 40627  string name = "FunctionTagRefs"
 28
 40629  DFREF    dfr = GetPackageFolder()
 40630  WAVE/Z/T wv  = dfr:$name
 40631  if(WaveExists(wv))
 40032    return wv
 633  endif
 34
 635  Make/T/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv
 636  IUTF_Utils_Vector#SetLength(wv, 0)
 37
 638  return wv
 40639End
 40
 7941static Function AddFunctionTagWave(fullFuncName)
 42  string fullFuncName
 43
 7944  variable index
 45
 7946  WAVE/WAVE ftagWaves = GetFunctionTagWaves()
 7947  WAVE/T    ftagRefs  = GetFunctionTagRefs()
 7948  WAVE/T    tags      = GetFunctionTagWave(fullFuncName)
 7949  if(!DimSize(tags, UTF_ROW))
 7950    return NaN
 051  endif
 52
 053  index           = IUTF_Utils_Vector#AddRow(ftagRefs)
 054  ftagRefs[index] = fullFuncName
 055  IUTF_Utils_Vector#EnsureCapacity(ftagWaves, index)
 056  ftagWaves[index] = tags
 7957End
 58
 59/// @brief Find the current index in the global function tag wave reference wave.
 60///
 61/// @param fullFuncName  the full function name
 62///
 63/// @returns The index inside the function tag wave reference wave. -1 if not found.
 32264static Function GetFunctionTagRef(fullFuncName)
 65  string fullFuncName
 66
 32267  WAVE/T ftagRefs = GetFunctionTagRefs()
 68
 32269  return IUTF_Utils_Vector#FindText(ftagRefs, fullFuncName)
 32270End
 71
 72/// @brief returns 1 if the comments above a function contain a certain tag, zero otherwise
 73///
 74/// @param funcName function name
 75/// @param tagName  tag that is searched (see FunctionTagStrings for possible tags)
 76/// @returns        1 if the comments above a function contain a certain tag, zero otherwise
 24377static Function HasFunctionTag(funcName, tagName)
 78  string funcName, tagName
 79
 24380  variable funcPos = GetFunctionTagRef(funcName)
 81
 24382  if(funcPos == -1)
 24383    return 0
 084  endif
 85
 086  WAVE/WAVE ftagWaves = GetFunctionTagWaves()
 087  WAVE      tagValues = ftagWaves[funcPos]
 88
 089  return (FindDimLabel(tagValues, UTF_ROW, tagName) != -2)
 24390End
 91
 92/// @brief returns the value belonging to a certain tag in the comments above a function.
 93/// In case of an error, returns a detailed error message instead.
 94///
 95/// @param[in]  funcName function name
 96/// @param[in]  tagName  tag that is searched (see FunctionTagStrings for possible tags)
 97/// @param[out] err      error code (see constants UTF_TAG*)
 98/// @returns             value belonging to a certain tag in the comments above a function, error message if not found
 7999static Function/S GetFunctionTagValue(funcName, tagName, err)
 100  string funcName, tagName
 101  variable &err
 102
 79103  variable tagPosition
 79104  string tagValue, msg
 79105  variable funcPos = GetFunctionTagRef(funcName)
 106
 79107  err = UTF_TAG_ABORTED
 79108  if(funcPos == -1)
 79109    err = UTF_TAG_NOT_FOUND
 79110    sprintf msg, "The tag %s was not found.", tagName
 79111    return msg
 0112  endif
 113
 0114  WAVE/WAVE ftagWaves    = GetFunctionTagWaves()
 0115  WAVE/T    tagValueWave = ftagWaves[funcPos]
 0116  tagPosition = FindDimLabel(tagValueWave, UTF_ROW, tagName)
 0117  if(tagPosition == -2)
 0118    err = UTF_TAG_NOT_FOUND
 0119    sprintf msg, "The tag %s was not found.", tagName
 0120    return msg
 0121  endif
 122
 0123  tagValue = tagValueWave[tagPosition]
 0124  if(IUTF_Utils#IsEmpty(tagValue))
 0125    err = UTF_TAG_EMPTY
 0126    sprintf msg, "The tag %s has no value.", tagName
 0127    return msg
 0128  endif
 129
 0130  err = UTF_TAG_OK
 131
 0132  return tagValue
 79133End
 134
 135/// @brief returns a wave consisting of function tags (see FunctionTagStrings)
 79136static Function/WAVE GetTagConstants()
 137
 79138  Make/T/FREE tagConstants = {UTF_FTAG_NOINSTRUMENTATION, UTF_FTAG_TD_GENERATOR, UTF_FTAG_EXPECTED_FAILURE, UTF_FTAG_SKI
 139
 79140  return tagConstants
 79141End
 142
 143/// @brief Checks if the line has the specified function/procedure tag.
 144///
 145/// @param tag         The function/procedure tag to check
 146/// @param line        The line to search tag
 147/// @param[out] value  The value of the tag if found, otherwise an empty string
 148///
 149/// @returns 1 if tag matched, 0 if not
 1840150static Function IsTagMatch(tag, line, value)
 151  string tag, line
 152  string &value
 153
 1840154  string expr, tagValue
 155
 1840156  value = ""
 157
 1840158  if(CmpStr("IUTF_", tag[0, 4]))
 460159    // function tags that do not use the IUTF_ prefix
 460160    expr = "\/{2,}[[:space:]]*\\Q" + tag + "\\E(?::)?(.*)$"
 1380161  else
 1380162    // compatibility layer to allow the deprecated UTF_ and the new IUTF_ prefix for
 1380163    // function tags
 1380164    expr = "\/{2,}[[:space:]]*I?\\Q" + tag[1, Inf] + "\\E(?::)?(.*)$"
 1840165  endif
 166
 1840167  SplitString/E=expr line, tagValue
 1840168  if(V_flag != 1)
 1840169    return 0
 0170  endif
 171
 0172  value = tagValue
 0173  return 1
 1840174End
 175
 176/// @brief Reads the function tags in the comments preceding the function keyword
 177/// returns a wave containing the tag values with their tag names as dimLabel
 178/// see FunctionTagStrings for possible tags
 179///
 180/// @param funcName Name of function
 181/// @returns        a wave containing the tag values with their tag names as dimLabel
 79182static Function/WAVE GetFunctionTagWave(funcName)
 183  string funcName
 184
 79185  string msg, expr, funcText, funcTextWithoutContext, funcTextWithContext, funcLine, tagName, tagValue, varName, allVarL
 79186  variable i, j, numUniqueTags, numLines, numFound
 79187  WAVE/T tag_constants = GetTagConstants()
 188
 79189  WAVE templates = IUTF_Test_MD_MMD#GetMMDVarTemplates()
 79190  numUniqueTags = DimSize(tag_constants, UTF_ROW)
 191
 79192  numFound = 0
 193
 79194  funcTextWithContext    = ProcedureText(funcName, -1, "[" + GetIndependentModuleName() + "]")
 79195  funcTextWithoutContext = ProcedureText(funcName, 0, "[" + GetIndependentModuleName() + "]")
 79196  funcText               = ReplaceString(funcTextWithoutContext, funcTextWithContext, "")
 79197  numLines               = ItemsInList(funcText, "\r")
 198
 79199  Make/FREE/T/N=(numLines) tagValueWave
 200
 79201  for(i = numLines - 1; numLines > 0 && i >= 0; i -= 1)
 230202    funcLine = StringFromList(i, funcText, "\r")
 230203    if(IUTF_Utils#IsEmpty(funcLine))
 0204      continue
 230205    endif
 206
 230207    for(j = 0; j < numUniqueTags; j += 1)
 1840208      tagName = tag_constants[j]
 1840209      if(!IsTagMatch(tagName, funcLine, tagValue))
 1840210        continue
 0211      endif
 212
 0213      tagValue = TrimString(tagValue)
 0214      if(FindDimLabel(tagValueWave, 0, tagName) != -2)
 0215        sprintf msg, "Test case %s has the tag %s at least twice.", funcName, tagValue
 0216        IUTF_Reporting#ReportErrorAndAbort(msg)
 0217      endif
 218
 0219      if(!CmpStr(tagName, UTF_FTAG_TD_GENERATOR) && ItemsInList(tagValue, ":") == 2)
 0220        varName    = StringFromList(0, tagvalue, ":")
 0221        tagName    = UTF_FTAG_TD_GENERATOR + " " + varName
 0222        allVarList = IUTF_Test_MD_MMD#GetMMDAllVariablesList()
 0223        if(WhichListItem(varName, allVarList, ";", 0, 0) == -1)
 0224          sprintf msg, "Test case %s uses an unknown variable name %s in the tag %s.", funcName, varName, tagValue
 0225          IUTF_Reporting#ReportErrorAndAbort(msg)
 0226        endif
 0227        tagValue = StringFromList(1, tagvalue, ":")
 0228      endif
 229
 0230      tagValueWave[numFound] = tagValue
 0231      SetDimLabel UTF_ROW, numFound, $tagName, tagValueWave
 0232      numfound += 1
 0233      break
 0234    endfor
 230235  endfor
 236
 79237  Redimension/N=(numFound) tagValueWave
 79238  return tagValueWave
 79239End