| | 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 | |
|
| | 7 | | static 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 |
| 0 | 13 | | static Function TAP_AreAllFunctionsSkip() |
| | 14 | |
|
| 0 | 15 | | variable dimPos |
| | 16 | |
|
| 0 | 17 | | WAVE/T testRunData = IUTF_Basics#GetTestRunData() |
| 0 | 18 | | dimPos = FindDimLabel(testRunData, UTF_COLUMN, "SKIP") |
| 0 | 19 | | Duplicate/FREE/R=[][dimPos, dimPos] testRunData, skipCol |
| | 20 | |
|
| 0 | 21 | | return DimSize(testRunData, UTF_ROW) == sum(skipCol) |
| 0 | 22 | | End |
| | 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 |
| 0 | 28 | | static Function TAP_IsFunctionTodo(funcName) |
| | 29 | | string funcName |
| | 30 | |
|
| 0 | 31 | | variable err |
| 0 | 32 | | string str |
| | 33 | |
|
| 0 | 34 | | str = IUTF_FunctionTags#GetFunctionTagValue(funcName, UTF_FTAG_TAP_DIRECTIVE, err) |
| 0 | 35 | | if(!err) |
| 0 | 36 | | return strsearch(str, "TODO", 0, 2) == 0 |
| 0 | 37 | | endif |
| | 38 | |
|
| 0 | 39 | | return 0 |
| 0 | 40 | | End |
| | 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 |
| 79 | 46 | | static Function TAP_IsFunctionSkip(funcName) |
| | 47 | | string funcName |
| | 48 | |
|
| 79 | 49 | | variable err |
| 79 | 50 | | string str |
| | 51 | |
|
| 79 | 52 | | str = IUTF_FunctionTags#GetFunctionTagValue(funcName, UTF_FTAG_TAP_DIRECTIVE, err) |
| 79 | 53 | | if(err == UTF_TAG_OK) |
| 0 | 54 | | return strsearch(str, "SKIP", 0, 2) == 0 |
| 79 | 55 | | endif |
| | 56 | |
|
| 79 | 57 | | return 0 |
| 79 | 58 | | End |
| | 59 | |
|
| 0 | 60 | | static Function/S TAP_GetValidDirective(str) |
| | 61 | | string str |
| | 62 | |
|
| 0 | 63 | | str = ReplaceString("#", str, "_") |
| 0 | 64 | | if(!IUTF_Utils#IsEmpty(str)) |
| 0 | 65 | | str = " # " + str |
| 0 | 66 | | endif |
| | 67 | |
|
| 0 | 68 | | return str |
| 0 | 69 | | End |
| | 70 | |
|
| | 71 | | /// If a TAP Description starts with a digit (which is invalid), add a '_' at the front |
| 0 | 72 | | static Function/S TAP_GetValidDescription(str) |
| | 73 | | string str |
| | 74 | |
|
| 0 | 75 | | str = ReplaceString("#", str, "_") |
| 0 | 76 | | if(!IUTF_Utils#IsEmpty(str)) |
| 0 | 77 | | str = " - " + str |
| 0 | 78 | | endif |
| | 79 | |
|
| 0 | 80 | | return str |
| 0 | 81 | | End |
| | 82 | |
|
| | 83 | | /// Converts generic diagnostic text to a valid TAP diagnostic text |
| 0 | 84 | | static Function/S TAP_ValidDiagnostic(diag) |
| | 85 | | string diag |
| | 86 | |
|
| 0 | 87 | | if(IUTF_Utils#IsEmpty(diag)) |
| 0 | 88 | | return diag |
| 0 | 89 | | endif |
| 0 | 90 | | // diagnostic message may start with 'ok' or 'not ok' in a line which are TAP keywords |
| 0 | 91 | | // so we add a "#" to each line |
| 0 | 92 | | diag = "# " + diag |
| 0 | 93 | | diag = ReplaceString("\r\n", diag, "\r") |
| 0 | 94 | | diag = ReplaceString("\r", diag, TAP_LINEEND_STR + "# ") |
| 0 | 95 | | diag = ReplaceString("\n", diag, TAP_LINEEND_STR + "# ") |
| 0 | 96 | | diag = diag[0, strlen(diag) - 3] |
| 0 | 97 | | return diag |
| 0 | 98 | | End |
| | 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. |
| 0 | 106 | | static Function/S TAP_ToTestCaseString(testCaseIndex, caseCount) |
| | 107 | | variable testCaseIndex |
| | 108 | | variable caseCount |
| | 109 | |
|
| 0 | 110 | | string name, out, ok, diagnostics, description, directive, caseCountStr, msg, prefix |
| 0 | 111 | | variable err |
| | 112 | |
|
| 0 | 113 | | WAVE/T wvTestCase = IUTF_Reporting#GetTestCaseWave() |
| 0 | 114 | | name = wvTestCase[testCaseIndex][%NAME] |
| 0 | 115 | | diagnostics = wvTestCase[testCaseIndex][%STDERR] |
| 0 | 116 | | directive = IUTF_FunctionTags#GetFunctionTagValue(name, UTF_FTAG_TAP_DIRECTIVE, err) |
| 0 | 117 | | if(err != UTF_TAG_OK) |
| 0 | 118 | | directive = "" |
| 0 | 119 | | endif |
| 0 | 120 | | description = IUTF_FunctionTags#GetFunctionTagValue(name, UTF_FTAG_TAP_DESCRIPTION, err) |
| 0 | 121 | | if(err != UTF_TAG_OK) |
| 0 | 122 | | description = "" |
| 0 | 123 | | endif |
| | 124 | |
|
| 0 | 125 | | directive = TAP_GetValidDirective(directive) |
| 0 | 126 | | description = TAP_GetValidDescription(description) |
| | 127 | |
|
| 0 | 128 | | WAVE/T wvTestSuite = IUTF_Reporting#GetTestSuiteWave() |
| 0 | 129 | | sprintf prefix, "%s (%s)", ReplaceString("#", name, ":"), wvTestSuite[%CURRENT][%PROCEDURENAME] |
| | 130 | |
|
| 0 | 131 | | strswitch(wvTestCase[testCaseIndex][%STATUS]) |
| 0 | 132 | | case IUTF_STATUS_SKIP: |
| 0 | 133 | | ok = "ok" |
| 0 | 134 | | diagnostics = "" |
| 0 | 135 | | break |
| 0 | 136 | | case IUTF_STATUS_RETRY: |
| 0 | 137 | | case IUTF_STATUS_SUCCESS: |
| 0 | 138 | | ok = "ok" |
| 0 | 139 | | diagnostics = TAP_ValidDiagnostic(diagnostics) |
| 0 | 140 | | break |
| 0 | 141 | | case IUTF_STATUS_ERROR: |
| 0 | 142 | | case IUTF_STATUS_FAIL: |
| 0 | 143 | | ok = "not ok" |
| 0 | 144 | | diagnostics = TAP_ValidDiagnostic(diagnostics) |
| 0 | 145 | | break |
| 0 | 146 | | default: |
| 0 | 147 | | sprintf msg, "Error: Unknown test status %s for test case %s (%d)", wvTestCase[testCaseIndex][%STATUS], name, test |
| 0 | 148 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 0 | 149 | | return "" |
| 0 | 150 | | endswitch |
| | 151 | |
|
| 0 | 152 | | sprintf caseCountStr, "%d", caseCount |
| 0 | 153 | | out = ok + " " + caseCountStr + " - " + prefix + description + directive + TAP_LINEEND_STR |
| 0 | 154 | | out += diagnostics |
| | 155 | |
|
| 0 | 156 | | return out |
| 0 | 157 | | End |
| | 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. |
| 0 | 166 | | static Function/S TAP_ToSuiteString(testSuiteIndex, caseCount) |
| | 167 | | variable testSuiteIndex |
| | 168 | | variable &caseCount |
| | 169 | |
|
| 0 | 170 | | variable childStart, childEnd, i |
| 0 | 171 | | string s = "" |
| | 172 | |
|
| 0 | 173 | | WAVE/T wvTestSuite = IUTF_Reporting#GetTestSuiteWave() |
| 0 | 174 | | childStart = str2num(wvTestSuite[testSuiteIndex][%CHILD_START]) |
| 0 | 175 | | childEnd = str2num(wvTestSuite[testSuiteIndex][%CHILD_END]) |
| | 176 | |
|
| 0 | 177 | | for(i = childStart; i < childEnd; i += 1) |
| 0 | 178 | | s += TAP_ToTestCaseString(i, caseCount) |
| 0 | 179 | | caseCount += 1 |
| 0 | 180 | | endfor |
| | 181 | |
|
| 0 | 182 | | return s |
| 0 | 183 | | End |
| | 184 | |
|
| 0 | 185 | | static Function TAP_Write() |
| | 186 | |
|
| 0 | 187 | | variable fnum, i, childStart, childEnd |
| 0 | 188 | | string filename, s, msg |
| 0 | 189 | | variable caseCount = 1 |
| | 190 | |
|
| 0 | 191 | | filename = IUTF_Utils_Paths#AtHome("tap_" + GetBaseFilename() + ".log", unusedName = 1) |
| | 192 | |
|
| 0 | 193 | | open/Z fnum as filename |
| 0 | 194 | | if(V_flag) |
| 0 | 195 | | sprintf msg, "Error: Could not create TAP output file at %s", filename |
| 0 | 196 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 0 | 197 | | return NaN |
| 0 | 198 | | endif |
| | 199 | |
|
| 0 | 200 | | WAVE/T wvTestRun = IUTF_Reporting#GetTestRunWave() |
| 0 | 201 | | childStart = str2num(wvTestRun[%CURRENT][%CHILD_START]) |
| 0 | 202 | | childEnd = str2num(wvTestRun[%CURRENT][%CHILD_END]) |
| | 203 | |
|
| 0 | 204 | | s = "TAP version 13" + TAP_LINEEND_STR |
| | 205 | |
|
| 0 | 206 | | if(!CmpStr(wvTestRun[%CURRENT][%NUM_TESTS], wvTestRun[%CURRENT][%NUM_SKIPPED])) |
| 0 | 207 | | s += "1..0 All test cases marked SKIP" + TAP_LINEEND_STR |
| 0 | 208 | | else |
| 0 | 209 | | s += "1.." + wvTestRun[%CURRENT][%NUM_TESTS] + TAP_LINEEND_STR |
| 0 | 210 | | endif |
| | 211 | |
|
| 0 | 212 | | for(i = childStart; i < childEnd; i += 1) |
| 0 | 213 | | s += TAP_ToSuiteString(i, caseCount) |
| 0 | 214 | | endfor |
| | 215 | |
|
| 0 | 216 | | if(shouldDoAbort()) |
| 0 | 217 | | s += "Bail out!" + TAP_LINEEND_STR |
| 0 | 218 | | endif |
| | 219 | |
|
| 0 | 220 | | fBinWrite fnum, s |
| 0 | 221 | | close fnum |
| 0 | 222 | | End |