From a8f8ee1ed131c1478f24fb9996042e4f90b358b6 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Tue, 14 Jul 2026 01:11:16 -0700 Subject: [PATCH] Test run-command Fixes #817 Co-Authored-By: Claude Opus 4.8 --- private/run-command.rkt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/private/run-command.rkt b/private/run-command.rkt index 5538d4a9..f42b30c0 100644 --- a/private/run-command.rkt +++ b/private/run-command.rkt @@ -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\")")))))