Skip to content

Commit 15e43a8

Browse files
committed
cpu_arch: choose_method
1 parent 5f8535c commit 15e43a8

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

+stdlib/+native/cpu_arch.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function a = cpu_arch()
2+
3+
a = string(computer('arch'));
4+
5+
end

+stdlib/cpu_arch.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
%% CPU_ARCH get the CPU architecture
22

3-
function a = cpu_arch()
4-
5-
if stdlib.has_java()
6-
a = stdlib.java.cpu_arch();
7-
elseif stdlib.has_dotnet()
8-
a = stdlib.dotnet.cpu_arch();
9-
else
10-
a = string(computer('arch'));
3+
function a = cpu_arch(method)
4+
arguments
5+
method (1,:) string = ["java", "dotnet", "native"]
116
end
127

13-
end
8+
fun = choose_method(method, "cpu_arch");
9+
10+
a = fun();
1411

12+
end

test/TestSys.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
properties (TestParameter)
88
fun = {@stdlib.isoctave, @stdlib.has_dotnet, ...
99
@stdlib.has_java, @stdlib.has_python}
10-
cpu_arch_fun = {@stdlib.cpu_arch, @stdlib.dotnet.cpu_arch, @stdlib.java.cpu_arch}
10+
cpu_arch_fun = {'java', 'dotnet', 'native'}
1111
ia_fun = {'sys', 'dotnet', 'java', 'python'}
1212
cr_method = {'sys', 'java', 'python'}
1313
end
@@ -161,9 +161,13 @@ function test_xcode_version(tc)
161161

162162

163163
function test_cpu_arch(tc, cpu_arch_fun)
164-
is_capable(tc, cpu_arch_fun)
165164

166-
arch = cpu_arch_fun();
165+
try
166+
arch = stdlib.cpu_arch(cpu_arch_fun);
167+
catch e
168+
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
169+
return
170+
end
167171
tc.verifyGreaterThan(strlength(arch), 0, "CPU architecture should not be empty")
168172
end
169173

@@ -174,7 +178,7 @@ function test_ram_total(tc, ia_fun)
174178
tc.verifyEqual(e.identifier, 'stdlib:choose_method:NameError', e.message)
175179
return
176180
end
177-
181+
178182
tc.verifyGreaterThan(t, 0)
179183
tc.verifyClass(t, 'uint64')
180184
end

0 commit comments

Comments
 (0)