Skip to content

Commit 376b437

Browse files
committed
define tests more robustly
1 parent 3fa2c98 commit 376b437

36 files changed

+204
-158
lines changed

+stdlib/dotnet_home.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%% DOTNET_HOME give .NET RuntimeLocation
2+
3+
function h = dotnet_home()
4+
5+
h = dotnetenv().RuntimeLocation;
6+
7+
end

test/TestAbsolute.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
classdef TestAbsolute < matlab.unittest.TestCase
2-
3-
properties
4-
td
5-
end
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestAbsolute < matlab.unittest.TestCase
63

74
properties (TestParameter)
85
p1 = {'', "", "hi", "./hi", "../hi"};
@@ -13,18 +10,17 @@
1310
methods(TestClassSetup)
1411
function test_dirs(tc)
1512
pkg_path(tc)
16-
tc.td = createTempdir(tc);
1713

18-
tc.applyFixture(matlab.unittest.fixtures.CurrentFolderFixture(tc.td))
14+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
1915
end
2016
end
2117

2218

23-
methods(Test, TestTags=["R2019b", "pure"])
19+
methods(Test)
2420

2521
function test_absolute1arg(tc, p1)
2622

27-
r = tc.td;
23+
r = pwd();
2824

2925
if strlength(p1)
3026
r = fullfile(r, p1);
@@ -39,7 +35,7 @@ function test_absolute1arg(tc, p1)
3935

4036
function test_absolute2arg(tc, p2)
4137

42-
r = tc.td;
38+
r = pwd();
4339

4440
if strlength(p2{2})
4541
r = fullfile(r, p2{2});

test/TestCanonical.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestCanonical < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestCanonical < matlab.unittest.TestCase
23

34
properties(TestParameter)
45
p = {{'', ""}, ...
@@ -15,11 +16,13 @@
1516
methods(TestClassSetup)
1617
function test_dirs(tc)
1718
pkg_path(tc)
19+
20+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
1821
end
1922
end
2023

2124

22-
methods(Test, TestTags=["R2019b", "impure"])
25+
methods(Test)
2326

2427
function test_canonical(tc, p, backend)
2528
try

test/TestDisk.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestDisk < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestDisk < matlab.unittest.TestCase
23

34
properties
45
CI = getenv("CI") == "true" || getenv("GITHUB_ACTIONS") == "true"
@@ -18,10 +19,12 @@
1819
methods(TestClassSetup)
1920
function test_dirs(tc)
2021
pkg_path(tc)
22+
23+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
2124
end
2225
end
2326

24-
methods (Test, TestTags=["R2019b", "impure"])
27+
methods (Test)
2528

2629
function test_disk_ac(tc, Ps, all_fun, disk_ac_name)
2730
n = "stdlib." + all_fun + "." + disk_ac_name;

test/TestExists.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestExists < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestExists < matlab.unittest.TestCase
23

34
properties(TestParameter)
45
Ps = {
@@ -18,10 +19,12 @@
1819
methods(TestClassSetup)
1920
function test_dirs(tc)
2021
pkg_path(tc)
22+
23+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
2124
end
2225
end
2326

24-
methods (Test, TestTags=["R2019b", "impure"])
27+
methods (Test)
2528

2629
function test_exists(tc, Ps)
2730
ok = stdlib.exists(Ps{1});
@@ -30,9 +33,8 @@ function test_exists(tc, Ps)
3033

3134

3235
function test_is_rw(tc, Ps, backend, fname)
33-
n = "stdlib." + backend + "." + fname;
3436
h = str2func("stdlib." + fname);
35-
tc.assertNotEmpty(which(n))
37+
3638
try
3739
r = h(Ps{1}, backend);
3840
tc.verifyEqual(r, Ps{2})
@@ -44,9 +46,11 @@ function test_is_rw(tc, Ps, backend, fname)
4446

4547
function test_is_rw_array(tc, backend, fname)
4648
h = str2func("stdlib." + fname);
49+
in = [".", tempname(), mfilename('fullpath') + ".m"];
50+
out = [true, false, true];
4751
try
48-
r = h([".", tempname(), mfilename() + ".m"], backend);
49-
tc.verifyEqual(r, [true, false, true])
52+
r = h(in, backend);
53+
tc.verifyEqual(r, out)
5054
catch e
5155
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
5256
end

test/TestExpanduser.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestExpanduser < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestExpanduser < matlab.unittest.TestCase
23

34
properties(TestParameter)
45
p = init_exp()
@@ -10,7 +11,7 @@ function test_dirs(tc)
1011
end
1112
end
1213

13-
methods(Test, TestTags=["R2019b", "impure"])
14+
methods(Test)
1415

1516
function test_expanduser(tc, p)
1617
tc.verifyEqual(stdlib.expanduser(p{1}), p{2})

test/TestFileImpure.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestFileImpure < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'impure'}) ...
2+
TestFileImpure < matlab.unittest.TestCase
23

34
properties(TestParameter)
45
ph = {{0, '"stdin"'}, {1, '"stdout"'}, {2, '"stderr"'}, {fopen(tempname()), ''}}
@@ -14,7 +15,7 @@ function test_dirs(tc)
1415
end
1516

1617

17-
methods (Test, TestTags=["R2019b", "impure"])
18+
methods (Test)
1819

1920
function test_file_size(tc, p_file_size)
2021
s = stdlib.file_size(p_file_size);
@@ -35,10 +36,9 @@ function test_null_file(tc)
3536

3637

3738
function test_makedir(tc)
38-
import matlab.unittest.constraints.IsFolder
3939
d = tempname();
4040
stdlib.makedir(d)
41-
tc.verifyThat(d, IsFolder)
41+
tc.verifyThat(d, matlab.unittest.constraints.IsFolder)
4242
rmdir(d)
4343
end
4444

test/TestFilePure.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
classdef TestFilePure < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'pure'}) ...
2+
TestFilePure < matlab.unittest.TestCase
23

34
methods(TestClassSetup)
45
function test_dirs(tc)
@@ -7,7 +8,7 @@ function test_dirs(tc)
78
end
89

910

10-
methods (Test, TestTags=["R2019b", "pure"])
11+
methods (Test)
1112

1213
function test_posix(tc)
1314

test/TestFilename.m

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
classdef TestFilename < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'pure'}) ...
2+
TestFilename < matlab.unittest.TestCase
23

34
properties (TestParameter)
45
p = init_p()
5-
e = {'/a/b/c/', "a/b/c/"}
66
backend = init_backend()
77
end
88

@@ -12,21 +12,16 @@ function test_dirs(tc)
1212
end
1313
end
1414

15-
methods (Test, TestTags=["R2019b", "pure"])
15+
methods (Test)
1616

1717
function test_filename(tc, p, backend)
1818
fn = stdlib.filename(p{1}, backend);
1919
tc.verifyEqual(fn, p{2})
2020
end
2121

22-
function test_filename_empty(tc, e, backend)
23-
fn = stdlib.filename(e, backend);
24-
tc.verifyEqual(strlength(fn), 0)
25-
end
26-
2722
function test_filename_array(tc, backend)
28-
in = ["", "a", "a/b/c", "a/b/c.txt", "a/b/.hidden", "a/b/c/"];
29-
exp = ["", "a", "c", "c.txt", ".hidden", ""];
23+
in = ["", "a", "a/b/c", "a/b/", "a/b/c.txt", "a/b/.hidden", "a/b/c/"];
24+
exp = ["", "a", "c", "", "c.txt", ".hidden", ""];
3025
out = stdlib.filename(in, backend);
3126
tc.verifyEqual(out, exp)
3227
end

test/TestHDF4.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
classdef TestHDF4 < matlab.unittest.TestCase
1+
classdef (TestTags = {'R2019b', 'hdf4'}) ...
2+
TestHDF4 < matlab.unittest.TestCase
23

34
properties
45
file
56
end
67

78
methods (TestClassSetup)
89
function setup_file(tc)
9-
import matlab.unittest.constraints.IsFile
1010
tc.file = fullfile(matlabroot, "toolbox/matlab/demos/example.hdf");
11-
tc.assumeThat(tc.file, IsFile)
11+
tc.assertThat(tc.file, matlab.unittest.constraints.IsFile)
1212

1313
pkg_path(tc)
1414
end
1515
end
1616

17-
methods (Test, TestTags=["R2019b", "hdf4"])
17+
methods (Test)
1818

1919
function test_exists(tc)
2020
import matlab.unittest.constraints.IsScalar

0 commit comments

Comments
 (0)