Skip to content

Commit 1ddc8b4

Browse files
committed
sys.is_char_device:windows: heuristic
1 parent c791558 commit 1ddc8b4

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

+stdlib/+sys/is_char_device.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
function y = is_char_device(file)
1+
function ok = is_char_device(file)
22

3-
cmd = sprintf('test -c %s', file);
3+
if ispc()
4+
% https://learn.microsoft.com/en-us/windows/console/console-handles
5+
charDevs = ["NUL", "CONIN$", "CONOUT$"];
6+
ok = any(contains(file, charDevs));
7+
else
8+
cmd = sprintf('test -c %s', file);
49

5-
[s, ~] = system(cmd);
6-
y = s == 0;
10+
[s, ~] = system(cmd);
11+
ok = s == 0;
12+
end
713

814
end

test/TestExists.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,14 @@ function test_is_rw_array(tc, backend, fname)
5959

6060
function test_is_char_device(tc, icm)
6161
% /dev/stdin may not be available on CI systems
62-
if ispc
63-
n = "NUL";
64-
else
65-
n = "/dev/null";
66-
end
67-
68-
tc.assertNotEmpty(which("stdlib." + icm + ".is_char_device"))
62+
n = stdlib.null_file();
6963

7064
try
71-
y = stdlib.is_char_device(n, icm);
65+
tc.verifyTrue(stdlib.is_char_device(n, icm), n)
7266
catch e
7367
tc.verifyEqual(e.identifier, 'stdlib:hbackend:NameError', e.message)
74-
return
7568
end
7669

77-
tc.verifyTrue(y)
7870
end
7971

8072
end

test/TestFileImpure.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ function test_file_size_array(tc)
2929

3030

3131
function test_null_file(tc)
32-
tc.assumeFalse(ispc)
33-
34-
tc.verifyThat(stdlib.null_file, matlab.unittest.constraints.IsFile)
32+
if ispc()
33+
tc.verifyEqual(stdlib.null_file, "NUL")
34+
else
35+
tc.verifyThat(stdlib.null_file, matlab.unittest.constraints.IsFile)
36+
end
3537
end
3638

3739

test/TestSubprocess.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function test_cwd(tc)
2626
c = 'pwd';
2727
end
2828

29-
% leave on for debugging.
30-
cmd_echo = true;
29+
% true for debugging echo of command.
30+
cmd_echo = false;
3131

3232
[s, m] = stdlib.subprocess_run(c, 'echo', cmd_echo);
3333
tc.assertEqual(s, 0, "status non-zero")

0 commit comments

Comments
 (0)