Skip to content

Commit 6c3db00

Browse files
committed
test use working dir
1 parent 05ea7e2 commit 6c3db00

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

+stdlib/makedir.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function makedir(direc)
88
direc = stdlib.expanduser(direc);
99

1010
if ~stdlib.strempty(direc) && ~isfolder(direc)
11-
[~] = mkdir(direc);
11+
% char() is for Matlab < R2018a
12+
[~] = mkdir(char(direc));
1213
end
1314

1415
ok = isfolder(direc);

example/TestWindowsCOM.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ function test_not(tc, Pn)
1212
end
1313

1414
function test_short_folder(tc)
15-
import matlab.unittest.constraints.IsFolder
1615

1716
progdir = getenv("PROGRAMFILES");
1817
if ispc()
19-
tc.assertThat(progdir, IsFolder, "$Env:PROGRAMFILES is not a directory")
18+
tc.assertThat(progdir, matlab.unittest.constraints.IsFolder, "$Env:PROGRAMFILES is not a directory")
2019
end
2120

2221
short = windows_shortname(progdir);

test/TestBackend.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ function test_dirs(tc)
2222
methods (Test)
2323
function test_backend(tc)
2424
import matlab.unittest.constraints.IsSubsetOf
25-
import matlab.unittest.constraints.IsFile
25+
2626

2727
readme = tc.root + "/Readme.md";
28-
tc.assertThat(readme, IsFile)
28+
if stdlib.matlabOlderThan('R2018a')
29+
tc.assertTrue(isfile(readme))
30+
else
31+
tc.assertThat(readme, matlab.unittest.constraints.IsFile)
32+
end
2933

3034
[i, b] = stdlib.cpu_load();
3135
tc.assertThat(b, IsSubsetOf(stdlib.Backend('cpu_load').backends))
@@ -129,7 +133,11 @@ function test_backend(tc)
129133

130134
[i, b] = stdlib.read_symlink('Readme.lnk');
131135
tc.assertThat(b, IsSubsetOf(stdlib.Backend('read_symlink').backends))
132-
tc.verifyThat(i, IsFile)
136+
if stdlib.matlabOlderThan('R2018a')
137+
tc.assertTrue(isfile(i))
138+
else
139+
tc.assertThat(i, matlab.unittest.constraints.IsFile)
140+
end
133141

134142
[i, b] = stdlib.samepath(readme, readme);
135143
tc.assertThat(b, IsSubsetOf(stdlib.Backend('samepath').backends))

test/TestDisk.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ function test_is_dev_drive(tc, B_ps)
134134

135135
function test_remove_file(tc)
136136

137-
f = tempname();
137+
f = "test_remove.tmp";
138138

139139
tc.verifyFalse(stdlib.remove(f), "should not succeed at removing non-existant path")
140140

141-
tc.assumeTrue(stdlib.touch(f), "failed to touch file " + f)
142-
tc.assumeThat(f, matlab.unittest.constraints.IsFile)
141+
tc.assertTrue(stdlib.touch(f), "failed to touch file " + f)
142+
if stdlib.matlabOlderThan('R2018a')
143+
tc.assertTrue(isfile(f))
144+
else
145+
tc.assertThat(f, matlab.unittest.constraints.IsFile)
146+
end
143147

144148
tc.verifyTrue(stdlib.remove(f), "failed to remove file " + f)
145149
end

test/TestFileImpure.m

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,46 @@
44

55
properties (TestParameter)
66
ph = {{0, '"stdin"'}, {1, '"stdout"'}, {2, '"stderr"'}, {fopen(tempname()), ''}}
7+
end
78

8-
p_file_size = {mfilename("fullpath") + ".m"}
9+
methods(TestClassSetup)
10+
function test_dirs(tc)
11+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
12+
end
913
end
1014

1115

1216
methods (Test)
1317

14-
function test_file_size(tc, p_file_size)
15-
s = stdlib.file_size(p_file_size);
18+
function test_file_size(tc)
19+
fn = [mfilename("fullpath"), '.m'];
20+
s = stdlib.file_size(fn);
1621
tc.verifyGreaterThan(s, 0)
1722
end
1823

1924

2025
function test_null_file(tc)
26+
n = stdlib.null_file;
27+
2128
if ispc()
22-
tc.verifyEqual(stdlib.null_file, "NUL")
29+
tc.verifyEqual(n, "NUL")
30+
elseif stdlib.matlabOlderThan('R2018a')
31+
tc.verifyTrue(isfile(n))
2332
else
24-
tc.verifyThat(stdlib.null_file, matlab.unittest.constraints.IsFile)
33+
tc.verifyThat(n, matlab.unittest.constraints.IsFile)
2534
end
2635
end
2736

2837

2938
function test_makedir(tc)
30-
d = tempname();
39+
d = "test_makedir.dir";
3140
stdlib.makedir(d)
32-
tc.verifyThat(d, matlab.unittest.constraints.IsFolder)
33-
rmdir(d)
41+
42+
if stdlib.matlabOlderThan('R2018a')
43+
tc.assertTrue(isfolder(d))
44+
else
45+
tc.verifyThat(d, matlab.unittest.constraints.IsFolder)
46+
end
3447
end
3548

3649

test/TestHash.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function create_file(tc)
2525
fprintf(fid, "hello");
2626
fclose(fid);
2727

28-
tc.assertThat(tc.file, matlab.unittest.constraints.IsFile)
28+
if stdlib.matlabOlderThan('R2018a')
29+
tc.assumeTrue(isfile(tc.file))
30+
else
31+
tc.assertThat(tc.file, matlab.unittest.constraints.IsFile)
32+
end
2933
end
3034
end
3135

0 commit comments

Comments
 (0)