Skip to content

Commit 2e54328

Browse files
committed
test: native_exe for test finery
1 parent c1dce42 commit 2e54328

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

buildfile.m

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

44
plan = buildplan(localfunctions);
55

6-
sel = ~HasTag("exe") & ~HasTag("java") & ~HasTag("java_exe") & ~HasTag("python");
6+
sel = HasTag('native_exe') & ~HasTag("exe") & ~HasTag("java") & ~HasTag("java_exe") & ~HasTag("python");
77
if ispc()
88
sel = sel & ~HasTag("unix");
99
else

test/TestSubprocess.m

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,49 @@ function test_dirs(tc)
1616
end
1717

1818

19+
methods (Test, TestTags = "native_exe")
20+
21+
function test_cwd(tc)
22+
23+
if ispc
24+
c = 'cd';
25+
else
26+
c = 'pwd';
27+
end
28+
29+
% leave on for debugging.
30+
cmd_echo = true;
31+
32+
[s, m] = stdlib.subprocess_run(c, 'echo', cmd_echo);
33+
tc.assertEqual(s, 0, "status non-zero")
34+
tc.verifyGreaterThan(strlength(m), 0, "empty directory not expected")
35+
36+
[s, mc] = stdlib.subprocess_run(c, 'cwd', matlabroot, 'echo', cmd_echo);
37+
tc.assertEqual(s, 0, "status non-zero")
38+
tc.verifyNotEqual(m, mc, "expected different directory to have different contents")
39+
40+
end
41+
42+
43+
function test_env_run(tc)
44+
45+
cwd = fileparts(mfilename('fullpath'));
46+
exe = fullfile(cwd, 'printenv.exe');
47+
tc.assumeThat(exe, matlab.unittest.constraints.IsFile)
48+
49+
env = struct('TEST1', 'test123', 'TEST2', 'test321');
50+
n = fieldnames(env);
51+
52+
for i = 1:numel(n)
53+
[ret, out] = stdlib.subprocess_run(strjoin({exe, n{i}}), 'env', env);
54+
tc.verifyEqual(ret, 0)
55+
tc.verifySubstring(out, env.(n{i}))
56+
end
57+
58+
end
59+
end
60+
61+
1962
methods (Test, TestTags={'exe'})
2063

2164
function test_stdout_stderr(tc, lang_out)
@@ -61,43 +104,6 @@ function test_stdin(tc, lang_in)
61104
tc.verifyEqual(msg, '3')
62105
end
63106

64-
65-
function test_cwd(tc)
66-
67-
if ispc
68-
c = 'dir';
69-
else
70-
c = 'ls -l';
71-
end
72-
73-
[s, m] = stdlib.subprocess_run(c);
74-
tc.assertEqual(s, 0, "status non-zero")
75-
tc.verifyGreaterThan(strlength(m), 0, "empty directory not expected")
76-
77-
[s, mc] = stdlib.subprocess_run(c, 'cwd', matlabroot);
78-
tc.assertEqual(s, 0, "status non-zero")
79-
tc.verifyNotEqual(m, mc, "expected different directory to have different contents")
80-
81-
end
82-
83-
84-
function test_env_run(tc)
85-
86-
cwd = fileparts(mfilename('fullpath'));
87-
exe = fullfile(cwd, 'printenv.exe');
88-
tc.assumeThat(exe, matlab.unittest.constraints.IsFile)
89-
90-
env = struct('TEST1', 'test123', 'TEST2', 'test321');
91-
n = fieldnames(env);
92-
93-
for i = 1:numel(n)
94-
[ret, out] = stdlib.subprocess_run(strjoin({exe, n{i}}), 'env', env);
95-
tc.verifyEqual(ret, 0)
96-
tc.verifySubstring(out, env.(n{i}))
97-
end
98-
99-
end
100-
101107
end
102108

103109

@@ -154,9 +160,9 @@ function test_java_stdin(tc, lang_in)
154160
function test_java_cwd(tc)
155161

156162
if ispc
157-
c = ["cmd", "/c", "dir"];
163+
c = ["cmd", "/c", "cd"];
158164
else
159-
c = ["ls", "-l"];
165+
c = "pwd";
160166
end
161167

162168
[s, m, e] = stdlib.java_run(c);

test_main.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function test_main(context, sel)
1414
end
1515
test_root = fullfile(cwd, "test");
1616

17-
tags = releaseTestTags();
17+
tags = ["native_exe", releaseTestTags()];
1818

1919
if ~exist('isMATLABReleaseOlderThan', 'builtin') || isMATLABReleaseOlderThan('R2022b')
2020
suite = testsuite(test_root, 'Tag', tags);

0 commit comments

Comments
 (0)