Skip to content

Commit c314625

Browse files
committed
get_owner: choose_method
1 parent 2256b6e commit c314625

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

+stdlib/get_owner.m

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
%%% Outputs
66
% * n: owner, or empty if path does not exist
77

8-
function n = get_owner(p)
8+
function n = get_owner(file, method)
99
arguments
10-
p {mustBeTextScalar}
10+
file {mustBeTextScalar}
11+
method (1,:) string = ["java", "dotnet", "python" "sys"]
1112
end
1213

13-
if stdlib.has_java()
14-
n = stdlib.java.get_owner(p);
15-
elseif ispc() && stdlib.has_dotnet()
16-
n = stdlib.dotnet.get_owner(p);
17-
elseif ~ispc() && stdlib.has_python()
18-
n = stdlib.python.get_owner(p);
19-
else
20-
n = stdlib.sys.get_owner(p);
21-
end
14+
fun = choose_method(method, "get_owner");
15+
16+
n = fun(file);
2217

2318
end

+stdlib/private/choose_method.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if stdlib.dotnet_api() < 6, continue, end
2020
end
2121

22-
if endsWith(name, "is_admin")
22+
if endsWith(name, ["get_owner", "is_admin"])
2323
if ~ispc(), continue, end
2424
end
2525

@@ -38,11 +38,11 @@
3838
if ~stdlib.python.has_psutil(); continue, end
3939
end
4040

41-
if endsWith(name, "cpu_load")
41+
if endsWith(name, ["cpu_load", "get_owner"])
4242
if ~isunix(), continue, end
4343
end
4444

45-
if endsWith(name, "is_admin")
45+
if endsWith(name, "is_admin")
4646
if ~isunix() || isMATLABReleaseOlderThan('R2024a'), continue, end
4747
end
4848

test/TestDisk.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
disk_ac_name = {'disk_available', 'disk_capacity'}
1414
hl_fun = {'java', 'python'}
1515
fst_fun = {'sys', 'dotnet', 'java', 'python'}
16-
owner_fun = {@stdlib.get_owner, @stdlib.sys.get_owner, @stdlib.dotnet.get_owner, @stdlib.java.get_owner, @stdlib.python.get_owner}
1716
end
1817

1918
methods(TestClassSetup)
@@ -111,17 +110,22 @@ function test_inode_device(tc, id_fun, id_name)
111110
end
112111

113112

114-
function test_owner(tc, Po, owner_fun)
115-
is_capable(tc, owner_fun)
113+
function test_owner(tc, Po, fst_fun)
114+
tc.assertNotEmpty(which("stdlib." + fst_fun + ".get_owner"))
116115

117-
s = owner_fun(Po);
116+
try
117+
o = stdlib.get_owner(Po, fst_fun);
118+
catch e
119+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
120+
return
121+
end
118122

119-
tc.verifyClass(s, 'string')
123+
tc.verifyClass(o, 'string')
120124

121125
if stdlib.exists(Po)
122-
tc.verifyGreaterThan(strlength(s), 0)
126+
tc.verifyGreaterThan(strlength(o), 0)
123127
else
124-
tc.verifyEmpty(s)
128+
tc.verifyEmpty(o)
125129
end
126130

127131
end

test/is_capable.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ function is_capable(tc, f)
1111
dapi = stdlib.dotnet_api();
1212
tc.assumeGreaterThan(dapi, 0, ".NET not available")
1313

14-
if endsWith(n, "owner")
15-
tc.assumeTrue(ispc(), "Windows only function")
16-
end
17-
1814
elseif contains(n, ".java.")
1915

2016
japi = stdlib.java_api();
@@ -24,10 +20,6 @@ function is_capable(tc, f)
2420

2521
tc.assumeTrue(stdlib.has_python(), "Python not available")
2622

27-
if endsWith(n, "owner")
28-
tc.assumeFalse(ispc(), "unix only function")
29-
end
30-
3123
elseif contains(n, ".sys.")
3224

3325
if endsWith(n, "samepath")

0 commit comments

Comments
 (0)