|
13 | 13 | fprintf([' \\_____| \\_____/ |_____/ |_| \\_\\ |_| |_| |\n']);
|
14 | 14 | fprintf(' | \n\n');
|
15 | 15 |
|
| 16 | +% Define CI boolean |
| 17 | +CIenv = false; |
| 18 | + |
16 | 19 | % request explicitly from the user to launch test suite locally
|
17 |
| -% if contains(getenv('HOME'), 'vmhadmin') || contains(getenv('HOME'), 'jenkins') |
18 | 20 | if contains(getenv('HOME'), 'saleh')
|
19 | 21 | % Running in CI environment
|
20 |
| -% fprintf('Running test in Jenkins/CI environment\n'); |
21 |
| - fprintf('Running test in cobratoolbox/CI environment\n'); |
22 |
| - |
| 22 | + fprintf('Running test in cobratoolbox/CI environment\n'); |
| 23 | + |
| 24 | + % Set CI boolean to true |
| 25 | + CIenv = true; |
| 26 | + |
23 | 27 | % on the CI, always reset the path to make absolutely sure, that we test
|
24 | 28 | % the current version
|
25 | 29 | restoredefaultpath;
|
|
29 | 33 | while isempty(reply)
|
30 | 34 | reply = input([' -> Do you want to launch the test suite locally? Time estimate: more than 60 minutes Y/N: '], 's');
|
31 | 35 | end
|
32 |
| - |
| 36 | + |
33 | 37 | if strcmpi(reply, 'y') || strcmpi(reply, 'yes')
|
34 | 38 | launchTestSuite = true;
|
35 | 39 | else
|
|
74 | 78 | testDirContent = getFilesInDir('type', 'all'); % Get all currently present files in the folder.
|
75 | 79 | testDirPath = pwd;
|
76 | 80 | cd(currentDir);
|
77 |
| -%{ |
| 81 | + %{ |
78 | 82 | if ~isempty(strfind(getenv('HOME'), 'jenkins')) || ~isempty(strfind(getenv('USERPROFILE'), 'jenkins'))
|
79 | 83 | WAITBAR_TYPE = 0;
|
80 | 84 |
|
|
86 | 90 | else
|
87 | 91 | WAITBAR_TYPE = 1;
|
88 | 92 | end
|
89 |
| -%} |
| 93 | + %} |
90 | 94 | if verLessThan('matlab', '8.2')
|
91 | 95 | error('The testsuite of The COBRA Toolbox can only be run with MATLAB R2014b+.')
|
92 | 96 | end
|
|
102 | 106 | % only retain the lines that end with .txt and .m and
|
103 | 107 | % are not comments and point to files in the /src folder
|
104 | 108 | ignoredPatterns = {'^.{0,3}$', ... % Is smaller than four.
|
105 |
| - ['^[^s][^r][^c][^' regexptranslate('escape', filesep) ']']}; % does not start with src/ |
| 109 | + ['^[^s][^r][^c][^' regexptranslate('escape', filesep) ']']}; % does not start with src/ |
106 | 110 | filterPatterns = {'\.txt$', '\.m$'}; % Is either a .m file or a .txt file.
|
107 | 111 | ignoreFiles = getIgnoredFiles(ignoredPatterns, filterPatterns);
|
108 | 112 |
|
|
122 | 126 | while ~feof(fid)
|
123 | 127 | lineOfFile = strtrim(char(fgetl(fid)));
|
124 | 128 | if length(lineOfFile) > 0 && length(strfind(lineOfFile(1), '%')) ~= 1 ...
|
125 |
| - && length(strfind(lineOfFile, 'end')) ~= 1 && length(strfind(lineOfFile, 'otherwise')) ~= 1 ... |
126 |
| - && length(strfind(lineOfFile, 'switch')) ~= 1 && length(strfind(lineOfFile, 'else')) ~= 1 ... |
127 |
| - && length(strfind(lineOfFile, 'case')) ~= 1 && length(strfind(lineOfFile, 'function')) ~= 1 |
128 |
| - nCodeLines = nCodeLines + 1; |
| 129 | + && length(strfind(lineOfFile, 'end')) ~= 1 && length(strfind(lineOfFile, 'otherwise')) ~= 1 ... |
| 130 | + && length(strfind(lineOfFile, 'switch')) ~= 1 && length(strfind(lineOfFile, 'else')) ~= 1 ... |
| 131 | + && length(strfind(lineOfFile, 'case')) ~= 1 && length(strfind(lineOfFile, 'function')) ~= 1 |
| 132 | + nCodeLines = nCodeLines + 1; |
129 | 133 |
|
130 | 134 | elseif length(lineOfFile) == 0
|
131 | 135 | nEmptyLines = nEmptyLines + 1;
|
|
142 | 146 |
|
143 | 147 | grades = {'A', 'B', 'C', 'D', 'E', 'F'};
|
144 | 148 | intervals = [0, 3;
|
145 |
| - 3, 6; |
146 |
| - 6, 9; |
147 |
| - 9, 12; |
148 |
| - 12, 15; |
149 |
| - 15, 100]; |
| 149 | + 3, 6; |
| 150 | + 6, 9; |
| 151 | + 9, 12; |
| 152 | + 12, 15; |
| 153 | + 15, 100]; |
150 | 154 |
|
151 | 155 | grade = 'F';
|
152 | 156 | for i = 1:length(intervals)
|
|
182 | 186 | sumFailed = sum(resultTable.Failed);
|
183 | 187 |
|
184 | 188 | fprintf(['\n > ', num2str(sumFailed), ' tests failed. ', num2str(sumSkipped), ' tests were skipped due to missing requirements.\n\n']);
|
185 |
| - %% NEW: Generate JUnit XML report for Codecov |
186 |
| - |
187 |
| - xmlFileName = 'testReport.junit.xml'; |
188 | 189 |
|
189 |
| - fid = fopen(xmlFileName, 'w'); |
190 |
| - if fid == -1 |
191 |
| - error('Could not open file for writing: %s', xmlFileName); |
192 |
| - end |
| 190 | + if CIenv |
| 191 | + %% NEW: Generate JUnit XML report for Codecov |
193 | 192 |
|
194 |
| - fprintf(fid, '<?xml version="1.0" encoding="UTF-8"?>\n'); |
| 193 | + xmlFileName = 'testReport.junit.xml'; |
195 | 194 |
|
196 |
| - numTests = height(resultTable); |
197 |
| - numFailures = sum(resultTable.Failed); |
198 |
| - numErrors = sum(resultTable.Failed); |
199 |
| - numSkipped = sum(resultTable.Skipped); |
| 195 | + fid = fopen(xmlFileName, 'w'); |
| 196 | + if fid == -1 |
| 197 | + error('Could not open file for writing: %s', xmlFileName); |
| 198 | + end |
200 | 199 |
|
201 |
| - % Compute total time and also count how many are "failures" vs. "errors" |
202 |
| - totalTime = sum(resultTable.Time); |
| 200 | + fprintf(fid, '<?xml version="1.0" encoding="UTF-8"?>\n'); |
203 | 201 |
|
204 |
| - % 1) Wrap in <testsuites> -- typical JUnit format |
205 |
| - fprintf(fid, '<testsuites name="COBRA Toolbox Test Suites" tests="%d" failures="%d" errors="%d" time="%.3f">\n', ... |
206 |
| - numTests, numFailures, numErrors, totalTime); |
| 202 | + numTests = height(resultTable); |
| 203 | + numFailures = sum(resultTable.Failed); |
| 204 | + numErrors = sum(resultTable.Failed); |
| 205 | + numSkipped = sum(resultTable.Skipped); |
207 | 206 |
|
208 |
| - % 2) A single <testsuite> inside |
209 |
| - fprintf(fid, ' <testsuite name="COBRA Toolbox Test Suite" tests="%d" failures="%d" errors="%d" skipped="%d" time="%.3f">\n', ... |
210 |
| - numTests, numFailures, numErrors, numSkipped, totalTime); |
| 207 | + % Compute total time and also count how many are "failures" vs. "errors" |
| 208 | + totalTime = sum(resultTable.Time); |
211 | 209 |
|
212 |
| - % 3) Loop over each test case |
213 |
| - for i = 1:numTests |
214 |
| - testName = resultTable.TestName{i}; |
215 |
| - if isnan(resultTable.Time(i)) |
216 |
| - tVal = 0; |
217 |
| - else |
218 |
| - tVal = resultTable.Time(i); |
219 |
| - end |
| 210 | + % 1) Wrap in <testsuites> -- typical JUnit format |
| 211 | + fprintf(fid, '<testsuites name="COBRA Toolbox Test Suites" tests="%d" failures="%d" errors="%d" time="%.3f">\n', ... |
| 212 | + numTests, numFailures, numErrors, totalTime); |
220 | 213 |
|
221 |
| - % Start the <testcase> tag |
222 |
| - fprintf(fid, ' <testcase classname="COBRA Toolbox" name="%s" time="%.3f"', testName, tVal); |
223 |
| - |
224 |
| - if resultTable.Passed(i) |
225 |
| - % Passed => just close |
226 |
| - fprintf(fid, '/>\n'); |
227 |
| - elseif resultTable.Skipped(i) |
228 |
| - % Skipped => <skipped/> |
229 |
| - fprintf(fid, '>\n'); |
230 |
| - fprintf(fid, ' <skipped message="%s"/>\n', escapeXML(resultTable.Details{i})); |
231 |
| - fprintf(fid, ' </testcase>\n'); |
232 |
| - else |
233 |
| - % Not passed, not skipped => either <failure> or <error> |
234 |
| - % Check the .Error or .Details to decide |
235 |
| - errMsg = result(i).Error.message; % or getReport() |
236 |
| - |
237 |
| - % Heuristic: if "Assertion" => <failure>, else <error>. |
238 |
| - if contains(errMsg, 'Assertion') || contains(errMsg, 'assert') |
239 |
| - fprintf(fid, '>\n'); |
240 |
| - fprintf(fid, ' <failure message="%s"/>\n', escapeXML(errMsg)); |
| 214 | + % 2) A single <testsuite> inside |
| 215 | + fprintf(fid, ' <testsuite name="COBRA Toolbox Test Suite" tests="%d" failures="%d" errors="%d" skipped="%d" time="%.3f">\n', ... |
| 216 | + numTests, numFailures, numErrors, numSkipped, totalTime); |
| 217 | + |
| 218 | + % 3) Loop over each test case |
| 219 | + for i = 1:numTests |
| 220 | + testName = resultTable.TestName{i}; |
| 221 | + if isnan(resultTable.Time(i)) |
| 222 | + tVal = 0; |
241 | 223 | else
|
242 |
| - fprintf(fid, '>\n'); |
243 |
| - fprintf(fid, ' <error message="%s"/>\n', escapeXML(errMsg)); |
| 224 | + tVal = resultTable.Time(i); |
244 | 225 | end
|
245 | 226 |
|
246 |
| - fprintf(fid, ' </testcase>\n'); |
| 227 | + % Start the <testcase> tag |
| 228 | + fprintf(fid, ' <testcase name="%s" time="%.3f"', testName, tVal); |
| 229 | + |
| 230 | + if resultTable.Passed(i) |
| 231 | + % Passed => just close |
| 232 | + fprintf(fid, '/>\n'); |
| 233 | + elseif resultTable.Skipped(i) |
| 234 | + % Skipped => <skipped/> |
| 235 | + fprintf(fid, '>\n'); |
| 236 | + fprintf(fid, ' <skipped message="%s"/>\n', escapeXML(resultTable.Details{i})); |
| 237 | + fprintf(fid, ' </testcase>\n'); |
| 238 | + else |
| 239 | + % Not passed, not skipped => either <failure> or <error> |
| 240 | + % Check the .Error or .Details to decide |
| 241 | + errMsg = result(i).Error.message; % or getReport() |
| 242 | + |
| 243 | + % Heuristic: if "Assertion" => <failure>, else <error>. |
| 244 | + if contains(errMsg, 'Assertion') || contains(errMsg, 'assert') |
| 245 | + fprintf(fid, '>\n'); |
| 246 | + fprintf(fid, ' <failure message="%s"/>\n', escapeXML(errMsg)); |
| 247 | + else |
| 248 | + fprintf(fid, '>\n'); |
| 249 | + fprintf(fid, ' <error message="%s"/>\n', escapeXML(errMsg)); |
| 250 | + end |
| 251 | + |
| 252 | + fprintf(fid, ' </testcase>\n'); |
| 253 | + end |
247 | 254 | end
|
248 |
| - end |
249 | 255 |
|
250 |
| - % Close out the suite and suites |
251 |
| - fprintf(fid, ' </testsuite>\n'); |
252 |
| - fprintf(fid, '</testsuites>\n'); |
253 |
| - fclose(fid); |
| 256 | + % Close out the suite and suites |
| 257 | + fprintf(fid, ' </testsuite>\n'); |
| 258 | + fprintf(fid, '</testsuites>\n'); |
| 259 | + fclose(fid); |
| 260 | + end |
254 | 261 | %% End of XML generation
|
255 | 262 |
|
256 | 263 | % count the number of covered lines of code
|
|
364 | 371 |
|
365 | 372 | %% Local helper function to escape XML special characters.
|
366 | 373 | function out = escapeXML(in)
|
367 |
| - if isempty(in) |
368 |
| - out = ''; |
369 |
| - return; |
370 |
| - end |
371 |
| - out = strrep(in, '&', '&'); |
372 |
| - out = strrep(out, '<', '<'); |
373 |
| - out = strrep(out, '>', '>'); |
374 |
| - out = strrep(out, '"', '"'); |
375 |
| - out = strrep(out, '''', '''); |
| 374 | +if isempty(in) |
| 375 | + out = ''; |
| 376 | + return; |
| 377 | +end |
| 378 | +out = strrep(in, '&', '&'); |
| 379 | +out = strrep(out, '<', '<'); |
| 380 | +out = strrep(out, '>', '>'); |
| 381 | +out = strrep(out, '"', '"'); |
| 382 | +out = strrep(out, '''', '''); |
376 | 383 | end
|
0 commit comments