Skip to content

Commit c7686d7

Browse files
committed
test: improve w/wo java coverage
1 parent 7c60a61 commit c7686d7

File tree

9 files changed

+102
-67
lines changed

9 files changed

+102
-67
lines changed

buildfile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function checkTask(~)
1212
function testTask(~)
1313
addpath(fileparts(mfilename("fullpath")))
1414

15-
r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true, OutputDetail="Detailed");
15+
r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true, OutputDetail="Concise");
1616

1717
assert(~isempty(r), "No tests were run")
1818
assertSuccess(r)

test/TestFileImpure.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
classdef TestFileImpure < matlab.unittest.TestCase
22

33
properties(TestParameter)
4+
use_java = num2cell(unique([stdlib.has_java(), false]))
5+
46
p_exists = {{pwd(), true}, {mfilename("fullpath") + ".m", true}, {"TestFileImpure.m", true} {tempname, false}}
57
% on CI matlabroot can be writable!
68

@@ -20,31 +22,31 @@
2022

2123
methods (Test)
2224

23-
function test_exists(tc, p_exists)
24-
ok = stdlib.exists(p_exists{1}, stdlib.has_java());
25+
function test_exists(tc, p_exists, use_java)
26+
ok = stdlib.exists(p_exists{1}, use_java);
2527
tc.verifyEqual(ok, p_exists{2})
2628
end
2729

28-
function test_file_size(tc)
29-
s = stdlib.file_size(mfilename("fullpath") + ".m", stdlib.has_java());
30+
function test_file_size(tc, use_java)
31+
s = stdlib.file_size(mfilename("fullpath") + ".m", use_java);
3032
tc.verifyGreaterThan(s, 0)
3133
end
3234

3335

34-
function test_is_readable(tc, p_exists)
35-
ok = stdlib.is_readable(p_exists{1}, stdlib.has_java());
36+
function test_is_readable(tc, p_exists, use_java)
37+
ok = stdlib.is_readable(p_exists{1}, use_java);
3638
tc.verifyEqual(ok, p_exists{2})
3739
end
3840

3941

40-
function test_is_writable(tc, p_is_writable)
41-
ok = stdlib.is_writable(p_is_writable{1}, stdlib.has_java());
42+
function test_is_writable(tc, p_is_writable, use_java)
43+
ok = stdlib.is_writable(p_is_writable{1}, use_java);
4244
tc.verifyEqual(ok, p_is_writable{2})
4345
end
4446

4547

46-
function test_expanduser(tc, p_expand)
47-
tc.verifyEqual(stdlib.expanduser(p_expand{1}), p_expand{2})
48+
function test_expanduser(tc, p_expand, use_java)
49+
tc.verifyEqual(stdlib.expanduser(p_expand{1}), p_expand{2}, use_java)
4850
end
4951

5052

test/TestFilePure.m

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
classdef TestFilePure < matlab.unittest.TestCase
22

33
properties (TestParameter)
4-
5-
p_is_absolute
6-
7-
p_filename = {
8-
{"", ""}, ...
9-
{"/a/b/c", "c"}, ...
10-
{"/a/b/c/", ""}, ...
11-
{"a/b/c.txt", "c.txt"}, ...
12-
{"a/b/c.txt.gz", "c.txt.gz"}
13-
};
14-
15-
p_stem ={{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, ...
16-
{"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}, ...
17-
{"a/b/.c", ".c"}}
18-
19-
p_suffix = {{"", ""}, {"/a/b/c", ""}, {"/a/b/c/", ""}, {"a/b/c.txt", ".txt"}, {"a/b/c.txt.gz", ".gz"}, {".stat", ".stat"}, {".stat.txt", ".txt"}}
20-
214
p_root
225
p_root_name
236
end
@@ -48,15 +31,6 @@
4831

4932
end
5033

51-
52-
function [p_is_absolute] = init_is_absolute()
53-
p_is_absolute = {{"", false}, {"x", false}, {"x:", false}, {"x:/foo", false}, {"/foo", true}};
54-
if ispc
55-
p_is_absolute{4}{2} = true;
56-
p_is_absolute{5}{2} = false;
57-
end
58-
end
59-
6034
end
6135

6236

@@ -72,24 +46,6 @@ function test_posix(tc)
7246
end
7347
end
7448

75-
function test_filename(tc, p_filename)
76-
tc.verifyEqual(stdlib.filename(p_filename{1}), p_filename{2})
77-
end
78-
79-
function test_suffix(tc, p_suffix)
80-
tc.verifyEqual(stdlib.suffix(p_suffix{1}), p_suffix{2})
81-
end
82-
83-
84-
function test_stem(tc, p_stem)
85-
tc.verifyEqual(stdlib.stem(p_stem{1}), p_stem{2})
86-
end
87-
88-
function test_is_absolute(tc, p_is_absolute)
89-
ok = stdlib.is_absolute(p_is_absolute{1}, stdlib.has_java());
90-
tc.verifyEqual(ok, p_is_absolute{2}, p_is_absolute{1})
91-
end
92-
9349
function test_root(tc, p_root)
9450
tc.verifyEqual(stdlib.root(p_root{1}), p_root{2})
9551
end

test/TestFilename.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classdef TestFilename < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
p = {
5+
{"", ""}, ...
6+
{"/a/b/c", "c"}, ...
7+
{"/a/b/c/", ""}, ...
8+
{"a/b/c.txt", "c.txt"}, ...
9+
{"a/b/c.txt.gz", "c.txt.gz"}
10+
};
11+
end
12+
13+
methods (Test)
14+
function test_filename(tc, p)
15+
tc.verifyEqual(stdlib.filename(p{1}), p{2})
16+
end
17+
end
18+
19+
end

test/TestIsAbsolute.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
classdef TestIsAbsolute < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
p
5+
use_java = num2cell(unique([stdlib.has_java(), false]))
6+
end
7+
8+
methods (TestParameterDefinition, Static)
9+
function p = init_is_absolute()
10+
p = {{"", false}, {"x", false}, {"x:", false}, {"x:/foo", false}, {"/foo", true}};
11+
if ispc
12+
p{4}{2} = true;
13+
p{5}{2} = false;
14+
end
15+
end
16+
17+
end
18+
19+
methods (Test)
20+
function test_is_absolute(tc, p, use_java)
21+
ok = stdlib.is_absolute(p{1}, use_java);
22+
tc.verifyEqual(ok, p{2}, p{1})
23+
end
24+
end
25+
26+
end

test/TestRelative.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@
6464
methods (Test)
6565

6666
function test_relative_to(tc, p_relative_to)
67-
tc.assumeTrue(stdlib.has_java)
67+
tc.assumeTrue(stdlib.has_java())
6868
tc.verifyEqual(stdlib.relative_to(p_relative_to{1}, p_relative_to{2}), p_relative_to{3}, "relative_to(" + p_relative_to{1} + "," + p_relative_to{2}+")")
6969
end
7070

7171

7272
function test_proximate_to(tc, p_proximate_to)
73-
tc.assumeTrue(stdlib.has_java)
73+
tc.assumeTrue(stdlib.has_java())
7474
tc.verifyEqual(stdlib.proximate_to(p_proximate_to{1}, p_proximate_to{2}), p_proximate_to{3}, "proximate_to(" + p_proximate_to{1} + "," + p_proximate_to{2}+")")
7575
end
7676

test/TestStem.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classdef TestStem < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
5+
p = {{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, ...
6+
{"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}, ...
7+
{"a/b/.c", ".c"}}
8+
9+
end
10+
11+
methods (Test)
12+
function test(tc, p)
13+
tc.verifyEqual(stdlib.stem(p{1}), p{2})
14+
end
15+
end
16+
17+
end

test/TestSuffix.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
classdef TestSuffix < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
p = {{"", ""}, {"/a/b/c", ""}, {"/a/b/c/", ""}, {"a/b/c.txt", ".txt"}, {"a/b/c.txt.gz", ".gz"}, {".stat", ".stat"}, {".stat.txt", ".txt"}}
5+
end
6+
7+
methods (Test)
8+
function test(tc, p)
9+
tc.verifyEqual(stdlib.suffix(p{1}), p{2})
10+
end
11+
end
12+
13+
end

test/TestWhich.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
classdef TestWhich < matlab.unittest.TestCase
22

3+
properties (TestParameter)
4+
use_java = num2cell(unique([stdlib.has_java(), false]))
5+
end
6+
37

48
methods (Test)
59

6-
function test_which_name(tc)
10+
function test_which_name(tc, use_java)
711

8-
tc.verifyEmpty(stdlib.which(tempname))
12+
tc.verifyEmpty(stdlib.which(tempname, getenv('PATH'), use_java))
913

1014
if ispc
1115
n = "pwsh.exe";
@@ -17,19 +21,17 @@ function test_which_name(tc)
1721
% Unix-like OS may have Matlab as alias which is not visible to
1822
% stdlib.which()
1923
% virus scanners may block stdlib.which("cmd.exe") on Windows
20-
tc.verifyNotEmpty(stdlib.which(n))
24+
tc.verifyNotEmpty(stdlib.which(n, getenv('PATH'), use_java))
2125

2226
end
2327

2428

25-
function test_is_exe_which_fullpath(tc)
29+
function test_is_exe_which_fullpath(tc, use_java)
2630
import matlab.unittest.constraints.IsFile
2731
import matlab.unittest.constraints.EndsWithSubstring
2832

29-
u = stdlib.has_java();
30-
31-
tc.verifyFalse(stdlib.is_exe("", u))
32-
tc.verifyFalse(stdlib.is_exe(tempname, u))
33+
tc.verifyFalse(stdlib.is_exe("", use_java))
34+
tc.verifyFalse(stdlib.is_exe(tempname, use_java))
3335

3436
n = "matlab";
3537
%% is_exe test
@@ -39,9 +41,9 @@ function test_is_exe_which_fullpath(tc)
3941
else
4042
fp = p;
4143
end
42-
tc.verifyTrue(stdlib.is_exe(fp, u))
44+
tc.verifyTrue(stdlib.is_exe(fp, use_java))
4345
%% which: test absolute path
44-
exe = stdlib.which(p);
46+
exe = stdlib.which(p, getenv('PATH'), use_java);
4547

4648
if ispc
4749
tc.verifyThat(exe, EndsWithSubstring(".exe"))

0 commit comments

Comments
 (0)