Skip to content

Commit 2eaaa86

Browse files
committed
absolute_path: fallback without java
1 parent 3b232a5 commit 2eaaa86

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

+stdlib/+fileio/absolute_path.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
try
3535
abspath = string(java.io.File(abspath).getCanonicalPath());
3636
catch excp
37-
error("stdlib:fileio:absolute_path", "%s is not a canonicalizable path. %s", abspath, excp.message)
37+
if excp.identifier == "MATLAB:undefinedVarOrClass"
38+
% Java is not available, so return unmodified path
39+
return
40+
else
41+
error("stdlib:fileio:absolute_path", "%s is not a canonicalizable path. %s", abspath, excp.message)
42+
end
3843
end
3944

4045
end % function

+stdlib/+fileio/example.ini

Lines changed: 0 additions & 29 deletions
This file was deleted.

+stdlib/+test/TestFilePure.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ function test_posix(tc)
1515
end
1616

1717
function test_samepath(tc)
18+
1819
import stdlib.fileio.samepath
1920

21+
tc.assumeTrue(usejava("jvm"), "Java required for samepath")
22+
2023
tc.verifyEmpty(samepath(string.empty, string.empty))
2124
tc.verifyTrue(samepath("", ""))
2225
tc.verifyFalse(samepath("a", "b"))
@@ -29,6 +32,8 @@ function test_path_tail(tc)
2932

3033
import stdlib.fileio.path_tail
3134

35+
tc.assumeTrue(usejava("jvm"), "Java required for path_tail")
36+
3237
tc.verifyEmpty(path_tail(string.empty))
3338
tc.verifyEqual(path_tail(""), "")
3439
tc.verifyEqual(path_tail("/foo/bar/baz"), "baz")
@@ -62,6 +67,8 @@ function test_absolute_path(tc)
6267

6368
import stdlib.fileio.absolute_path
6469

70+
tc.assumeTrue(usejava("jvm"), "Java required for absolute_path")
71+
6572
tc.verifyEmpty(absolute_path(string.empty))
6673
tc.verifyEqual(absolute_path(""), string(pwd))
6774

@@ -71,11 +78,14 @@ function test_absolute_path(tc)
7178
tc.verifyTrue(strncmp(pabs, pabs2, 2))
7279

7380
par1 = absolute_path("../2foo");
81+
tc.verifyNotEmpty(par1)
82+
tc.verifyFalse(contains(par1, ".."))
83+
7484
par2 = absolute_path("../4foo");
75-
tc.verifyFalse(startsWith(par1, ".."))
7685
tc.verifyTrue(strncmp(par2, pabs2, 2))
7786

7887
pt1 = absolute_path("bar/../2foo");
88+
tc.verifyNotEmpty(pt1)
7989
tc.verifyFalse(contains(pt1, ".."))
8090

8191
va = absolute_path("2foo");

+stdlib/+test/TestIntg.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ function test_checkRAM(tc)
1212
end
1313

1414
function test_diskfree(tc)
15-
import stdlib.sys.diskfree
15+
import stdlib.sys.diskfree
16+
17+
tc.assumeTrue(usejava("jvm"), "Java required for path_tail")
18+
1619
tc.assertTrue(isnumeric(diskfree('~')))
1720
tc.assertTrue(diskfree('~') > 0, 'diskfree')
1821
end

0 commit comments

Comments
 (0)