Skip to content

Commit 63008a8

Browse files
committed
hostname: return char
1 parent 7ade9f5 commit 63008a8

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

+stdlib/+dotnet/get_hostname.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
function n = get_hostname()
55

6-
n = string(System.Environment.MachineName);
6+
n = char(System.Environment.MachineName);
77
% https://learn.microsoft.com/en-us/dotnet/api/system.environment.machinename
88

99
end

+stdlib/+java/get_hostname.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function n = get_hostname()
22

3-
n = string(javaMethod("getLocalHost", "java.net.InetAddress").getHostName());
3+
n = char(javaMethod("getLocalHost", "java.net.InetAddress").getHostName());
44

55
end

+stdlib/+python/get_hostname.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function n = get_hostname()
22

33
try
4-
n = string(py.socket.gethostname());
4+
n = char(py.socket.gethostname());
55
catch e
66
warning(e.identifier, "get_hostname failed: %s", e.message);
77
n = string.empty;

+stdlib/+sys/get_hostname.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
function n = get_hostname()
22

3-
cmd = "hostname";
3+
cmd = 'hostname';
44
[s, n] = system(cmd);
55

66
if s == 0
7-
n = string(strtrim(n));
7+
n = char(strtrim(n));
88
else
9-
warning("Failed to get hostname from system %s: %s", cmd, n);
10-
n = string.empty;
9+
n = '';
1110
end
1211

1312
end

test/TestSys.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,13 @@ function test_hostname(tc, all_fun)
138138
tc.assertNotEmpty(which("stdlib." + all_fun + ".get_hostname"))
139139
try
140140
h = stdlib.hostname(all_fun);
141-
tc.verifyGreaterThan(strlength(h), 0)
142141
catch e
143142
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
143+
return
144144
end
145+
146+
tc.verifyClass(h, 'char')
147+
tc.verifyGreaterThan(strlength(h), 0)
145148
end
146149

147150
function test_username(tc, all_fun)

0 commit comments

Comments
 (0)