Skip to content

Commit 1ead7d9

Browse files
committed
samepath: default non-java
1 parent 3fc30f5 commit 1ead7d9

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

+stdlib/samepath.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function issame = samepath(path1, path2)
1+
function issame = samepath(path1, path2, use_java)
22
%% samepath(path1, path)
33
% true if inputs resolve to same path
44
% files need not exist
@@ -10,13 +10,15 @@
1010
arguments
1111
path1 (1,1) string
1212
path2 (1,1) string
13+
use_java (1,1) logical = false
1314
end
1415

1516
issame = false;
1617
if ~stdlib.exists(path1) || ~stdlib.exists(path2)
1718
return
1819
end
1920

21+
if use_java
2022
% needs absolute
2123
path1 = stdlib.absolute(path1, string.empty, false, true);
2224
path2 = stdlib.absolute(path2, string.empty, false, true);
@@ -28,4 +30,8 @@
2830
% alternative, lower-level method is lexical only (not suitable for us):
2931
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#equals(java.lang.Object)
3032

33+
else
34+
issame = stdlib.canonical(path1, false, false) == stdlib.canonical(path2, false, false);
35+
end
36+
3137
end

test/TestFileImpure.m

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,6 @@ function test_null_file(tc)
7979
end
8080

8181

82-
function test_is_regular_file(tc)
83-
import matlab.unittest.constraints.IsFile
84-
tc.assumeTrue(stdlib.has_java)
85-
if ~ispc
86-
tc.assumeThat(stdlib.null_file, IsFile)
87-
end
88-
tc.verifyFalse(stdlib.is_regular_file(stdlib.null_file), "null file is not a regular file")
89-
90-
end
91-
92-
93-
function test_touch_modtime(tc)
94-
tc.assumeTrue(stdlib.has_java)
95-
fn = tempname;
96-
tc.verifyTrue(stdlib.touch(fn))
97-
t0 = stdlib.get_modtime(fn);
98-
99-
pause(1.) % empirical to avoid failing >=. 0.4 failed intermittantly
100-
tc.verifyTrue(stdlib.set_modtime(fn))
101-
t1 = stdlib.get_modtime(fn);
102-
103-
tc.verifyGreaterThanOrEqual(t1, t0)
104-
105-
end
106-
107-
108-
10982
function test_makedir(tc)
11083
import matlab.unittest.constraints.IsFolder
11184
d = tempname;
@@ -115,7 +88,6 @@ function test_makedir(tc)
11588

11689
%%
11790
function test_samepath(tc, in_same, other_same, ref_same)
118-
tc.assumeTrue(stdlib.has_java)
11991
tc.verifyEqual(stdlib.samepath(in_same, other_same), ref_same)
12092
end
12193

test/TestJava.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,52 @@ function test_hard_link_count(tc)
6464
tc.verifyEmpty(stdlib.hard_link_count(tempname))
6565
end
6666

67+
6768
function test_is_parallel(tc)
6869
import matlab.unittest.constraints.IsOfClass
6970
tc.verifyThat(stdlib.is_parallel_worker, IsOfClass('logical'))
7071
end
7172

73+
7274
function test_ram(tc)
7375
tc.verifyGreaterThan(stdlib.ram_total(), 0)
7476
tc.verifyGreaterThan(stdlib.ram_free(), 0)
7577
end
7678

79+
7780
function test_cpu_count(tc)
7881
tc.verifyGreaterThan(stdlib.cpu_count(), 0)
7982
end
8083

84+
8185
function test_cpu_load(tc)
8286
tc.verifyGreaterThanOrEqual(stdlib.cpu_load(), 0)
8387
end
8488

89+
90+
function test_is_regular_file(tc)
91+
import matlab.unittest.constraints.IsFile
92+
if ~ispc
93+
tc.assumeThat(stdlib.null_file, IsFile)
94+
end
95+
tc.verifyFalse(stdlib.is_regular_file(stdlib.null_file), "null file is not a regular file")
96+
97+
end
98+
99+
100+
function test_touch_modtime(tc)
101+
fn = tempname;
102+
tc.verifyTrue(stdlib.touch(fn))
103+
t0 = stdlib.get_modtime(fn);
104+
105+
pause(1.) % empirical to avoid failing >=. 0.4 failed intermittantly
106+
tc.verifyTrue(stdlib.set_modtime(fn))
107+
t1 = stdlib.get_modtime(fn);
108+
109+
tc.verifyGreaterThanOrEqual(t1, t0)
110+
end
111+
112+
85113
end
86114

87115
end

0 commit comments

Comments
 (0)