-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_main.m
More file actions
92 lines (73 loc) · 1.88 KB
/
test_main.m
File metadata and controls
92 lines (73 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
%% TEST_MAIN Run all tests
function test_main(context, sel)
import matlab.unittest.TestRunner
import matlab.unittest.selectors.HasTag
if nargin < 1
context = [];
end
if nargin < 2
sel = (~HasTag('exe') & ~HasTag('java_exe')) | HasTag('native_exe');
end
if isempty(context)
cwd = fileparts(mfilename('fullpath'));
else
cwd = context.Plan.RootFolder;
end
test_root = strcat(cwd, '/test');
suite = define_suite(test_root, sel);
runner = TestRunner.withTextOutput;
r = runner.run(suite);
assert(~isempty(r), 'No tests were run')
Lf = sum([r.Failed]);
Lok = sum([r.Passed]);
Lk = sum([r.Incomplete]);
Lt = numel(r);
assert(Lf == 0, sprintf('%d / %d tests failed', Lf, Lt))
if Lk
fprintf('%d / %d tests skipped\n', Lk, Lt);
end
fprintf('%d / %d tests succeeded\n', Lok, Lt);
end
function suite = define_suite(test_root, sel)
import matlab.unittest.selectors.HasTag
try
rtags = releaseTestTags();
catch e
% Matlab < R2016b
if strcmp(e.identifier, 'MATLAB:m_illegal_character')
suite = testsuite(test_root);
sel = sel & HasTag('R2016a');
suite = suite.selectIf(sel);
return
else
rethrow(e)
end
end
try
suite = testsuite(test_root, 'Tag', rtags, 'InvalidFileFoundAction', 'error');
catch e
if ~strcmp(e.identifier, 'MATLAB:InputParser:UnmatchedParameter')
rethrow(e)
end
try
suite = testsuite(test_root, 'Tag', rtags);
catch e
switch e.identifier
case {'MATLAB:expectedScalartext', 'MATLAB:expectedScalar'}
suite = testsuite(test_root);
assert(numel(rtags) > 0, 'No test tags found for this Matlab release')
ts = HasTag(rtags(1));
if numel(rtags) > 1
for t = rtags(2:end)
ts = ts | HasTag(t);
end
end
sel = sel & ts;
otherwise
rethrow(e)
end
end
end
% selectIf takes the subset of suite tests that meet 'sel' conditions
suite = suite.selectIf(sel);
end