11%% TEST_MAIN Run all tests
2- %
3- % Matlab >= R2020a recommended
42
53function test_main(context , sel )
4+ import matlab .unittest .TestRunner
5+ import matlab .unittest .selectors .HasTag
6+
67if nargin < 1
78 context = [];
89end
910if nargin < 2
1011 sel = (~HasTag(' exe' ) & ~HasTag(' java_exe' )) | HasTag(' native_exe' );
1112end
1213
13- import matlab .unittest .TestRunner
14- import matlab .unittest .selectors .HasTag
1514
1615if isempty(context )
1716 cwd = fileparts(mfilename(' fullpath' ));
@@ -20,12 +19,48 @@ function test_main(context, sel)
2019end
2120test_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
2560try
26- suite = testsuite(test_root , ' Tag' , rtags , ' InvalidFileFoundAction' , " error" );
61+ suite = testsuite(test_root , ' Tag' , rtags , ' InvalidFileFoundAction' , ' error' );
2762catch 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
5186end
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
5489suite = 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-
7391end
0 commit comments