Skip to content

Commit 9939187

Browse files
committed
better test suite for older matlab
1 parent c93bedd commit 9939187

File tree

8 files changed

+38
-40
lines changed

8 files changed

+38
-40
lines changed

+stdlib/filename.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
% filename (including suffix) without directory
77

88
function f = filename(p, backend)
9-
arguments
10-
p
11-
backend = 'fileparts'
9+
if nargin < 2
10+
backend = 'fileparts';
1211
end
1312

1413
% fileparts is 5x to 10x faster than regexp and pattern

private/releaseTestTags.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
end
1111

1212
releasesKnown = [
13-
"R2019b", "R2020a", "R2020b", "R2021a", "R2021b", ...
14-
"R2022a", "R2022b", "R2023a", "R2023b", "R2024a", ...
15-
"R2024b", "R2025a", "R2025b"];
13+
"R2019a", "R2019b", "R2020a", "R2020b", ...
14+
"R2021a", "R2021b", "R2022a", "R2022b", ...
15+
"R2023a", "R2023b", "R2024a", "R2024b", ...
16+
"R2025a", "R2025b"];
1617

1718
% takes releases not newer than this release
1819
idx = find(releasesKnown >= r, 1, 'first');

test/TestAbsolute.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2019b', 'impure'}) ...
2+
TestTags = {'R2019a', 'impure'}) ...
33
TestAbsolute < matlab.unittest.TestCase
44

55
properties (TestParameter)

test/TestFilename.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2019b', 'pure'}) ...
2+
TestTags = {'R2019a', 'pure'}) ...
33
TestFilename < matlab.unittest.TestCase
44

55
properties (TestParameter)

test/TestIsAbsolute.m

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2019b', 'pure'}) ...
2+
TestTags = {'R2019a', 'pure'}) ...
33
TestIsAbsolute < matlab.unittest.TestCase
44

55
properties (TestParameter)
6-
p = {{"", false}, {"x", false}, {"x:", false}}
7-
pu = {{"x:/foo", false}, {"/foo", true}}
8-
pw = {{"x:/foo", true}, {"/foo", false}}
6+
p = init_p()
97
end
108

119

@@ -17,27 +15,16 @@ function test_is_absolute(tc, p)
1715
end
1816

1917
end
20-
21-
22-
methods (Test, TestTags={'unix'})
23-
24-
function test_is_absolute_unix(tc, pu)
25-
tc.assumeTrue(isunix())
26-
ok = stdlib.is_absolute(pu{1});
27-
tc.verifyEqual(ok, pu{2}, pu{1})
2818
end
2919

30-
end
3120

21+
function p = init_p()
22+
p = {{"", false}, {"x", false}, {"x:", false}};
3223

33-
methods (Test, TestTags={'windows'})
34-
35-
function test_is_absolute_windows(tc, pw)
36-
tc.assumeTrue(ispc())
37-
ok = stdlib.is_absolute(pw{1});
38-
tc.verifyEqual(ok, pw{2}, pw{1})
39-
end
40-
24+
if ispc()
25+
p = [p, {{"x:/foo", true}, {"/foo", false}}];
26+
else
27+
p = [p, {{"x:/foo", false}, {"/foo", true}}];
4128
end
4229

4330
end

test/TestStem.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'pure'}) ...
2+
TestTags = {'R2019a', 'pure'}) ...
33
TestStem < matlab.unittest.TestCase
44

55
properties (TestParameter)
@@ -19,7 +19,7 @@
1919
end
2020

2121

22-
methods (Test, TestTags={'R2019b'})
22+
methods (Test)
2323

2424
function test_stem(tc, p)
2525
tc.verifyEqual(stdlib.stem(p{1}), p{2})

test/TestSuffix.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'pure'}) ...
2+
TestTags = {'R2019a', 'pure'}) ...
33
TestSuffix < matlab.unittest.TestCase
44

55
properties (TestParameter)
@@ -14,7 +14,7 @@
1414
end
1515

1616

17-
methods (Test, TestTags={'R2019b'})
17+
methods (Test)
1818

1919
function test_suffix(tc, p)
2020
r = stdlib.suffix(p{1});

test_main.m

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
% Matlab >= R2020a recommended
44

55
function test_main(context, sel)
6-
arguments
7-
context = []
8-
sel = ~HasTag("exe") & ~HasTag("java_exe")
6+
if nargin < 1
7+
context = [];
8+
end
9+
if nargin < 2
10+
sel = (~HasTag("exe") & ~HasTag("java_exe")) | HasTag("native_exe");
911
end
1012

1113
import matlab.unittest.TestRunner
@@ -18,20 +20,29 @@ function test_main(context, sel)
1820
end
1921
test_root = fullfile(cwd, "test");
2022

21-
tags = ["native_exe", releaseTestTags()];
23+
rtags = releaseTestTags();
2224

2325
try
24-
suite = testsuite(test_root, 'Tag', tags, 'InvalidFileFoundAction', "error");
26+
suite = testsuite(test_root, 'Tag', rtags, 'InvalidFileFoundAction', "error");
2527
catch e
2628
if e.identifier ~= "MATLAB:InputParser:UnmatchedParameter"
2729
rethrow(e)
2830
end
2931

3032
try
31-
suite = testsuite(test_root, 'Tag', tags);
33+
suite = testsuite(test_root, 'Tag', rtags);
3234
catch e
3335
if e.identifier == "MATLAB:expectedScalartext"
34-
suite = testsuite(test_root, 'Tag', "R2019b");
36+
suite = testsuite(test_root);
37+
38+
assert(numel(rtags) > 0, "No test tags found for this Matlab release")
39+
ts = HasTag(rtags(1));
40+
if numel(rtags) > 1
41+
for t = rtags(2:end)
42+
ts = ts | HasTag(t);
43+
end
44+
end
45+
sel = sel & ts;
3546
else
3647
rethrow(e)
3748
end

0 commit comments

Comments
 (0)