Skip to content

Commit 085991e

Browse files
committed
functionalize
1 parent b802107 commit 085991e

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

test_main.m

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
%% TEST_MAIN Run all tests
2-
%
3-
% Matlab >= R2020a recommended
42

53
function test_main(context, sel)
4+
import matlab.unittest.TestRunner
5+
import matlab.unittest.selectors.HasTag
6+
67
if nargin < 1
78
context = [];
89
end
910
if nargin < 2
1011
sel = (~HasTag('exe') & ~HasTag('java_exe')) | HasTag('native_exe');
1112
end
1213

13-
import matlab.unittest.TestRunner
14-
import matlab.unittest.selectors.HasTag
1514

1615
if isempty(context)
1716
cwd = fileparts(mfilename('fullpath'));
@@ -20,12 +19,48 @@ function test_main(context, sel)
2019
end
2120
test_root = strcat(cwd, '/test');
2221

23-
rtags = releaseTestTags();
22+
suite = define_suite(test_root, sel);
23+
24+
runner = TestRunner.withTextOutput;
25+
r = runner.run(suite);
26+
27+
assert(~isempty(r), 'No tests were run')
28+
29+
Lf = sum([r.Failed]);
30+
Lok = sum([r.Passed]);
31+
Lk = sum([r.Incomplete]);
32+
Lt = numel(r);
33+
assert(Lf == 0, sprintf('%d / %d tests failed', Lf, Lt))
34+
35+
if Lk
36+
fprintf('%d / %d tests skipped\n', Lk, Lt);
37+
end
38+
39+
fprintf('%d / %d tests succeeded\n', Lok, Lt);
40+
41+
end
42+
43+
44+
function suite = define_suite(test_root, sel)
45+
46+
try
47+
rtags = releaseTestTags();
48+
catch e
49+
% Matlab < R2016b
50+
if strcmp(e.identifier, 'MATLAB:m_illegal_character')
51+
suite = testsuite(test_root);
52+
sel = sel & HasTag('R2016a');
53+
suite = suite.selectIf(sel);
54+
return
55+
else
56+
rethrow(e)
57+
end
58+
end
2459

2560
try
26-
suite = testsuite(test_root, 'Tag', rtags, 'InvalidFileFoundAction', "error");
61+
suite = testsuite(test_root, 'Tag', rtags, 'InvalidFileFoundAction', 'error');
2762
catch e
28-
if e.identifier ~= "MATLAB:InputParser:UnmatchedParameter"
63+
if ~strcmp(e.identifier, 'MATLAB:InputParser:UnmatchedParameter')
2964
rethrow(e)
3065
end
3166

@@ -50,24 +85,7 @@ function test_main(context, sel)
5085
end
5186
end
5287

53-
% selectIf takes the subset of suite tests that meet "sel" conditions
88+
% selectIf takes the subset of suite tests that meet 'sel' conditions
5489
suite = suite.selectIf(sel);
5590

56-
runner = TestRunner.withTextOutput;
57-
r = runner.run(suite);
58-
59-
assert(~isempty(r), 'No tests were run')
60-
61-
Lf = sum([r.Failed]);
62-
Lok = sum([r.Passed]);
63-
Lk = sum([r.Incomplete]);
64-
Lt = numel(r);
65-
assert(Lf == 0, sprintf('%d / %d tests failed', Lf, Lt))
66-
67-
if Lk
68-
fprintf('%d / %d tests skipped\n', Lk, Lt);
69-
end
70-
71-
fprintf('%d / %d tests succeeded\n', Lok, Lt);
72-
7391
end

0 commit comments

Comments
 (0)