Skip to content

Commit afb55f3

Browse files
committed
testExists class
1 parent 7a27843 commit afb55f3

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

test/TestExists.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classdef TestExists < matlab.unittest.TestCase
2+
3+
properties(TestParameter)
4+
Ps = {{pwd(), true}, {mfilename("fullpath") + ".m", true}, {"TestFileImpure.m", true} {tempname, false}, {"file:///", false}}
5+
% on CI matlabroot can be writable!
6+
end
7+
8+
methods (Test)
9+
10+
function test_exists(tc, Ps)
11+
ok = stdlib.exists(Ps{1});
12+
tc.verifyEqual(ok, Ps{2})
13+
end
14+
15+
16+
function test_is_readable(tc, Ps)
17+
ok = stdlib.is_readable(Ps{1});
18+
tc.verifyEqual(ok, Ps{2})
19+
end
20+
21+
22+
end
23+
24+
end

test/TestFileImpure.m

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
classdef TestFileImpure < matlab.unittest.TestCase
22

33
properties(TestParameter)
4-
p_exists = {{pwd(), true}, {mfilename("fullpath") + ".m", true}, {"TestFileImpure.m", true} {tempname, false}}
5-
% on CI matlabroot can be writable!
6-
74
p_is_writable = {{pwd(), true}, {"not-exists", false}};
85

96
p_expand = {{"", ""}, {"~abc", "~abc"}, {"~", stdlib.homedir()}, {"~/c", stdlib.homedir() + "/c"}, {'~/////c', stdlib.homedir() + "/c"}};
@@ -20,23 +17,12 @@
2017

2118
methods (Test)
2219

23-
function test_exists(tc, p_exists)
24-
ok = stdlib.exists(p_exists{1});
25-
tc.verifyEqual(ok, p_exists{2})
26-
end
27-
2820
function test_file_size(tc)
2921
s = stdlib.file_size(mfilename("fullpath") + ".m");
3022
tc.verifyGreaterThan(s, 0)
3123
end
3224

3325

34-
function test_is_readable(tc, p_exists)
35-
ok = stdlib.is_readable(p_exists{1});
36-
tc.verifyEqual(ok, p_exists{2})
37-
end
38-
39-
4026
function test_is_writable(tc, p_is_writable)
4127
ok = stdlib.is_writable(p_is_writable{1});
4228
tc.verifyEqual(ok, p_is_writable{2})
@@ -70,20 +56,9 @@ function test_samepath(tc, p_same)
7056

7157
function test_get_pid(tc)
7258
pid = stdlib.get_pid();
73-
tc.verifyGreaterThan(pid, 0, "expected positive PID")
59+
tc.verifyGreaterThan(pid, 0)
7460
end
7561

76-
function test_get_permissions(tc)
77-
import matlab.unittest.constraints.StartsWithSubstring
78-
import matlab.unittest.constraints.IsOfClass
79-
80-
p = stdlib.get_permissions(".");
81-
tc.verifyThat(p, StartsWithSubstring("r"))
82-
tc.verifyThat(p, IsOfClass("char"))
83-
84-
p = stdlib.get_permissions(tempname);
85-
tc.verifyEmpty(p)
86-
end
8762

8863
function test_handle2filename(tc, ph)
8964
tc.verifyEqual(stdlib.handle2filename(ph{1}), string(ph{2}))

test/TestPermissions.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
classdef TestPermissions < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
Ps = {".", tempname, "", "not-exist"}
5+
end
6+
7+
methods (Test)
8+
9+
function test_get_permissions(tc, Ps)
10+
import matlab.unittest.constraints.StartsWithSubstring
11+
import matlab.unittest.constraints.IsOfClass
12+
13+
p = stdlib.get_permissions(Ps);
14+
15+
if stdlib.exists(Ps)
16+
tc.verifyThat(p, StartsWithSubstring("r"))
17+
tc.verifyThat(p, IsOfClass("char"))
18+
else
19+
tc.verifyEmpty(p)
20+
end
21+
22+
end
23+
24+
end
25+
26+
end

0 commit comments

Comments
 (0)