From 87c34b102341d9119c209cdddaff64d8ffd91977 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 8 Jul 2014 07:11:41 +0100 Subject: [PATCH] pkg-build/thread: fix test --- pkgs/plt-services/meta/pkg-build/thread.rkt | 66 +++++++++++++++------ 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/pkgs/plt-services/meta/pkg-build/thread.rkt b/pkgs/plt-services/meta/pkg-build/thread.rkt index 1b0a2f96c2..8876769b2a 100644 --- a/pkgs/plt-services/meta/pkg-build/thread.rkt +++ b/pkgs/plt-services/meta/pkg-build/thread.rkt @@ -89,21 +89,51 @@ ;; -------------------------------------------------- -(module+ test - (define t1 (thread/chunk-output - (lambda () - (printf "hi\n") - (eprintf "bye\n") - (flush-chunk-output) - (sleep) - (printf "HI\n") - (eprintf "BYE\n")))) - (define t2 (thread/chunk-output - (lambda () - (printf "hola\n") - (eprintf "adios\n") - (flush-chunk-output) - (sleep) - (printf "HOLA\n") - (eprintf "ADIOS\n")))) - (wait-chunk-output)) +(module test racket/base + (define o (open-output-bytes)) + (parameterize ([current-output-port o] + [current-error-port o]) + (define-syntax-rule (def id) + (define id + (dynamic-require (module-path-index-join + `(submod "..") + (variable-reference->module-path-index + (#%variable-reference))) + 'id))) + (def thread/chunk-output) + (def flush-chunk-output) + (def wait-chunk-output) + (define t1 (thread/chunk-output + (lambda () + (printf "hi\n") + (eprintf "bye\n") + (flush-chunk-output) + (sleep) + (printf "HI\n") + (eprintf "BYE\n")))) + (define t2 (thread/chunk-output + (lambda () + (printf "hola\n") + (eprintf "adios\n") + (flush-chunk-output) + (sleep) + (printf "HOLA\n") + (eprintf "ADIOS\n")))) + (wait-chunk-output)) + (let ([l '("hi\nbye" "hola\nadios")] + [s (get-output-string o)] + [sa (lambda (a b) (string-append (car a) + "\n" + (cadr a) + "\n" + (car b) + "\n" + (cadr b) + "\n"))] + [r reverse] + [u (lambda (l) (map string-upcase l))]) + (unless (or (equal? s (sa l (u l))) + (equal? s (sa (r l) (u l))) + (equal? s (sa (r l) (u (r l)))) + (equal? s (sa l (u (r l))))) + (error "mismatch: " s))))