11classdef TestWhich < matlab .unittest .TestCase
22
33properties (TestParameter )
4- mexe = {matlabroot + " /bin/" + matlab_name() , ...
5- fullfile (matlabroot, 'bin', matlab_name() )}
4+ mexe = {matlabroot + " /bin/matlab " , ...
5+ fullfile (matlabroot, 'bin', 'matlab' )}
66end
77
88methods (Test , TestTags = " impure" )
@@ -12,16 +12,21 @@ function test_which_name(tc)
1212tc .verifyEmpty(stdlib .which(tempname()))
1313
1414if ispc
15- n = ' pwsh.exe' ;
15+ names = [ " pwsh" , " pwsh .exe" ] ;
1616else
17- n = ' ls ' ;
17+ names = " ls " ;
1818end
1919%% which: Matlab in environment variable PATH
2020% MacOS Matlab does not source .zshrc so Matlab is not on internal Matlab PATH
2121% Unix-like OS may have Matlab as alias which is not visible to
2222% stdlib.which()
2323% virus scanners may block stdlib.which("cmd.exe") on Windows
24- tc .verifyNotEmpty(stdlib .which(n ))
24+ for n = names
25+ exe = stdlib .which(n );
26+ tc .verifyNotEmpty(exe , " Executable not found: " + n )
27+ tc .verifyTrue(isfile(exe ), " Executable is not a file: " + n )
28+ tc .verifyTrue(stdlib .is_exe(exe ), " Executable is not executable: " + n )
29+ end
2530
2631end
2732
@@ -31,28 +36,23 @@ function test_which_absolute(tc, mexe)
3136end
3237
3338
34- function test_which_multipath (tc )
39+ function test_which_onepath (tc )
3540
36- n = matlab_name();
41+ tc .verifyNotEmpty(stdlib .which(" matlab" , fullfile(matlabroot , ' bin' )), ...
42+ " Matlab not found by which() given specific path=" )
3743
38- paths = split(string(getenv(' PATH' )), pathsep );
39- paths(end + 1 ) = matlabroot + " /bin" ;
44+ end
4045
41- exe = stdlib .which(n , paths );
4246
43- tc .verifyNotEmpty( exe , " Matlab not found by which() " )
47+ function test_which_multipath( tc )
4448
45- end
49+ paths = split(string(getenv(' PATH' )), pathsep );
50+ paths(end + 1 ) = fullfile(matlabroot , ' bin' );
4651
47- end
52+ tc .verifyNotEmpty( stdlib .which( " matlab " , paths ), " Matlab not found by which() " )
4853
4954end
5055
51-
52- function n = matlab_name()
53-
54- n = ' matlab' ;
55- if ispc
56- n = strcat(n , ' .exe' );
5756end
57+
5858end
0 commit comments