11classdef TestSubprocess < matlab .unittest .TestCase
22
3- properties
4- td
5- end
6-
73properties (TestParameter )
84lang_out = {" c" , " fortran" }
95lang_in = {" cpp" , " fortran" }
106end
117
8+
129methods (TestClassSetup )
1310
1411function pkg_path(tc )
1512p = matlab .unittest .fixtures .PathFixture(fileparts(fileparts(mfilename(' fullpath' ))));
1613tc .applyFixture(p )
1714end
1815
19- function set_temp_wd(tc )
20- if isMATLABReleaseOlderThan(' R2022a' )
21- tc.td = tempname();
22- mkdir(tc .td );
23- else
24- tc.td = tc .createTemporaryFolder();
25- end
26- end
2716end
2817
29- methods (TestClassTeardown )
30- function remove_temp_wd(tc )
31- if isMATLABReleaseOlderThan(' R2022a' )
32- [s , m , i ] = rmdir(tc .td , ' s' );
33- if ~s , warning(i , " Failed to remove temporary directory %s: %s" , tc .td , m ); end
34- end
35- end
36- end
3718
3819methods (Test , TestTags = [" exe" ])
3920
@@ -45,6 +26,11 @@ function test_stdout_stderr(tc, lang_out)
4526tc .assumeThat(exe , IsFile )
4627
4728[status , msg ] = stdlib .subprocess_run(exe );
29+
30+ if ispc()
31+ tc .assumeNotEqual(status , - 1073741515 , " GCC DLLs probably not on PATH" )
32+ end
33+
4834tc .assertEqual(status , 0 )
4935tc .verifySubstring(msg , ' stderr' )
5036tc .verifySubstring(msg , ' stdout' )
@@ -67,6 +53,10 @@ function test_stdin(tc, lang_in)
6753
6854[status , msg ] = stdlib .subprocess_run(exe , stdin= " 1 2" );
6955
56+ if ispc()
57+ tc .assumeNotEqual(status , - 1073741515 , " GCC DLLs probably not on PATH" )
58+ end
59+
7060tc .assertEqual(status , 0 )
7161tc .verifyEqual(msg , ' 3' )
7262end
@@ -126,6 +116,11 @@ function test_Java_stdout_stderr(tc, lang_out)
126116end
127117
128118[status , msg , err ] = stdlib .java_run(exe );
119+
120+ if ispc()
121+ tc .assumeNotEqual(status , - 1073741515 , " GCC DLLs probably not on PATH" )
122+ end
123+
129124tc .assertEqual(status , 0 , err )
130125tc .verifySubstring(msg , " stdout" )
131126tc .verifyEqual(err , " stderr" )
@@ -146,6 +141,10 @@ function test_java_stdin(tc, lang_in)
146141
147142[status , msg , err ] = stdlib .java_run(exe , stdin= " 1 2" );
148143
144+ if ispc()
145+ tc .assumeNotEqual(status , - 1073741515 , " GCC DLLs probably not on PATH" )
146+ end
147+
149148tc .assertEqual(status , 0 , err )
150149tc .verifyEqual(msg , " 3" )
151150tc .verifyEqual(err , " " )
@@ -154,6 +153,12 @@ function test_java_stdin(tc, lang_in)
154153
155154function test_java_cwd(tc )
156155
156+ if isMATLABReleaseOlderThan(' R2022a' )
157+ td = tempdir ;
158+ else
159+ td = tc .createTemporaryFolder();
160+ end
161+
157162if ispc
158163 c = [" cmd" , " /c" , " dir" ];
159164else
@@ -165,7 +170,7 @@ function test_java_cwd(tc)
165170tc .verifyGreaterThan(strlength(m ), 0 , " empty directory not expected" )
166171tc .verifyEqual(strlength(e ), 0 , e )
167172
168- [s , mc , e ] = stdlib .java_run(c , cwd= tc . td );
173+ [s , mc , e ] = stdlib .java_run(c , cwd= td );
169174tc .assertEqual(s , 0 , " status non-zero" )
170175tc .verifyNotEqual(m , mc , " expected different directory to have different contents" )
171176tc .verifyEqual(strlength(e ), 0 , e )
0 commit comments