Skip to content

Commit 6e4c824

Browse files
committed
testing more rigorous by having selectable sets of tags
1 parent 1424cf6 commit 6e4c824

File tree

11 files changed

+120
-62
lines changed

11 files changed

+120
-62
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- os: windows-latest
3838
release: R2025a
3939
- os: windows-latest
40-
release: R2023a
40+
release: R2023b
4141

4242

4343
steps:

.github/workflows/composite-mex/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ runs:
77
steps:
88

99
- name: Mex Test
10-
if: ${{ matrix.release >= 'R2023a' || startsWith(matrix.release, 'latest') }}
10+
if: ${{ matrix.release >= 'R2023b' || startsWith(matrix.release, 'latest') }}
1111
uses: matlab-actions/run-build@v2
1212
with:
1313
startup-options: ${{ matrix.startup-options }} -logfile ${{ matrix.release }}-${{ runner.os }}-test.log
14-
tasks: mex test
14+
tasks: ${{ matrix.release < 'R2024b' && !startsWith(matrix.release, 'latest') && 'test_mex' || 'test:mex' }}

.github/workflows/composite-nomex/action.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@ runs:
77
steps:
88

99
- name: Non-Mex Test
10-
if: ${{ matrix.release >= 'R2023a' || startsWith(matrix.release, 'latest') }}
10+
if: ${{ matrix.release >= 'R2024b' || startsWith(matrix.release, 'latest') }}
1111
uses: matlab-actions/run-build@v2
1212
with:
1313
startup-options: ${{ matrix.startup-options }}
14-
tasks: test
14+
tasks: test:nomex ${{ !contains(matrix.startup-options, '-nojvm') && 'test:exe' }}
15+
16+
17+
- name: Non-Mex Test (< R2024b)
18+
if: ${{ matrix.release >= 'R2023b' && matrix.release < 'R2024b' && !startsWith(matrix.release, 'latest') }}
19+
uses: matlab-actions/run-build@v2
20+
with:
21+
startup-options: ${{ matrix.startup-options }}
22+
tasks: test_nomex ${{ !contains(matrix.startup-options, '-nojvm') && 'test_exe' }}
23+
1524

1625
# note: "source-folder" is necessary, but watch out as it adds all subfolders to path too
1726
# https://github.com/matlab-actions/run-tests?tab=readme-ov-file#run-matlab-tests
18-
- name: Run tests (manual)
19-
if: ${{ matrix.release < 'R2023a' && !startsWith(matrix.release, 'latest') }}
20-
uses: matlab-actions/run-tests@v2
27+
- name: Non-mex tests (< R2023b)
28+
if: ${{ matrix.release < 'R2023b' && !startsWith(matrix.release, 'latest') }}
29+
uses: matlab-actions/run-command@v2
2130
with:
22-
source-folder: ${{ github.workspace }}
23-
select-by-folder: test
24-
strict: false
25-
startup-options: -logfile ${{ matrix.release }}-${{ runner.os }}-test.log
31+
command: test_nomex
32+
startup-options: -sd ./test -logfile ${{ matrix.release }}-${{ runner.os }}-test.log
2633

2734

2835
- name: upload logfile

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Filesystem.class
22
CodeIssues.sarif
3-
TestResults.xml
4-
code-coverage.xml
3+
*.xml
54

65
resources/
76
.buildtool/

buildfile.m

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function plan = buildfile
2-
assert(~isMATLABReleaseOlderThan("R2023a"), "MATLAB R2023a or newer is required for this buildfile")
2+
import matlab.unittest.selectors.HasTag
3+
assert(~isMATLABReleaseOlderThan("R2023b"), "MATLAB R2023b or newer is required for this buildfile")
34

45
plan = buildplan(localfunctions);
56

@@ -8,14 +9,37 @@
89
addpath(plan.RootFolder)
910

1011
%% Self-test setup
11-
if isMATLABReleaseOlderThan("R2023b")
12-
plan("test") = matlab.buildtool.Task(Actions=@legacy_test);
13-
elseif isMATLABReleaseOlderThan("R2024a")
14-
plan("test") = matlab.buildtool.tasks.TestTask("test", Strict=false);
12+
plan("clean") = matlab.buildtool.tasks.CleanTask;
13+
14+
cnomex = ~HasTag("exe") & ~HasTag("mex");
15+
cmex = ~HasTag("exe") & HasTag("mex");
16+
17+
if isMATLABReleaseOlderThan("R2024b")
18+
19+
plan("test_exe") = matlab.buildtool.tasks.TestTask("test", Tag="exe", Dependencies="exe");
20+
plan("test_nomex") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cnomex), Dependencies="clean");
21+
plan("test_mex") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cmex), Dependencies="mex");
22+
23+
elseif isMATLABReleaseOlderThan("R2025a")
24+
25+
plan("test:exe") = matlab.buildtool.tasks.TestTask("test", Tag="exe", Dependencies="exe");
26+
plan("test:nomex") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cnomex), Dependencies="clean");
27+
plan("test:mex") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cmex), Dependencies="mex");
28+
1529
else
1630
% can't use SourceFiles= if "mex" Task was run, even if plan("test").DisableIncremental = true;
1731
% this means incremental tests can't be used with MEX files (as of R2024b)
18-
plan("test") = matlab.buildtool.tasks.TestTask("test", Strict=false, TestResults="TestResults.xml");
32+
plan("test:exe") = matlab.buildtool.tasks.TestTask("test", Tag="exe", ...
33+
Dependencies="exe", TestResults="TestResults_exe.xml", Strict=false);
34+
35+
plan("test:nomex") = matlab.buildtool.tasks.TestTask("test", ...
36+
Selector=cnomex, ...
37+
Dependencies="clean", TestResults="TestResults_nomex.xml", Strict=false);
38+
39+
plan("test:mex") = matlab.buildtool.tasks.TestTask("test", ...
40+
Selector=cmex, ...
41+
Dependencies="mex", TestResults="TestResults_mex.xml", Strict=false);
42+
1943
end
2044

2145
td = plan.RootFolder + "/test";
@@ -26,11 +50,6 @@
2650
exes = [exes, td+"/stdout_stderr_fortran.exe", td+"/stdin_fortran.exe"];
2751
end
2852
plan("exe") = matlab.buildtool.Task(Inputs=srcs, Outputs=exes, Actions=@build_exe);
29-
plan("test").Dependencies = "exe";
30-
31-
if ~isMATLABReleaseOlderThan("R2023b")
32-
plan("clean") = matlab.buildtool.tasks.CleanTask;
33-
end
3453

3554
if ~isMATLABReleaseOlderThan("R2024a")
3655
plan("check") = matlab.buildtool.tasks.CodeIssuesTask(pkg_name, IncludeSubfolders=true, ...
@@ -82,9 +101,15 @@ function legacy_mex(context, compiler_opt, linker_opt)
82101
end
83102

84103

85-
function legacy_test(context)
86-
r = runtests(context.Plan.RootFolder + "/test", Strict=false);
87-
% Parallel Computing Toolbox takes more time to startup than is worth it for this task
104+
function legacy_test(context, sel)
105+
import matlab.unittest.TestSuite
106+
107+
suite = TestSuite.fromFolder(context.Plan.RootFolder + "/test");
108+
suite = suite.selectIf(sel);
109+
110+
runner = testrunner();
111+
112+
r = run(runner, suite);
88113

89114
assert(~isempty(r), "No tests were run")
90115
assertSuccess(r)
@@ -256,10 +281,6 @@ function build_exe(context)
256281
if msvc
257282
std = "/std:c++17";
258283
% on Windows, Matlab doesn't register unsupported MSVC or oneAPI
259-
elseif cxx.Name == "Xcode Clang++"
260-
if isMATLABReleaseOlderThan("R2023b") && stdlib.version_atleast(cxx.Version, "15.0")
261-
warning("Xcode Clang++ " + cxx.Version + " may not support this Matlab version")
262-
end
263284
elseif ~strlength(compiler_id) && cxx.ShortName == "g++"
264285
if ~stdlib.version_atleast(cxx.Version, "8")
265286
warning("g++ 8 or newer is required for MEX, detected g++" + cxx.Version)

test/TestDisk.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
Ps = {".", "", "not-exist"}
55
end
66

7+
methods(Test, TestTags = "mex")
8+
9+
function test_mex_disk_available(tc)
10+
import matlab.unittest.constraints.IsFile
11+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/disk_available." + mexext, IsFile)
12+
end
13+
14+
function test_mex_disk_capacity(tc)
15+
import matlab.unittest.constraints.IsFile
16+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/disk_capacity." + mexext, IsFile)
17+
end
18+
19+
end
20+
721
methods (Test)
822

923
function test_disk_available(tc, Ps)
10-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/disk_available." + mexext))
1124

1225
zero = uint64(0);
1326

@@ -19,7 +32,6 @@ function test_disk_available(tc, Ps)
1932
end
2033

2134
function test_disk_capacity(tc, Ps)
22-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/disk_capacity." + mexext))
2335

2436
zero = uint64(0);
2537

test/TestMex.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
classdef TestMex < matlab.unittest.TestCase
22

3-
methods (Test)
3+
methods (Test, TestTags = "mex")
44

55
function test_is_char_device(tc)
6-
7-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/is_char_device." + mexext))
8-
96
% /dev/stdin may not be available on CI systems
107
if ispc
118
n = "NUL";
@@ -18,14 +15,13 @@ function test_is_char_device(tc)
1815

1916

2017
function test_is_admin(tc)
21-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/is_admin." + mexext))
22-
2318
tc.verifyClass(stdlib.is_admin(), "logical")
2419
end
2520

2621

2722
function test_remove_file(tc)
28-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext))
23+
import matlab.unittest.constraints.IsFile
24+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext, IsFile)
2925

3026
d = tc.createTemporaryFolder();
3127

@@ -39,7 +35,8 @@ function test_remove_file(tc)
3935

4036

4137
function test_remove_empty_dir(tc)
42-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext))
38+
import matlab.unittest.constraints.IsFile
39+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext, IsFile)
4340

4441
d = tc.createTemporaryFolder();
4542

@@ -48,7 +45,8 @@ function test_remove_empty_dir(tc)
4845

4946

5047
function test_remove_recursive(tc)
51-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext))
48+
import matlab.unittest.constraints.IsFile
49+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/remove." + mexext, IsFile)
5250

5351
d = tc.createTemporaryFolder();
5452

test/TestPermissions.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
Ps = {".", tempname(), "", "not-exist"}
55
end
66

7+
methods(Test, TestTags = "mex")
8+
9+
function test_mex_set_permissions(tc)
10+
import matlab.unittest.constraints.IsFile
11+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/set_permissions." + mexext, IsFile)
12+
end
13+
14+
15+
end
16+
17+
718
methods (Test)
819

920
function test_get_permissions(tc, Ps)
@@ -26,8 +37,6 @@ function test_set_permissions(tc)
2637

2738
import matlab.unittest.constraints.StartsWithSubstring
2839

29-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/set_permissions." + mexext))
30-
3140
tf = tc.createTemporaryFolder();
3241

3342
nr = fullfile(tf, "no-read");

test/TestRelative.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55
pp = init_prox()
66
end
77

8-
methods(TestClassSetup)
9-
function mex_required(tc)
10-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/relative_to." + mexext))
11-
tc.assumeTrue(isfile(fileparts(mfilename("fullpath")) + "/../+stdlib/proximate_to." + mexext))
12-
end
13-
end
14-
15-
16-
methods (Test)
8+
methods (Test, TestTags = "mex")
179

1810
function test_relative_to(tc, pr)
11+
import matlab.unittest.constraints.IsFile
12+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/relative_to." + mexext, IsFile)
13+
1914
tc.verifyEqual(stdlib.relative_to(pr{1}, pr{2}), pr{3}, ...
2015
"relative_to(" + pr{1} + "," + pr{2}+")")
2116
end
2217

2318
function test_proximate_to(tc, pp)
19+
import matlab.unittest.constraints.IsFile
20+
tc.assertThat(fileparts(mfilename("fullpath")) + "/../+stdlib/proximate_to." + mexext, IsFile)
21+
2422
tc.verifyEqual(stdlib.proximate_to(pp{1}, pp{2}), pp{3}, ...
2523
"proximate_to(" + pp{1} + "," + pp{2}+")")
2624
end

test/TestSubprocess.m

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ function java_required(tc)
1212
end
1313

1414

15-
methods (Test)
15+
methods (Test, TestTags="exe")
1616

1717
function test_stdout_stderr(tc, lang_out)
1818
import matlab.unittest.constraints.IsFile
1919

2020
cwd = fileparts(mfilename('fullpath'));
2121
exe = cwd + "/stdout_stderr_" + lang_out + ".exe";
22-
tc.assumeThat(exe, IsFile, exe + " not found")
22+
tc.assumeThat(exe, IsFile)
2323

2424
[status, msg, err] = stdlib.subprocess_run(exe);
2525
tc.assertEqual(status, 0, err)
@@ -29,11 +29,10 @@ function test_stdout_stderr(tc, lang_out)
2929

3030

3131
function test_stdin(tc, lang_in)
32-
import matlab.unittest.constraints.IsFile
3332

3433
cwd = fileparts(mfilename('fullpath'));
3534
exe = cwd + "/stdin_" + lang_in + ".exe";
36-
tc.assumeThat(exe, IsFile, exe + " not found")
35+
tc.assumeThat(exe, matlab.unittest.constraints.IsFile)
3736

3837
[status, msg, err] = stdlib.subprocess_run(exe, stdin="1 2");
3938

@@ -67,11 +66,10 @@ function test_cwd(tc)
6766

6867

6968
function test_env_run(tc)
70-
import matlab.unittest.constraints.IsFile
7169

7270
cwd = fileparts(mfilename('fullpath'));
7371
exe = cwd + "/printenv.exe";
74-
tc.assumeThat(exe, IsFile, exe + " not found")
72+
tc.assumeThat(exe, matlab.unittest.constraints.IsFile)
7573

7674
names = ["TEST1", "TEST2"];
7775
vals = ["test123", "test321"];
@@ -89,11 +87,10 @@ function test_env_run(tc)
8987

9088
function test_timeout(tc)
9189
import matlab.unittest.constraints.StartsWithSubstring
92-
import matlab.unittest.constraints.IsFile
9390

9491
cwd = fileparts(mfilename('fullpath'));
9592
exe = cwd + "/sleep.exe";
96-
tc.assumeThat(exe, IsFile, exe + " not found")
93+
tc.assumeThat(exe, matlab.unittest.constraints.IsFile)
9794

9895
[ret, ~, err] = stdlib.subprocess_run(exe, timeout=1, stdout=false, stderr=false);
9996

0 commit comments

Comments
 (0)