os: prevent os.exists_in_system_path() from panicing

pull/9276/head
Delyan Angelov 2021-03-12 17:05:26 +02:00
parent 995db65471
commit def53fd73f
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 12 additions and 0 deletions

View File

@ -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)
} }

View File

@ -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
}