Skip to content

Commit dd5d745

Browse files
committed
test: < R2022a compatibility
1 parent 7ccbdb9 commit dd5d745

File tree

10 files changed

+198
-41
lines changed

10 files changed

+198
-41
lines changed

Readme.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ These system, filesystem, and HDF5 / HDF4 / NetCDF functions are used across num
1212

1313
Matlab R2020b is the minimum required version.
1414
URLs (e.g. https://, s3:// and similar) are treated as not existing.
15-
The self-tests require at least Matlab R2022a and can be run from the matlab-stdlib/ directory.
15+
The self-tests require at least Matlab R2021b and can be run from the matlab-stdlib/ directory.
1616

1717
```matlab
18-
%% Matlab R2023a or newer
18+
%% Matlab >= R2023a
1919
buildtool test
2020
```
2121

2222
```matlab
23-
%% Matlab R2022a or newer
24-
addpath .
25-
runtests("test")
23+
%% Matlab >= R2021b
24+
run('test/test_nomex.m')
2625
```
2726

28-
Functions requiring or optionally benefiting from MEX are indicated in the
29-
[API Documentation](https://geospace-code.github.io/matlab-stdlib).
30-
3127
Build the optional high-performance
3228
[MEX](https://www.mathworks.com/help/matlab/cpp-mex-file-applications.html)
3329
functions from the Matlab prompt in Matlab R2023a or newer:

test/TestAbsolute.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@
1111

1212

1313
methods(TestClassSetup)
14-
function set_cwd(tc)
15-
import matlab.unittest.fixtures.CurrentFolderFixture
16-
tc.td = tc.createTemporaryFolder();
17-
tc.applyFixture(CurrentFolderFixture(tc.td))
14+
function set_temp_wd(tc)
15+
if isMATLABReleaseOlderThan('R2022a')
16+
tc.td = tempname();
17+
mkdir(tc.td);
18+
else
19+
tc.td = tc.createTemporaryFolder();
20+
end
21+
tc.applyFixture(matlab.unittest.fixtures.CurrentFolderFixture(tc.td))
22+
end
23+
end
24+
25+
methods(TestClassTeardown)
26+
function remove_temp_wd(tc)
27+
if isMATLABReleaseOlderThan('R2022a')
28+
rmdir(tc.td, 's');
29+
end
1830
end
1931
end
2032

test/TestHDF5.m

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
A4
1010
utf
1111
utf2
12+
td
1213
end
1314

1415
properties (TestParameter)
@@ -19,9 +20,17 @@
1920
end
2021

2122
methods(TestClassSetup)
22-
function setup_file(tc)
2323

24-
td = tc.createTemporaryFolder();
24+
function set_temp_wd(tc)
25+
if isMATLABReleaseOlderThan('R2022a')
26+
tc.td = tempname();
27+
mkdir(tc.td);
28+
else
29+
tc.td = tc.createTemporaryFolder();
30+
end
31+
end
32+
33+
function setup_file(tc)
2534

2635
tc.A0 = 42.;
2736
tc.A1 = [42.; 43.];
@@ -32,7 +41,7 @@ function setup_file(tc)
3241
tc.utf = 'Hello There 😄';
3342
tc.utf2 = [tc.utf; ""];
3443

35-
tc.file = td + "/basic.h5";
44+
tc.file = tc.td + "/basic.h5";
3645

3746
% create test data first, so that parallel tests works
3847
stdlib.h5save(tc.file, '/A0', tc.A0)
@@ -53,6 +62,15 @@ function setup_file(tc)
5362

5463
tc.assertThat(tc.file, matlab.unittest.constraints.IsFile)
5564
end
65+
66+
end
67+
68+
methods(TestClassTeardown)
69+
function remove_temp_wd(tc)
70+
if isMATLABReleaseOlderThan('R2022a')
71+
rmdir(tc.td, 's');
72+
end
73+
end
5674
end
5775

5876

test/TestHash.m

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
classdef TestHash < matlab.unittest.TestCase
22

3+
properties
4+
td
5+
end
6+
37
properties (TestParameter)
48
Ph = {{'md5', '5d41402abc4b2a76b9719d911017c592'}, ...
59
{'sha-256', '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'}}
610
end
711

812

9-
methods (Test, TestTags="java")
13+
methods(TestMethodSetup)
14+
function set_temp_wd(tc)
15+
if isMATLABReleaseOlderThan('R2022a')
16+
tc.td = tempname();
17+
mkdir(tc.td);
18+
else
19+
tc.td = tc.createTemporaryFolder();
20+
end
21+
end
22+
end
23+
24+
methods(TestMethodTeardown)
25+
function remove_temp_wd(tc)
26+
if isMATLABReleaseOlderThan('R2022a')
27+
rmdir(tc.td, 's');
28+
end
29+
end
30+
end
1031

32+
methods (Test)
1133

1234
function test_hash_text(tc, Ph)
35+
tc.assumeTrue(stdlib.has_dotnet() || stdlib.has_java())
1336

14-
td = tc.createTemporaryFolder();
15-
16-
fn = td + "/hello";
37+
fn = tc.td + "/hello";
1738
fid = fopen(fn, "w");
1839

1940
tc.assumeGreaterThan(fid, 0);

test/TestJava.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
classdef TestJava < matlab.unittest.TestCase
22

3+
properties
4+
td
5+
end
6+
7+
methods(TestClassSetup)
8+
function set_temp_wd(tc)
9+
if isMATLABReleaseOlderThan('R2022a')
10+
tc.td = tempname();
11+
mkdir(tc.td);
12+
else
13+
tc.td = tc.createTemporaryFolder();
14+
end
15+
end
16+
end
17+
18+
methods(TestClassTeardown)
19+
function remove_temp_wd(tc)
20+
if isMATLABReleaseOlderThan('R2022a')
21+
rmdir(tc.td, 's');
22+
end
23+
end
24+
end
325

426
methods(Test, TestTags="java")
527

@@ -33,9 +55,7 @@ function test_is_regular_file(tc)
3355

3456
function test_touch_modtime(tc)
3557

36-
tf = tc.createTemporaryFolder();
37-
38-
fn = fullfile(tf, "modtime.txt");
58+
fn = fullfile(tc.td, "modtime.txt");
3959

4060
tc.verifyTrue(stdlib.touch(fn, datetime("yesterday")))
4161
t0 = stdlib.get_modtime(fn);

test/TestNetCDF.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@
1010
utf0
1111
utf1
1212
utf2
13+
td
1314
end
1415

1516
methods (TestClassSetup)
1617

17-
function setup_file(tc)
18+
function set_temp_wd(tc)
19+
if isMATLABReleaseOlderThan('R2022a')
20+
tc.td = tempname();
21+
mkdir(tc.td);
22+
else
23+
tc.td = tc.createTemporaryFolder();
24+
end
25+
end
1826

19-
td = tc.createTemporaryFolder();
27+
function setup_file(tc)
2028

2129
tc.A0 = 42.;
2230
tc.A1 = [42.; 43.];
@@ -29,7 +37,7 @@ function setup_file(tc)
2937
tc.utf2 = [tc.utf0, ""; "📞", "👋"];
3038

3139

32-
tc.file = td + "/basic.nc";
40+
tc.file = tc.td + "/basic.nc";
3341

3442
% create test data first, so that parallel tests works
3543
stdlib.ncsave(tc.file, 'A0', tc.A0)
@@ -51,6 +59,15 @@ function setup_file(tc)
5159
end
5260

5361

62+
methods(TestClassTeardown)
63+
function remove_temp_wd(tc)
64+
if isMATLABReleaseOlderThan('R2022a')
65+
rmdir(tc.td, 's');
66+
end
67+
end
68+
end
69+
70+
5471
methods (Test, TestTags="netcdf")
5572

5673
function test_get_variables(tc)

test/TestPermissions.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
classdef TestPermissions < matlab.unittest.TestCase
22

3+
properties
4+
td
5+
end
6+
7+
38
properties (TestParameter)
49
Ps = {".", pwd()}
510
end
611

712

13+
methods(TestClassSetup)
14+
function set_temp_wd(tc)
15+
if isMATLABReleaseOlderThan('R2022a')
16+
tc.td = tempname();
17+
mkdir(tc.td);
18+
else
19+
tc.td = tc.createTemporaryFolder();
20+
end
21+
end
22+
end
23+
24+
methods(TestClassTeardown)
25+
function remove_temp_wd(tc)
26+
if isMATLABReleaseOlderThan('R2022a')
27+
rmdir(tc.td, 's');
28+
end
29+
end
30+
end
31+
32+
833
methods (Test, TestTags="impure")
934

1035
function test_get_permissions(tc, Ps)
@@ -27,9 +52,7 @@ function test_set_permissions(tc)
2752

2853
import matlab.unittest.constraints.StartsWithSubstring
2954

30-
tf = tc.createTemporaryFolder();
31-
32-
nr = fullfile(tf, "no-read");
55+
nr = fullfile(tc.td, "no-read");
3356

3457
tc.verifyTrue(stdlib.touch(nr))
3558
stdlib.set_permissions(nr, -1, 0, 0)
@@ -39,7 +62,7 @@ function test_set_permissions(tc)
3962
tc.verifyThat(p, StartsWithSubstring("-"), "no-read permission failed to set")
4063
end
4164

42-
nw = fullfile(tf, "no-write");
65+
nw = fullfile(tc.td, "no-write");
4366

4467
tc.verifyTrue(stdlib.touch(nw))
4568
stdlib.set_permissions(nw, 0, -1, 0)

test/TestResolve.m

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

1111
methods(TestClassSetup)
12-
function set_cwd(tc)
13-
import matlab.unittest.fixtures.CurrentFolderFixture
14-
tc.td = tc.createTemporaryFolder();
15-
tc.applyFixture(CurrentFolderFixture(tc.td))
12+
function set_temp_wd(tc)
13+
if isMATLABReleaseOlderThan('R2022a')
14+
tc.td = tempname();
15+
mkdir(tc.td);
16+
else
17+
tc.td = tc.createTemporaryFolder();
18+
end
19+
tc.applyFixture(matlab.unittest.fixtures.CurrentFolderFixture(tc.td))
20+
end
21+
end
22+
23+
methods(TestClassTeardown)
24+
function remove_temp_wd(tc)
25+
if isMATLABReleaseOlderThan('R2022a')
26+
rmdir(tc.td, 's');
27+
end
1628
end
1729
end
1830

test/TestSubprocess.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
classdef TestSubprocess < matlab.unittest.TestCase
22

3+
properties
4+
td
5+
end
6+
37
properties (TestParameter)
48
lang_out = {"c", "fortran"}
59
lang_in = {"cpp", "fortran"}
610
end
711

12+
methods(TestClassSetup)
13+
function set_temp_wd(tc)
14+
if isMATLABReleaseOlderThan('R2022a')
15+
tc.td = tempname();
16+
mkdir(tc.td);
17+
else
18+
tc.td = tc.createTemporaryFolder();
19+
end
20+
end
21+
end
22+
23+
methods(TestClassTeardown)
24+
function remove_temp_wd(tc)
25+
if isMATLABReleaseOlderThan('R2022a')
26+
rmdir(tc.td, 's');
27+
end
28+
end
29+
end
30+
831
methods (Test, TestTags=["exe"])
932

1033
function test_stdout_stderr(tc, lang_out)
@@ -124,9 +147,7 @@ function test_java_cwd(tc)
124147
tc.verifyGreaterThan(strlength(m), 0, "empty directory not expected")
125148
tc.verifyEqual(strlength(e), 0, e)
126149

127-
td = tc.createTemporaryFolder();
128-
129-
[s, mc, e] = stdlib.java_run(c, cwd=td);
150+
[s, mc, e] = stdlib.java_run(c, cwd=tc.td);
130151
tc.assertEqual(s, 0, "status non-zero")
131152
tc.verifyNotEqual(m, mc, "expected different directory to have different contents")
132153
tc.verifyEqual(strlength(e), 0, e)

0 commit comments

Comments
 (0)