Skip to content

Commit d89fdfd

Browse files
committed
test: skip for too old Matlab
1 parent df684aa commit d89fdfd

File tree

4 files changed

+35
-47
lines changed

4 files changed

+35
-47
lines changed

test/TestHDF5.m

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,10 @@ function setup_file(tc)
4444
stdlib.h5save(bf, '/A3', A3, "size", size(A3))
4545
stdlib.h5save(bf, '/A4', A4)
4646

47-
try
48-
if ~isMATLABReleaseOlderThan("R2020b")
47+
if ~too_old("R2020b")
4948
stdlib.h5save(bf, "/utf", utf)
5049
stdlib.h5save(bf, "/utf2", utf2)
5150
end
52-
catch e
53-
if e.identifier ~= "MATLAB:UndefinedFunction"
54-
rethrow(e)
55-
end
56-
end
5751

5852
stdlib.h5save(bf, '/t/x', 12)
5953
stdlib.h5save(bf, '/t/y', 13)
@@ -81,15 +75,9 @@ function test_get_variables(tc)
8175
v = stdlib.h5variables(basic);
8276
k = ["A0", "A1", "A2", "A3", "A4"];
8377

84-
try
85-
if ~isMATLABReleaseOlderThan("R2020b")
78+
if ~too_old("R2020b")
8679
k = [k, "utf", "utf2"];
8780
end
88-
catch e
89-
if e.identifier ~= "MATLAB:UndefinedFunction"
90-
rethrow(e)
91-
end
92-
end
9381

9482
tc.verifyEqual(sort(v), k)
9583

@@ -140,19 +128,13 @@ function test_size(tc)
140128
tc.verifyTrue(isvector(s))
141129
tc.verifyEqual(s, [4,3,2,5])
142130

143-
try
144-
if ~isMATLABReleaseOlderThan("R2020b")
131+
if ~too_old("R2020b")
145132
s = stdlib.h5size(basic, '/utf');
146133
tc.verifyEmpty(s)
147134

148135
s = stdlib.h5size(basic, '/utf2');
149136
tc.verifyEqual(s, 2)
150137
end
151-
catch e
152-
if e.identifier ~= "MATLAB:UndefinedFunction"
153-
rethrow(e)
154-
end
155-
end
156138

157139
end
158140

@@ -182,8 +164,7 @@ function test_read(tc)
182164
tc.verifyEqual(ndims(s), 4)
183165
tc.verifyEqual(s, tc.TestData.A4)
184166

185-
try
186-
if ~isMATLABReleaseOlderThan("R2020b")
167+
if ~too_old("R2020b")
187168
s = h5read(basic, '/utf');
188169
tc.verifyTrue(ischar(s))
189170
tc.verifyEqual(s, tc.TestData.utf)
@@ -192,11 +173,6 @@ function test_read(tc)
192173
tc.verifyThat(s, IsOfClass('string'))
193174
tc.verifyEqual(s, tc.TestData.utf2)
194175
end
195-
catch e
196-
if e.identifier ~= "MATLAB:UndefinedFunction"
197-
rethrow(e)
198-
end
199-
end
200176

201177
end
202178

@@ -219,7 +195,11 @@ function test_shape(tc)
219195
function test_coerce(tc, type)
220196
basic = tc.TestData.basic;
221197

222-
stdlib.h5save(basic, "/"+type, 0, "type",type)
198+
if any(type == ["string", "char"])
199+
tc.assumeFalse(too_old("R2020b"))
200+
end
201+
202+
stdlib.h5save(basic, "/" + type, 0, "type", type)
223203

224204
switch type
225205
case "string", vt = 'char';
@@ -265,6 +245,8 @@ function test_int8(tc)
265245

266246
function test_string(tc, str)
267247

248+
tc.assumeFalse(too_old("R2020b"))
249+
268250
basic = tc.TestData.basic;
269251

270252
stdlib.h5save(basic, "/"+str, str)

test/TestNetCDF.m

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,11 @@ function setup_file(tc)
4141
stdlib.ncsave(basic, 'A3', A3, "dims", {'x3', size(A3,1), 'y3', size(A3,2), 'z3', size(A3,3)})
4242
stdlib.ncsave(basic, 'A4', A4, "dims", {'x4', size(A4,1), 'y4', size(A4,2), 'z4', size(A4,3), 'w4', size(A4,4)})
4343

44-
try
45-
if ~isMATLABReleaseOlderThan('R2021b')
44+
if ~too_old('R2021b')
4645
stdlib.ncsave(basic, "utf0", utf0)
4746
stdlib.ncsave(basic, "utf1", utf1, "dims", {'s1', size(utf1, 1)})
4847
stdlib.ncsave(basic, "utf2", utf2, "dims", {'s1', size(utf2, 1), 't1', size(utf2, 2)})
4948
end
50-
catch e
51-
if e.identifier ~= "MATLAB:UndefinedFunction"
52-
rethrow(e)
53-
end
54-
end
55-
5649

5750
stdlib.ncsave(basic, '/t/x', 12)
5851
stdlib.ncsave(basic, '/t/y', 13)
@@ -69,15 +62,9 @@ function test_get_variables(tc)
6962

7063
k = ["A0", "A1", "A2", "A3", "A4"];
7164

72-
try
73-
if ~isMATLABReleaseOlderThan('R2021b')
65+
if ~too_old('R2021b')
7466
k = [k, ["utf0", "utf1", "utf2"]];
7567
end
76-
catch e
77-
if e.identifier ~= "MATLAB:UndefinedFunction"
78-
rethrow(e)
79-
end
80-
end
8168

8269
tc.verifyEqual(sort(stdlib.ncvariables(basic)), k)
8370

@@ -135,7 +122,7 @@ function test_size(tc)
135122
function test_size_string(tc)
136123
basic = tc.TestData.basic;
137124

138-
tc.assumeFalse(isMATLABReleaseOlderThan('R2021b'), "NetCDF4 string requires Matlab >= R2021b")
125+
tc.assumeFalse(too_old('R2021b'), "NetCDF4 string requires Matlab >= R2021b")
139126

140127
s = stdlib.ncsize(basic, 'utf0');
141128
tc.verifyEmpty(s)
@@ -177,7 +164,7 @@ function test_read_string(tc)
177164
import matlab.unittest.constraints.IsOfClass
178165
basic = tc.TestData.basic;
179166

180-
tc.assumeFalse(isMATLABReleaseOlderThan('R2021b'), "NetCDF4 string requires Matlab >= R2021b")
167+
tc.assumeFalse(too_old('R2021b'), "NetCDF4 string requires Matlab >= R2021b")
181168

182169
s = ncread(basic, 'utf0');
183170
tc.verifyThat(s, IsOfClass('string'))

test/TestSubprocess.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function test_timeout(tc)
8585
c = ["sleep", "3"];
8686
end
8787

88-
[ret, ~, err] = stdlib.subprocess_run(c, timeout=timeout);
88+
[ret, ~, err] = stdlib.subprocess_run(c, "timeout", timeout);
8989

9090
tc.verifyNotEqual(ret, 0, err)
9191
tc.verifyThat(err, StartsWithSubstring("Subprocess timeout"))

test/too_old.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%% TOO_OLD check if Matlab older than R2020b or as specificed by release "r"
2+
%
3+
% example:
4+
% too_old("R2020b") % returns true if Matlab is older than R2020b
5+
6+
7+
function old = too_old(r)
8+
9+
try
10+
old = isMATLABReleaseOlderThan(r);
11+
catch e
12+
if e.identifier == "MATLAB:UndefinedFunction"
13+
old = true;
14+
else
15+
rethrow(e)
16+
end
17+
end
18+
19+
end

0 commit comments

Comments
 (0)