Handle command not found with status 127

* geesh/shell.scm (sh:exec-let): Print a message and set the status to
127 when path search fails.
* tests/shell.scm: Update test.
This commit is contained in:
Timothy Sample 2018-11-25 19:57:01 -05:00
parent 2c1dd2d67e
commit 8c061471d3
2 changed files with 8 additions and 10 deletions

View File

@ -111,7 +111,10 @@ environment variable bindings @var{bindings}."
(and=> (find-utility name)
(lambda (path)
(exec-utility bindings path name args)))
(error "Command not found."))
(begin (format (current-error-port)
"~a: ~a: Command not found.~%"
(car (program-arguments)) name)
(set-status! 127)))
(exec-utility bindings name name args)))
(define (sh:exec name . args)

View File

@ -106,19 +106,14 @@
(lambda () (sh:exec "utility")))
(file-exists? sentinal)))))
(test-assert "Throws error if a utility cannot be found"
(test-equal "Sets status to 127 if a utility cannot be found"
127
(call-with-temporary-directory
(lambda (directory)
(with-variables `(("PATH" . ,directory))
(lambda ()
(catch #t
(lambda ()
(sh:exec "utility")
#f)
(lambda args
(match args
(('misc-error _ _ ("Command not found.") _) #t)
(_ #f)))))))))
(sh:exec "utility")
(get-status))))))
(test-equal "Executes regular built-ins"
"foo bar\n"