Skip to content

Commit 3fc30f5

Browse files
committed
test: put always java-requiring tests in TestJava
1 parent 81b618c commit 3fc30f5

File tree

6 files changed

+121
-122
lines changed

6 files changed

+121
-122
lines changed

test/TestFileImpure.m

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -119,61 +119,6 @@ function test_samepath(tc, in_same, other_same, ref_same)
119119
tc.verifyEqual(stdlib.samepath(in_same, other_same), ref_same)
120120
end
121121

122-
function test_hash(tc)
123-
import matlab.unittest.constraints.IsFile
124-
import matlab.unittest.fixtures.TemporaryFolderFixture
125-
tc.assumeTrue(stdlib.has_java)
126-
fixture = tc.applyFixture(TemporaryFolderFixture);
127-
128-
fn = stdlib.join(fixture.Folder, "hello");
129-
fid = fopen(fn, "w");
130-
tc.assumeGreaterThan(fid, 0);
131-
fprintf(fid, "hello");
132-
fclose(fid);
133-
tc.assumeThat(fn, IsFile)
134-
135-
tc.verifyEqual(stdlib.file_checksum(fn, "md5"), "5d41402abc4b2a76b9719d911017c592")
136-
tc.verifyEqual(stdlib.file_checksum(fn, "sha256"), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824")
137-
138-
end
139-
140-
141-
function test_filesystem_type(tc)
142-
import matlab.unittest.constraints.IsOfClass
143-
144-
tc.assumeTrue(stdlib.has_java)
145-
146-
t = stdlib.filesystem_type(".");
147-
148-
tc.verifyThat(t, IsOfClass('string'))
149-
150-
end
151-
152-
153-
function test_owner(tc)
154-
tc.assumeTrue(stdlib.has_java)
155-
owner = stdlib.get_owner('.');
156-
L = strlength(owner);
157-
tc.verifyGreaterThan(L, 0, "expected non-empty username")
158-
159-
end
160-
161-
162-
function test_username(tc)
163-
tc.assumeTrue(stdlib.has_java)
164-
u = stdlib.get_username();
165-
L = strlength(u);
166-
tc.verifyGreaterThan(L, 0, "expected non-empty username")
167-
168-
end
169-
170-
function test_hostname(tc)
171-
tc.assumeTrue(stdlib.has_java)
172-
h = stdlib.hostname();
173-
L = strlength(h);
174-
tc.verifyGreaterThan(L, 0, "expected non-empty hostname")
175-
176-
end
177122

178123
function test_getpid(tc)
179124
pid = stdlib.getpid();
@@ -193,33 +138,6 @@ function test_handle2filename(tc)
193138
tc.verifyEmpty(stdlib.handle2filename(fopen(tempname)))
194139
end
195140

196-
function test_java_version(tc)
197-
tc.assumeTrue(stdlib.has_java)
198-
v = stdlib.java_version();
199-
L = strlength(v);
200-
tc.verifyGreaterThanOrEqual(L, 4)
201-
end
202-
203-
function test_java_api(tc)
204-
tc.assumeTrue(stdlib.has_java)
205-
v = stdlib.java_api();
206-
tc.verifyGreaterThanOrEqual(v, 8)
207-
end
208-
209-
function test_hard_link_count(tc)
210-
tc.assumeTrue(stdlib.has_java)
211-
fn = mfilename("fullpath") + ".m";
212-
213-
if ispc
214-
tc.verifyEmpty(stdlib.hard_link_count(fn))
215-
else
216-
tc.verifyGreaterThanOrEqual(stdlib.hard_link_count(fn), 1)
217-
end
218-
219-
tc.verifyEmpty(stdlib.hard_link_count(tempname))
220-
221-
end
222-
223141
end
224142

225143
end

test/TestHash.m

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
end
77

88
methods(TestClassSetup)
9+
10+
function has_java(tc)
11+
tc.assumeTrue(stdlib.has_java)
12+
end
13+
914
function setup_path(tc)
1015
import matlab.unittest.fixtures.PathFixture
1116
cwd = fileparts(mfilename("fullpath"));
@@ -20,8 +25,6 @@ function test_extract(tc)
2025
import matlab.unittest.constraints.IsFile
2126
import matlab.unittest.fixtures.TemporaryFolderFixture
2227

23-
tc.assumeTrue(stdlib.has_java)
24-
2528
fixture = tc.applyFixture(TemporaryFolderFixture);
2629
tmpDir = fixture.Folder;
2730

@@ -37,9 +40,8 @@ function test_extract(tc)
3740

3841
end
3942

40-
function test_hash(tc, type, hash)
4143

42-
tc.assumeTrue(stdlib.has_java)
44+
function test_hash(tc, type, hash)
4345

4446
r = fileparts(mfilename('fullpath'));
4547
fn = fullfile(r, "hello.tar.zst");
@@ -53,6 +55,24 @@ function test_hash(tc, type, hash)
5355

5456
end
5557

58+
59+
function test_hash_text(tc)
60+
import matlab.unittest.constraints.IsFile
61+
import matlab.unittest.fixtures.TemporaryFolderFixture
62+
fixture = tc.applyFixture(TemporaryFolderFixture);
63+
64+
fn = stdlib.join(fixture.Folder, "hello");
65+
fid = fopen(fn, "w");
66+
tc.assumeGreaterThan(fid, 0);
67+
fprintf(fid, "hello");
68+
fclose(fid);
69+
tc.assumeThat(fn, IsFile)
70+
71+
tc.verifyEqual(stdlib.file_checksum(fn, "md5"), "5d41402abc4b2a76b9719d911017c592")
72+
tc.verifyEqual(stdlib.file_checksum(fn, "sha256"), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824")
73+
74+
end
75+
5676
end
5777

5878
end

test/TestJava.m

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
classdef TestJava < matlab.unittest.TestCase
2+
3+
methods(TestClassSetup)
4+
5+
function has_java(tc)
6+
tc.assumeTrue(stdlib.has_java)
7+
end
8+
9+
end
10+
11+
methods(Test)
12+
13+
function test_filesystem_type(tc)
14+
import matlab.unittest.constraints.IsOfClass
15+
16+
t = stdlib.filesystem_type(".");
17+
18+
tc.verifyThat(t, IsOfClass('string'))
19+
end
20+
21+
22+
function test_owner(tc)
23+
owner = stdlib.get_owner('.');
24+
L = strlength(owner);
25+
tc.verifyGreaterThan(L, 0, "expected non-empty username")
26+
end
27+
28+
29+
function test_username(tc)
30+
u = stdlib.get_username();
31+
L = strlength(u);
32+
tc.verifyGreaterThan(L, 0, "expected non-empty username")
33+
end
34+
35+
function test_hostname(tc)
36+
h = stdlib.hostname();
37+
L = strlength(h);
38+
tc.verifyGreaterThan(L, 0, "expected non-empty hostname")
39+
end
40+
41+
42+
function test_java_version(tc)
43+
v = stdlib.java_version();
44+
L = strlength(v);
45+
tc.verifyGreaterThanOrEqual(L, 4)
46+
end
47+
48+
49+
function test_java_api(tc)
50+
v = stdlib.java_api();
51+
tc.verifyGreaterThanOrEqual(v, 8)
52+
end
53+
54+
55+
function test_hard_link_count(tc)
56+
fn = mfilename("fullpath") + ".m";
57+
58+
if ispc
59+
tc.verifyEmpty(stdlib.hard_link_count(fn))
60+
else
61+
tc.verifyGreaterThanOrEqual(stdlib.hard_link_count(fn), 1)
62+
end
63+
64+
tc.verifyEmpty(stdlib.hard_link_count(tempname))
65+
end
66+
67+
function test_is_parallel(tc)
68+
import matlab.unittest.constraints.IsOfClass
69+
tc.verifyThat(stdlib.is_parallel_worker, IsOfClass('logical'))
70+
end
71+
72+
function test_ram(tc)
73+
tc.verifyGreaterThan(stdlib.ram_total(), 0)
74+
tc.verifyGreaterThan(stdlib.ram_free(), 0)
75+
end
76+
77+
function test_cpu_count(tc)
78+
tc.verifyGreaterThan(stdlib.cpu_count(), 0)
79+
end
80+
81+
function test_cpu_load(tc)
82+
tc.verifyGreaterThanOrEqual(stdlib.cpu_load(), 0)
83+
end
84+
85+
end
86+
87+
end

test/TestSubprocess.m

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

33
methods (TestClassSetup)
4+
5+
function has_java(tc)
6+
tc.assumeTrue(stdlib.has_java)
7+
end
8+
49
function setup_path(tc)
510
import matlab.unittest.fixtures.PathFixture
611
cwd = fileparts(mfilename("fullpath"));
@@ -13,8 +18,6 @@ function setup_path(tc)
1318

1419
function test_simple_run(tc)
1520

16-
tc.assumeTrue(stdlib.has_java)
17-
1821
if ispc
1922
c = ["cmd", "/c", "dir"];
2023
else
@@ -32,8 +35,6 @@ function test_simple_run(tc)
3235
function test_cwd(tc)
3336
import matlab.unittest.fixtures.TemporaryFolderFixture
3437

35-
tc.assumeTrue(stdlib.has_java)
36-
3738
if ispc
3839
c = ["cmd", "/c", "dir"];
3940
else
@@ -58,8 +59,6 @@ function test_cwd(tc)
5859

5960
function test_env_run(tc)
6061

61-
tc.assumeTrue(stdlib.has_java)
62-
6362
names = ["TEST1", "TEST2"];
6463
vals = ["test123", "test321"];
6564

test/TestSys.m

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,5 @@ function test_platform(tc)
3333
tc.verifyThat(stdlib.is_windows_powershell, IsOfClass('logical'))
3434
end
3535

36-
function test_is_parallel(tc)
37-
import matlab.unittest.constraints.IsOfClass
38-
tc.assumeTrue(stdlib.has_java)
39-
tc.verifyThat(stdlib.is_parallel_worker, IsOfClass('logical'))
40-
end
41-
42-
function test_ram(tc)
43-
44-
tc.assumeTrue(stdlib.has_java)
45-
46-
tc.verifyGreaterThan(stdlib.ram_total(), 0)
47-
tc.verifyGreaterThan(stdlib.ram_free(), 0)
48-
49-
end
50-
51-
function test_cpu_count(tc)
52-
53-
tc.assumeTrue(stdlib.has_java)
54-
tc.verifyGreaterThan(stdlib.cpu_count(), 0)
55-
56-
end
57-
58-
function test_cpu_load(tc)
59-
60-
tc.assumeTrue(stdlib.has_java)
61-
tc.verifyGreaterThanOrEqual(stdlib.cpu_load(), 0)
62-
63-
end
64-
6536
end
6637
end

test/TestWSL.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
classdef TestWSL < matlab.unittest.TestCase
22

33
methods (TestClassSetup)
4+
5+
function has_java(tc)
6+
tc.assumeTrue(stdlib.has_java)
7+
end
8+
49
function setup_path(tc)
510
import matlab.unittest.fixtures.PathFixture
611
cwd = fileparts(mfilename("fullpath"));
@@ -13,7 +18,6 @@ function setup_path(tc)
1318

1419
function test_is_exe_which_wsl(tc)
1520
import matlab.unittest.constraints.IsFile
16-
tc.assumeTrue(stdlib.has_java)
1721
tc.assumeTrue(ispc, "Windows only")
1822
tc.assumeTrue(stdlib.has_wsl(), "did not find Windows Subsystem for Linux")
1923

0 commit comments

Comments
 (0)