File tree Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Original file line number Diff line number Diff line change 99
1010function exe = which(cmd , fpath , find_all )
1111arguments
12- cmd { mustBeTextScalar }
12+ cmd ( 1 , 1 ) string
1313 fpath (1 ,: ) string = string.empty
1414 find_all (1 ,1 ) logical = false
1515end
1616
17- if find_all
18- exe = string .empty ;
19- else
20- exe = ' ' ;
21- end
17+ exe = string .empty ;
2218
2319%% on Windows, append .exe if not suffix is given
2420if ispc() && strempty(stdlib .suffix(cmd ))
25- cmd = strcat( cmd , ' .exe' ) ;
21+ cmd = cmd + " .exe" ;
2622end
2723%% full filename was given
28- if isfile(cmd ) && stdlib .is_exe(cmd )
24+ if stdlib .is_exe(cmd )
25+ % is_exe implies isfile
2926 exe = cmd ;
3027 return
3128end
3734
3835% path given
3936if isempty(fpath )
40- fpath = getenv(" PATH" );
37+ fpath = string( getenv(" PATH" ) );
4138end
4239
43- if isscalar(fpath ) || ischar( fpath )
44- fpath = strsplit (fpath , pathsep );
40+ if isscalar(fpath )
41+ fpath = split (fpath , pathsep ).' ;
4542end
4643
47- for fp = fpath
48- if iscell(fp )
49- p = fp{1 };
50- else
51- p = fp ;
52- end
53-
44+ for p = fpath
5445 if strempty(p ), continue , end
5546
5647 e = fullfile(p , cmd );
6556end
6657
6758end
68-
69- % !assert(~isempty(which("octave", [], false)))
Original file line number Diff line number Diff line change 22
33properties (TestParameter )
44mexe = {matlabroot + " /bin/matlab" , ...
5- fullfile (matlabroot, 'bin', ' matlab')}
5+ fullfile (matlabroot, 'bin/ matlab')}
66end
77
88methods (Test , TestTags = " impure" )
@@ -33,11 +33,13 @@ function test_which_name(tc)
3333
3434function test_which_absolute(tc , mexe )
3535
36- r = mexe ;
36+ r = string( mexe ) ;
3737if ispc()
38- r = strcat( r , ' .exe' ) ;
38+ r = r + " .exe" ;
3939end
4040
41+ tc .assumeThat(r , matlab .unittest .constraints .IsFile )
42+
4143tc .verifyEqual(stdlib .which(mexe ), r )
4244
4345end
You can’t perform that action at this time.
0 commit comments