Skip to content

Commit c0821d1

Browse files
committed
simplify test_main.m
1 parent e9feffe commit c0821d1

3 files changed

Lines changed: 8 additions & 28 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ These rules apply under the namespace "stdlib" (directory +stdlib/) and all its
4444

4545
- The code syntax must work for Matlab >= R2020b
4646
- The code must not require any Matlab toolboxes, only base Matlab functionality
47-
- Prohibited to use Matlab factory function "isMATLABReleaseOlderThan()" as it is slow. Instead we use stdlib.matlabOlderThan() which is like 200x faster than isMATLABReleaseOlderThan() and works for Matlab >= R2016b
47+
- Prohibited to use Matlab factory function "isMATLABReleaseOlderThan()" as it is slow, except in ./test_main.m or ./buildfile.m. Instead we use stdlib.matlabOlderThan() which is like 200x faster than isMATLABReleaseOlderThan() and works for Matlab >= R2016b
4848
- When an exception is encountered, we generally desire that the code return an "empty" value of the appropriate type. In certain cases we may throw or rethrow an error.
4949
- where the output represents a filesystem path, the output should be a string type if any input is string type, otherwise char type.
5050

scripts/test_matlab_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ def test_matlab_version(version):
3838
elif version >= "2019a":
3939
cmd = lcmd + "matlab -batch test_main"
4040
else:
41-
cmd = lcmd + "matlab -r 'test_main; exit'"
41+
cmd = lcmd + "matlab -batch 'test_main'"
4242

4343
subprocess.check_call(cmd, shell=True, cwd=R)

test_main.m

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,14 @@ function test_main(context, sel)
4646

4747
rtags = releaseTestTags();
4848

49-
try
50-
suite = testsuite(test_root, 'Tag', rtags, 'InvalidFileFoundAction', 'error');
51-
catch e
52-
if ~strcmp(e.identifier, 'MATLAB:InputParser:UnmatchedParameter')
53-
rethrow(e)
54-
end
55-
56-
try
57-
suite = testsuite(test_root, 'Tag', rtags);
58-
catch e
59-
switch e.identifier
60-
case {'MATLAB:expectedScalartext', 'MATLAB:expectedScalar'}
61-
suite = testsuite(test_root);
62-
63-
assert(numel(rtags) > 0, 'No test tags found for this Matlab release')
64-
ts = HasTag(rtags(1));
65-
if numel(rtags) > 1
66-
for t = rtags(2:end)
67-
ts = ts | HasTag(t);
68-
end
69-
end
70-
sel = sel & ts;
71-
otherwise
72-
rethrow(e)
73-
end
74-
end
49+
if isMATLABReleaseOlderThan("R2022b")
50+
eact = {};
51+
else
52+
eact = {'InvalidFileFoundAction', 'error'};
7553
end
7654

55+
suite = testsuite(test_root, 'Tag', rtags, eact{:});
56+
7757
% selectIf takes the subset of suite tests that meet 'sel' conditions
7858
suite = suite.selectIf(sel);
7959

0 commit comments

Comments
 (0)