Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions private/run-command.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,26 @@
"command" (string-join (cons cmd-name stringified-args) " ")
"stderr" stderr-string))
stdout-string)


(module+ test
(require rackunit)

;; Use the running Racket executable so these tests need no platform-specific commands on $PATH.
(define racket-exe
(path->string (find-executable-path (find-system-path 'exec-file))))

(test-case "run-command returns the subprocess's stdout"
(check-equal? (run-command racket-exe "-e" "(display \"hello\")") "hello"))

(test-case "run-command raises when the executable isn't in $PATH"
(check-exn #rx"couldn't find executable in \\$PATH"
(λ () (run-command "resyntax-nonexistent-executable-a1b2c3"))))

(test-case "run-command raises when the command exits with a nonzero code"
(check-exn #rx"command exited with a nonzero exit code"
(λ () (run-command racket-exe "-e" "(exit 1)"))))

(test-case "run-command raises when the command writes to stderr"
(check-exn #rx"command exited successfully, but wrote to stderr"
(λ () (run-command racket-exe "-e" "(eprintf \"oops\")")))))
Loading