< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-tap
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-tap.ipf
Tag: 74147b3
Line coverage
5%
Covered lines: 8
Uncovered lines: 128
Coverable lines: 136
Total lines: 222
Line coverage: 5.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

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

#LineLine coverage
 1#pragma TextEncoding="UTF-8"
 2#pragma rtGlobals=3 // Use modern global access method and strict wave access.
 3#pragma rtFunctionErrors=1
 4#pragma version=1.10
 5#pragma ModuleName=IUTF_Tap
 6
 7static StrConstant TAP_LINEEND_STR = "\n"
 8
 9/// @brief returns 1 if all test cases are marked as SKIP and TAP is enabled, zero otherwise
 10///
 11/// @param testCaseList list of function names
 12/// @returns 1 if all test cases are marked as SKIP and TAP is enabled, zero otherwise
 013static Function TAP_AreAllFunctionsSkip()
 14
 015  variable dimPos
 16
 017  WAVE/T testRunData = IUTF_Basics#GetTestRunData()
 018  dimPos = FindDimLabel(testRunData, UTF_COLUMN, "SKIP")
 019  Duplicate/FREE/R=[][dimPos, dimPos] testRunData, skipCol
 20
 021  return DimSize(testRunData, UTF_ROW) == sum(skipCol)
 022End
 23
 24/// @brief returns 1 if function is marked as TODO, zero otherwise
 25///
 26/// @param funcName name of function
 27/// @returns 1 if function is marked as TODO, zero otherwise
 028static Function TAP_IsFunctionTodo(funcName)
 29  string funcName
 30
 031  variable err
 032  string   str
 33
 034  str = IUTF_FunctionTags#GetFunctionTagValue(funcName, UTF_FTAG_TAP_DIRECTIVE, err)
 035  if(!err)
 036    return strsearch(str, "TODO", 0, 2) == 0
 037  endif
 38
 039  return 0
 040End
 41
 42/// @brief returns 1 if function is marked as SKIP, zero otherwise
 43///
 44/// @param funcName name of function
 45/// @returns 1 if function is marked as SKIP, zero otherwise
 7946static Function TAP_IsFunctionSkip(funcName)
 47  string funcName
 48
 7949  variable err
 7950  string   str
 51
 7952  str = IUTF_FunctionTags#GetFunctionTagValue(funcName, UTF_FTAG_TAP_DIRECTIVE, err)
 7953  if(err == UTF_TAG_OK)
 054    return strsearch(str, "SKIP", 0, 2) == 0
 7955  endif
 56
 7957  return 0
 7958End
 59
 060static Function/S TAP_GetValidDirective(str)
 61  string str
 62
 063  str = ReplaceString("#", str, "_")
 064  if(!IUTF_Utils#IsEmpty(str))
 065    str = " # " + str
 066  endif
 67
 068  return str
 069End
 70
 71/// If a TAP Description starts with a digit (which is invalid), add a '_' at the front
 072static Function/S TAP_GetValidDescription(str)
 73  string str
 74
 075  str = ReplaceString("#", str, "_")
 076  if(!IUTF_Utils#IsEmpty(str))
 077    str = " - " + str
 078  endif
 79
 080  return str
 081End
 82
 83/// Converts generic diagnostic text to a valid TAP diagnostic text
 084static Function/S TAP_ValidDiagnostic(diag)
 85  string diag
 86
 087  if(IUTF_Utils#IsEmpty(diag))
 088    return diag
 089  endif
 090  // diagnostic message may start with 'ok' or 'not ok' in a line which are TAP keywords
 091  // so we add a "#" to each line
 092  diag = "# " + diag
 093  diag = ReplaceString("\r\n", diag, "\r")
 094  diag = ReplaceString("\r", diag, TAP_LINEEND_STR + "# ")
 095  diag = ReplaceString("\n", diag, TAP_LINEEND_STR + "# ")
 096  diag = diag[0, strlen(diag) - 3]
 097  return diag
 098End
 99
 100/// @brief Converts a test case into TAP text
 101///
 102/// @param testCaseIndex     The index of the current test case inside the results wave
 103/// @param[in,out] caseCount The current number of printed test cases. This is used as all test
 104///                          cases need their own unique index and TAP has no concept of test
 105///                          suites. This function wont update this number.
 0106static Function/S TAP_ToTestCaseString(testCaseIndex, caseCount)
 107  variable testCaseIndex
 108  variable caseCount
 109
 0110  string name, out, ok, diagnostics, description, directive, caseCountStr, msg, prefix
 0111  variable err
 112
 0113  WAVE/T wvTestCase = IUTF_Reporting#GetTestCaseWave()
 0114  name        = wvTestCase[testCaseIndex][%NAME]
 0115  diagnostics = wvTestCase[testCaseIndex][%STDERR]
 0116  directive   = IUTF_FunctionTags#GetFunctionTagValue(name, UTF_FTAG_TAP_DIRECTIVE, err)
 0117  if(err != UTF_TAG_OK)
 0118    directive = ""
 0119  endif
 0120  description = IUTF_FunctionTags#GetFunctionTagValue(name, UTF_FTAG_TAP_DESCRIPTION, err)
 0121  if(err != UTF_TAG_OK)
 0122    description = ""
 0123  endif
 124
 0125  directive   = TAP_GetValidDirective(directive)
 0126  description = TAP_GetValidDescription(description)
 127
 0128  WAVE/T wvTestSuite = IUTF_Reporting#GetTestSuiteWave()
 0129  sprintf prefix, "%s (%s)", ReplaceString("#", name, ":"), wvTestSuite[%CURRENT][%PROCEDURENAME]
 130
 0131  strswitch(wvTestCase[testCaseIndex][%STATUS])
 0132    case IUTF_STATUS_SKIP:
 0133      ok          = "ok"
 0134      diagnostics = ""
 0135      break
 0136    case IUTF_STATUS_RETRY:
 0137    case IUTF_STATUS_SUCCESS:
 0138      ok          = "ok"
 0139      diagnostics = TAP_ValidDiagnostic(diagnostics)
 0140      break
 0141    case IUTF_STATUS_ERROR:
 0142    case IUTF_STATUS_FAIL:
 0143      ok          = "not ok"
 0144      diagnostics = TAP_ValidDiagnostic(diagnostics)
 0145      break
 0146    default:
 0147      sprintf msg, "Error: Unknown test status %s for test case %s (%d)", wvTestCase[testCaseIndex][%STATUS], name, test
 0148      IUTF_Reporting#IUTF_PrintStatusMessage(msg)
 0149      return ""
 0150  endswitch
 151
 0152  sprintf caseCountStr, "%d", caseCount
 0153  out  = ok + " " + caseCountStr + " - " + prefix + description + directive + TAP_LINEEND_STR
 0154  out += diagnostics
 155
 0156  return out
 0157End
 158
 159/// @brief Converts a test suite into TAP text
 160///
 161/// @param testSuiteIndex    The index of the current test suite inside the results wave
 162/// @param[in,out] caseCount The current number of printed test cases. This is used as all test
 163///                          cases need their own unique index and TAP has no concept of test
 164///                          suites. After this function call this parameter is updated to the new
 165///                          number of printed test cases.
 0166static Function/S TAP_ToSuiteString(testSuiteIndex, caseCount)
 167  variable  testSuiteIndex
 168  variable &caseCount
 169
 0170  variable childStart, childEnd, i
 0171  string s = ""
 172
 0173  WAVE/T wvTestSuite = IUTF_Reporting#GetTestSuiteWave()
 0174  childStart = str2num(wvTestSuite[testSuiteIndex][%CHILD_START])
 0175  childEnd   = str2num(wvTestSuite[testSuiteIndex][%CHILD_END])
 176
 0177  for(i = childStart; i < childEnd; i += 1)
 0178    s         += TAP_ToTestCaseString(i, caseCount)
 0179    caseCount += 1
 0180  endfor
 181
 0182  return s
 0183End
 184
 0185static Function TAP_Write()
 186
 0187  variable fnum, i, childStart, childEnd
 0188  string filename, s, msg
 0189  variable caseCount = 1
 190
 0191  filename = IUTF_Utils_Paths#AtHome("tap_" + GetBaseFilename() + ".log", unusedName = 1)
 192
 0193  open/Z fnum as filename
 0194  if(V_flag)
 0195    sprintf msg, "Error: Could not create TAP output file at %s", filename
 0196    IUTF_Reporting#IUTF_PrintStatusMessage(msg)
 0197    return NaN
 0198  endif
 199
 0200  WAVE/T wvTestRun = IUTF_Reporting#GetTestRunWave()
 0201  childStart = str2num(wvTestRun[%CURRENT][%CHILD_START])
 0202  childEnd   = str2num(wvTestRun[%CURRENT][%CHILD_END])
 203
 0204  s = "TAP version 13" + TAP_LINEEND_STR
 205
 0206  if(!CmpStr(wvTestRun[%CURRENT][%NUM_TESTS], wvTestRun[%CURRENT][%NUM_SKIPPED]))
 0207    s += "1..0 All test cases marked SKIP" + TAP_LINEEND_STR
 0208  else
 0209    s += "1.." + wvTestRun[%CURRENT][%NUM_TESTS] + TAP_LINEEND_STR
 0210  endif
 211
 0212  for(i = childStart; i < childEnd; i += 1)
 0213    s += TAP_ToSuiteString(i, caseCount)
 0214  endfor
 215
 0216  if(shouldDoAbort())
 0217    s += "Bail out!" + TAP_LINEEND_STR
 0218  endif
 219
 0220  fBinWrite fnum, s
 0221  close fnum
 0222End