os: prevent os.exists_in_system_path() from panicing
parent
995db65471
commit
def53fd73f
|
@ -375,6 +375,9 @@ fn executable_fallback() string {
|
||||||
// find_exe_path walks the environment PATH, just like most shell do, it returns
|
// find_exe_path walks the environment PATH, just like most shell do, it returns
|
||||||
// the absolute path of the executable if found
|
// the absolute path of the executable if found
|
||||||
pub fn find_abs_path_of_executable(exepath string) ?string {
|
pub fn find_abs_path_of_executable(exepath string) ?string {
|
||||||
|
if exepath == '' {
|
||||||
|
return error('expected non empty `exepath`')
|
||||||
|
}
|
||||||
if is_abs_path(exepath) {
|
if is_abs_path(exepath) {
|
||||||
return real_path(exepath)
|
return real_path(exepath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,3 +543,12 @@ fn test_posix_set_bit() {
|
||||||
rm(fpath) or {}
|
rm(fpath) or {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_exists_in_system_path() {
|
||||||
|
assert os.exists_in_system_path('') == false
|
||||||
|
$if windows {
|
||||||
|
assert os.exists_in_system_path('cmd') == true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert os.exists_in_system_path('ls') == true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue