From 498d70003a55b27f8e3659113929e44cf4c4fbda Mon Sep 17 00:00:00 2001 From: Cristian Esquivias Date: Tue, 12 Aug 2014 19:19:28 -0700 Subject: [PATCH] Refactored tests to be more DRY --- rash.rkt | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/rash.rkt b/rash.rkt index 6e719c9..f250c9e 100644 --- a/rash.rkt +++ b/rash.rkt @@ -25,32 +25,29 @@ (require racket/match) (require racket/system) + (define (launch-racket command stdin) + (define stdout (open-output-string)) + (match-let ([(list _ _ pid stderr state-fn) + (process*/ports stdout + stdin + (current-error-port) + (find-executable-path "racket") + "-e" + command)]) + (state-fn 'wait)) + stdout) + (test-case "Spawn a sub process with current-output-port for stdout and current-error-port for stderr. stdin is not used." - (let ([stdout (open-output-string)]) - (match-let ([(list _ stdin pid stderr state-fn) - (process*/ports - stdout - #f - (current-error-port) - (find-executable-path "racket") - "-e" - "(require \"rash.rkt\") (start \"echo\" '(\"hello\"))")]) - (state-fn 'wait) - (check string=? "hello\n" (get-output-string stdout))))) + (define stdout (launch-racket + "(require \"rash.rkt\") (start \"echo\" '(\"hello\"))" + #f)) + (check string=? "hello\n" (get-output-string stdout))) (test-case "Spawn a sub process with piping in stdin." - (let ([stdout (open-output-string)]) - (match-let ([(list _ _ pid stderr state-fn) - (process*/ports - stdout - (open-input-string "hello") - (current-error-port) - (find-executable-path "racket") - "-e" - "(require \"rash.rkt\") (start \"wc\" '(\"-c\") #:stdin (current-input-port))")]) - (state-fn 'wait) - (check string=? "5" (string-trim (get-output-string stdout)))))) -) + (define stdout (launch-racket + "(require \"rash.rkt\") (start \"wc\" '(\"-c\") #:stdin (current-input-port))" + (open-input-string "hello"))) + (check string=? "5" (string-trim (get-output-string stdout)))))