Skip to content

Commit a7e84f9

Browse files
committed
username: choose_method
1 parent e89dd2d commit a7e84f9

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

+stdlib/get_username.m

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
%% GET_USERNAME tell username of current user
22
%
3-
function n = get_username()
3+
function n = get_username(method)
4+
arguments
5+
method (1,:) string = ["java", "dotnet", "python", "sys"]
6+
end
47

8+
fun = choose_method(method, "get_username");
59

6-
if stdlib.has_dotnet()
7-
n = stdlib.dotnet.get_username();
8-
elseif stdlib.has_java()
9-
n = stdlib.java.get_username();
10-
elseif stdlib.has_python()
11-
n = stdlib.python.get_username();
12-
else
13-
n = stdlib.sys.get_username();
14-
end
10+
n = fun();
1511

1612
end

test/TestSys.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
fun = {@stdlib.isoctave, @stdlib.has_dotnet, ...
99
@stdlib.has_java, @stdlib.has_python}
1010
cpu_arch_fun = {@stdlib.cpu_arch, @stdlib.dotnet.cpu_arch, @stdlib.java.cpu_arch}
11-
user_fun = {@stdlib.get_username, @stdlib.sys.get_username, @stdlib.dotnet.get_username, @stdlib.java.get_username, @stdlib.python.get_username}
1211
ia_fun = {'sys', 'dotnet', 'java', 'python'}
1312
cr_method = {'sys', 'java', 'python'}
1413
end
@@ -132,6 +131,7 @@ function test_is_parallel(tc)
132131
end
133132

134133
function test_hostname(tc, ia_fun)
134+
tc.assertNotEmpty(which("stdlib." + ia_fun + ".get_hostname"))
135135
try
136136
h = stdlib.hostname(ia_fun);
137137
tc.verifyGreaterThan(strlength(h), 0)
@@ -140,10 +140,14 @@ function test_hostname(tc, ia_fun)
140140
end
141141
end
142142

143-
function test_username(tc, user_fun)
144-
is_capable(tc, user_fun)
145-
u = user_fun();
146-
tc.verifyGreaterThan(strlength(u), 0)
143+
function test_username(tc, ia_fun)
144+
tc.assertNotEmpty(which("stdlib." + ia_fun + ".get_username"))
145+
try
146+
u = stdlib.get_username(ia_fun);
147+
tc.verifyGreaterThan(strlength(u), 0)
148+
catch e
149+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
150+
end
147151
end
148152

149153

0 commit comments

Comments
 (0)