From d6ef4f607e6af5a86aec30a62a3b2b73318a8f16 Mon Sep 17 00:00:00 2001 From: kana Date: Thu, 10 Nov 2011 17:04:03 +0900 Subject: [PATCH] Simplify tests with-gasmine-output-to-port etc --- t/before-after.t | 67 +++++++++++++--------------------------- t/evaluation-order.t | 73 +++++++++++++++++++++++++------------------- t/it-syntax.t | 72 ++++++++++++++++++------------------------- 3 files changed, 93 insertions(+), 119 deletions(-) diff --git a/t/before-after.t b/t/before-after.t index 181c110..0b0c722 100755 --- a/t/before-after.t +++ b/t/before-after.t @@ -4,41 +4,20 @@ (use gauche.parameter) (use test.gasmine) -(define (with-output-to-null thunk) - (let1 result #f - (with-output-to-string - (lambda () - (set! result (thunk)))) - result)) - -(describe "with-output-to-null" - (it "should discard output to the current port" - (expect - (with-output-to-null - (lambda () - (write "hi") - 'hey)) - eq? - 'hey) - ) - ) - (describe "before" (it "should be evaluate before evaluating a spec" (expect - (parameterize ([all-suites '()]) - (let1 stack '() - (describe "-" - (before (push! stack "b1")) - (before (push! stack "b2")) - (before (push! stack "b3")) - (it "i1" (push! stack "i1")) - (it "i2" (push! stack "i2")) - (it "i3" (push! stack "i3")) - ) - (with-output-to-null - run-suites) - (reverse stack))) + (let1 stack '() + (with-gasmine-output-to-null + (lambda () + (describe "-" + (before (push! stack "b1")) + (before (push! stack "b2")) + (before (push! stack "b3")) + (it "i1" (push! stack "i1")) + (it "i2" (push! stack "i2")) + (it "i3" (push! stack "i3"))))) + (reverse stack)) equal? '("b1" "b2" "b3" "i1" "b1" "b2" "b3" "i2" @@ -49,19 +28,17 @@ (describe "after" (it "should be evaluate after evaluating a spec" (expect - (parameterize ([all-suites '()]) - (let1 stack '() - (describe "-" - (after (push! stack "a1")) - (after (push! stack "a2")) - (after (push! stack "a3")) - (it "i1" (push! stack "i1")) - (it "i2" (push! stack "i2")) - (it "i3" (push! stack "i3")) - ) - (with-output-to-null - run-suites) - (reverse stack))) + (let1 stack '() + (with-gasmine-output-to-null + (lambda () + (describe "-" + (after (push! stack "a1")) + (after (push! stack "a2")) + (after (push! stack "a3")) + (it "i1" (push! stack "i1")) + (it "i2" (push! stack "i2")) + (it "i3" (push! stack "i3"))))) + (reverse stack)) equal? '("i1" "a1" "a2" "a3" "i2" "a1" "a2" "a3" diff --git a/t/evaluation-order.t b/t/evaluation-order.t index 0bbf4bc..33646a3 100755 --- a/t/evaluation-order.t +++ b/t/evaluation-order.t @@ -1,43 +1,52 @@ #!/usr/bin/env gosh (add-load-path ".") +(use gauche.parameter) (use test.gasmine) -(define stack '()) - -(describe "suite 1" - (push! stack "1") - (it "is dummy" - (push! stack "1-1")) - (it "is dummy" - (push! stack "1-2")) - (it "is dummy" - (push! stack "1-3"))) - -(describe "suite 2" - (push! stack "2") - (it "is dummy" - (push! stack "2-1")) - (it "is dummy" - (push! stack "2-2")) - (it "is dummy" - (push! stack "2-3"))) - -(describe "suite 3" - (push! stack "3") - (it "is dummy" - (push! stack "3-1")) - (it "is dummy" - (push! stack "3-2")) - (it "is dummy" - (push! stack "3-3"))) +(define (with-output-to-null thunk) + (let1 result #f + (with-output-to-string + (lambda () + (set! result (thunk)))) + result)) (describe "suite evaluation order" (it "should evaluate suites and specs in order of definition" - (expect (reverse stack) equal? '("1" "2" "3" - "1-1" "1-2" "1-3" - "2-1" "2-2" "2-3" - "3-1" "3-2" "3-3")))) + (expect + (let1 stack '() + (with-gasmine-output-to-null + (lambda () + (describe "suite 1" + (push! stack "1") + (it "is dummy" + (push! stack "1-1")) + (it "is dummy" + (push! stack "1-2")) + (it "is dummy" + (push! stack "1-3"))) + (describe "suite 2" + (push! stack "2") + (it "is dummy" + (push! stack "2-1")) + (it "is dummy" + (push! stack "2-2")) + (it "is dummy" + (push! stack "2-3"))) + (describe "suite 3" + (push! stack "3") + (it "is dummy" + (push! stack "3-1")) + (it "is dummy" + (push! stack "3-2")) + (it "is dummy" + (push! stack "3-3"))))) + (reverse stack)) + equal? + '("1" "2" "3" + "1-1" "1-2" "1-3" + "2-1" "2-2" "2-3" + "3-1" "3-2" "3-3")))) (run-suites) diff --git a/t/it-syntax.t b/t/it-syntax.t index cb035c0..b829df7 100755 --- a/t/it-syntax.t +++ b/t/it-syntax.t @@ -10,26 +10,22 @@ (it "should output its description" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should succeed" - (expect #t eq? #t))) - (run-suites)))) + (describe "-" + (it "should succeed" + (expect #t eq? #t))))) equal? (unlines "ok 1 - should succeed" "1..1")) ) (it "should output details about failure with expected value" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should fail" - (expect '(#t) equal? '(#f)))) - (run-suites)))) + (describe "-" + (it "should fail" + (expect '(#t) equal? '(#f)))))) equal? (unlines "not ok 1 - should fail" "# Expected '(#t) equal? '(#f)" @@ -39,14 +35,12 @@ ) (it "should output details about failure without expected value" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should match" - (define (foo) "foo") - (expect (foo) #/^bar$/))) - (run-suites)))) + (describe "-" + (it "should match" + (define (foo) "foo") + (expect (foo) #/^bar$/))))) equal? (unlines "not ok 1 - should match" "# Expected (foo) #/^bar$/" @@ -55,16 +49,14 @@ ) (it "should output details about evaluation failure" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should fail" - (expect (#t) equal? '(#f)))) - (describe "-" - (it "should fail" - (expect '(#t) equal? (#f)))) - (run-suites)))) + (describe "-" + (it "should fail" + (expect (#t) equal? '(#f)))) + (describe "-" + (it "should fail" + (expect '(#t) equal? (#f)))))) equal? (unlines "not ok 1 - should fail" "# Expected (#t) equal? '(#f)" @@ -80,28 +72,24 @@ ) (it "should output its description with SKIP message" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should succeed" - (SKIP "required tools not found"))) - (run-suites)))) + (describe "-" + (it "should succeed" + (SKIP "required tools not found"))))) equal? (unlines "ok 1 - # SKIP should succeed (required tools not found)" "1..1")) ) (it "should output its description with TODO message" (expect - (with-output-to-string + (with-gasmine-output-to-string (lambda () - (parameterize ([all-suites '()]) - (describe "-" - (it "should succeed" - (TODO)) - (it "should succeed" - (TODO "known breakage"))) - (run-suites)))) + (describe "-" + (it "should succeed" + (TODO)) + (it "should succeed" + (TODO "known breakage"))))) equal? (unlines "not ok 1 - # TODO should succeed" "not ok 2 - # TODO should succeed (known breakage)"