Skip to content

Commit 9b21d1c

Browse files
committed
improve test coverage and corner cases
1 parent 6735430 commit 9b21d1c

File tree

2 files changed

+58
-28
lines changed

2 files changed

+58
-28
lines changed

+stdlib/filesystem_type.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
function t = filesystem_type(p)
99
arguments
10-
p (1,1) string
10+
p (1,1) string = ""
1111
end
1212

13+
t = "";
14+
15+
if stdlib.len(p) && ~stdlib.exists(p), return, end
16+
1317
op = javaPathObject(p);
1418

1519
if stdlib.isoctave()

test/TestJava.m

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

3+
properties (TestParameter)
4+
Ps = {".", tempname, "", "not-exist"}
5+
end
6+
37
methods(TestClassSetup)
48
function java_required(tc)
59
tc.assumeTrue(stdlib.has_java())
@@ -9,48 +13,55 @@ function java_required(tc)
913

1014
methods(Test)
1115

12-
function test_filesystem_type(tc)
16+
function test_filesystem_type(tc, Ps)
1317
import matlab.unittest.constraints.IsOfClass
1418

15-
t = stdlib.filesystem_type(".");
19+
s = stdlib.filesystem_type(Ps);
20+
tc.verifyThat(s, IsOfClass('string'))
21+
L = strlength(s);
1622

17-
tc.verifyThat(t, IsOfClass('string'))
23+
if strlength(Ps) == 0 || stdlib.exists(Ps)
24+
tc.verifyGreaterThan(L, 0)
25+
else
26+
tc.verifyEqual(L, 0)
27+
end
1828
end
1929

2030

21-
function test_owner(tc)
22-
owner = stdlib.get_owner('.');
23-
tc.verifyGreaterThan(strlength(owner), 0, "expected non-empty username")
31+
function test_owner(tc, Ps)
32+
import matlab.unittest.constraints.IsOfClass
2433

25-
owner = stdlib.get_owner(tempname);
26-
tc.verifyEqual(strlength(owner), 0, "expected empty owner")
34+
s = stdlib.get_owner(Ps);
35+
tc.verifyThat(s, IsOfClass('string'))
36+
L = strlength(s);
2737

38+
if stdlib.exists(Ps)
39+
tc.verifyGreaterThan(L, 0)
40+
else
41+
tc.verifyEqual(L, 0)
42+
end
2843
end
2944

3045

3146
function test_username(tc)
3247
u = stdlib.get_username();
33-
L = strlength(u);
34-
tc.verifyGreaterThan(L, 0, "expected non-empty username")
48+
tc.verifyGreaterThan(strlength(u), 0)
3549
end
3650

3751
function test_hostname(tc)
3852
h = stdlib.hostname();
39-
L = strlength(h);
40-
tc.verifyGreaterThan(L, 0, "expected non-empty hostname")
53+
tc.verifyGreaterThan(strlength(h), 0)
4154
end
4255

4356
function test_java_vendor(tc)
4457
v = stdlib.java_vendor();
45-
L = strlength(v);
46-
tc.verifyGreaterThan(L, 0, "expected non-empty vendor")
58+
tc.verifyGreaterThan(strlength(v), 0)
4759
end
4860

4961

5062
function test_java_version(tc)
5163
v = stdlib.java_version();
52-
L = strlength(v);
53-
tc.verifyGreaterThanOrEqual(L, 4)
64+
tc.verifyGreaterThanOrEqual(strlength(v), 4)
5465
end
5566

5667

@@ -61,16 +72,13 @@ function test_java_api(tc)
6172

6273
function test_cpu_arch(tc)
6374
arch = stdlib.cpu_arch();
64-
L = strlength(arch);
65-
tc.verifyGreaterThan(L, 0, "expected non-empty arch")
75+
tc.verifyGreaterThan(strlength(arch), 0)
6676
end
6777

6878
function test_os_version(tc)
6979
[os, ver] = stdlib.os_version();
70-
Lo = strlength(os);
71-
Lv = strlength(ver);
72-
tc.verifyGreaterThan(Lo, 0, "expected non-empty os")
73-
tc.verifyGreaterThan(Lv, 0, "expected non-empty version")
80+
tc.verifyGreaterThan(strlength(os), 0, "expected non-empty os")
81+
tc.verifyGreaterThan(strlength(ver), 0, "expected non-empty version")
7482
end
7583

7684
function test_hard_link_count(tc)
@@ -130,17 +138,35 @@ function test_touch_modtime(tc)
130138
end
131139

132140

141+
function test_get_modtime(tc)
142+
tc.verifyEmpty(stdlib.get_modtime(""))
143+
end
144+
145+
function test_set_modtime(tc)
146+
tc.verifyEqual(stdlib.set_modtime(""), false)
147+
end
148+
149+
133150
function test_checkRAM(tc)
134-
tc.assertTrue(islogical(stdlib.checkRAM(1, "double")))
151+
import matlab.unittest.constraints.IsOfClass
152+
tc.verifyThat(stdlib.checkRAM(1, "double"), IsOfClass("logical"))
135153
end
136154

137155

138-
function test_disk_available(tc)
139-
tc.assertGreaterThan(stdlib.disk_available('/'), 0)
156+
function test_disk_available(tc, Ps)
157+
if stdlib.exists(Ps)
158+
tc.verifyGreaterThan(stdlib.disk_available(Ps), 0)
159+
else
160+
tc.verifyEqual(stdlib.disk_available(Ps), 0)
161+
end
140162
end
141163

142-
function test_disk_capacity(tc)
143-
tc.assertGreaterThan(stdlib.disk_capacity('/'), 0)
164+
function test_disk_capacity(tc, Ps)
165+
if stdlib.exists(Ps)
166+
tc.verifyGreaterThan(stdlib.disk_capacity(Ps), 0)
167+
else
168+
tc.verifyEqual(stdlib.disk_capacity(Ps), 0)
169+
end
144170
end
145171

146172
end

0 commit comments

Comments
 (0)