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,47 +12,54 @@ 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
2833
2934function test_which_absolute(tc , mexe )
30- tc .verifyEqual(stdlib .which(mexe ), mexe )
31- end
3235
36+ r = mexe ;
37+ if ispc()
38+ r = strcat(r , ' .exe' );
39+ end
3340
34- function test_which_multipath( tc )
41+ tc .verifyEqual( stdlib .which( mexe ), r )
3542
36- n = matlab_name();
43+ end
3744
38- paths = split(string(getenv(' PATH' )), pathsep );
39- paths(end + 1 ) = matlabroot + " /bin" ;
4045
41- exe = stdlib .which( n , paths );
46+ function test_which_onepath( tc )
4247
43- tc .verifyNotEmpty(exe , " Matlab not found by which()" )
48+ tc .verifyNotEmpty(stdlib .which(" matlab" , fullfile(matlabroot , ' bin' )), ...
49+ " Matlab not found by which() given specific path=" )
4450
4551end
4652
47- end
4853
49- end
54+ function test_which_multipath( tc )
5055
56+ paths = split(string(getenv(' PATH' )), pathsep );
57+ paths(end + 1 ) = fullfile(matlabroot , ' bin' );
5158
52- function n = matlab_name( )
59+ tc .verifyNotEmpty( stdlib .which( " matlab " , paths ), " Matlab not found by which() " )
5360
54- n = ' matlab' ;
55- if ispc
56- n = strcat(n , ' .exe' );
5761end
62+
63+ end
64+
5865end
0 commit comments