Refactored tests to be more DRY
This commit is contained in:
parent
08603caaa1
commit
498d70003a
43
rash.rkt
43
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)))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user