Skip to content

Commit 81b15d5

Browse files
committed
is_symlink: array
1 parent 04fbe87 commit 81b15d5

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

+stdlib/is_symlink.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
function ok = is_symlink(file, backend)
44
arguments
5-
file {mustBeTextScalar}
5+
file string
66
backend (1,:) string = ["native", "java", "dotnet", "python", "sys"]
77
end
88

9-
fun = hbackend(backend, "is_symlink", 'R2024b');
9+
[fun, b] = hbackend(backend, "is_symlink", 'R2024b');
1010

11-
ok = fun(file);
11+
if isscalar(file) || b == "native"
12+
ok = fun(file);
13+
else
14+
ok = arrayfun(fun, file);
15+
end
1216

1317
end

test/TestSymlink.m

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
p = {{"not-exist", false}, ...
1111
{mfilename("fullpath") + ".m", false}, ...
1212
{"", false}};
13-
cs_fun = {'native', 'sys', 'dotnet', 'python'}
13+
cs_backend = {'native', 'sys', 'dotnet', 'python'}
1414
Pre = {'', "", tempname()}
15-
rs_fun = {'native', 'sys', 'dotnet', 'java', 'python'}
15+
ir_backend = {'native', 'sys', 'dotnet', 'java', 'python'}
1616
end
1717

1818
methods(TestClassSetup)
@@ -44,48 +44,57 @@ function setup_symlink(tc)
4444

4545
methods (Test, TestTags=["impure", "symlink"])
4646

47-
function test_is_symlink(tc, p, rs_fun)
48-
tc.assertNotEmpty(which("stdlib." + rs_fun + ".is_symlink"))
47+
function test_is_symlink(tc, p, ir_backend)
48+
tc.assertNotEmpty(which("stdlib." + ir_backend + ".is_symlink"))
4949
try
50-
tc.verifyTrue(stdlib.is_symlink(tc.link, rs_fun), "failed to detect own link")
51-
tc.verifyEqual(stdlib.is_symlink(p{1}, rs_fun), p{2}, p{1})
50+
tc.verifyTrue(stdlib.is_symlink(tc.link, ir_backend), "failed to detect own link")
51+
tc.verifyEqual(stdlib.is_symlink(p{1}, ir_backend), p{2}, p{1})
52+
catch e
53+
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
54+
end
55+
end
56+
57+
function test_is_symlink_array(tc, ir_backend)
58+
try
59+
r = stdlib.is_symlink([tc.link, mfilename() + ".m"], ir_backend);
60+
tc.verifyEqual(r, [true, false], "failed to detect own link")
5261
catch e
5362
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
5463
end
5564
end
5665

5766

58-
function test_read_symlink_empty(tc, Pre, rs_fun)
67+
function test_read_symlink_empty(tc, Pre, ir_backend)
5968
try
60-
tc.verifyEmpty(stdlib.read_symlink(Pre, rs_fun))
69+
tc.verifyEmpty(stdlib.read_symlink(Pre, ir_backend))
6170
catch e
6271
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
6372
end
6473
end
6574

6675

67-
function test_read_symlink(tc, rs_fun)
68-
tc.assertNotEmpty(which("stdlib." + rs_fun + ".read_symlink"))
76+
function test_read_symlink(tc, ir_backend)
77+
tc.assertNotEmpty(which("stdlib." + ir_backend + ".read_symlink"))
6978
try
70-
tc.verifyEqual(stdlib.read_symlink(tc.link, rs_fun), string(tc.target))
79+
tc.verifyEqual(stdlib.read_symlink(tc.link, ir_backend), string(tc.target))
7180
catch e
7281
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
7382
end
7483
end
7584

7685

77-
function test_create_symlink(tc, cs_fun)
78-
tc.assumeNotEmpty(which("stdlib." + cs_fun + ".create_symlink"))
86+
function test_create_symlink(tc, cs_backend)
87+
tc.assumeNotEmpty(which("stdlib." + cs_backend + ".create_symlink"))
7988
tc.applyFixture(matlab.unittest.fixtures.SuppressedWarningsFixture(["MATLAB:io:filesystem:symlink:TargetNotFound","MATLAB:io:filesystem:symlink:FileExists"]))
8089

8190
ano = tc.td + "/another.lnk";
8291

8392
h = @stdlib.create_symlink;
8493

8594
try
86-
tc.verifyFalse(h('', tempname(), cs_fun))
87-
tc.verifyFalse(h(tc.target, tc.link, cs_fun), "should fail for existing symlink")
88-
tc.verifyTrue(h(tc.target, ano, cs_fun))
95+
tc.verifyFalse(h('', tempname(), cs_backend))
96+
tc.verifyFalse(h(tc.target, tc.link, cs_backend), "should fail for existing symlink")
97+
tc.verifyTrue(h(tc.target, ano, cs_backend))
8998
catch e
9099
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
91100
return

0 commit comments

Comments
 (0)