Skip to content

Commit

Permalink
Simplify tests with-gasmine-output-to-port etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kana committed Nov 10, 2011
1 parent 91d2e7c commit d6ef4f6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 119 deletions.
67 changes: 22 additions & 45 deletions t/before-after.t
Expand Up @@ -4,41 +4,20 @@
(use gauche.parameter) (use gauche.parameter)
(use test.gasmine) (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" (describe "before"
(it "should be evaluate before evaluating a spec" (it "should be evaluate before evaluating a spec"
(expect (expect
(parameterize ([all-suites '()]) (let1 stack '()
(let1 stack '() (with-gasmine-output-to-null
(describe "-" (lambda ()
(before (push! stack "b1")) (describe "-"
(before (push! stack "b2")) (before (push! stack "b1"))
(before (push! stack "b3")) (before (push! stack "b2"))
(it "i1" (push! stack "i1")) (before (push! stack "b3"))
(it "i2" (push! stack "i2")) (it "i1" (push! stack "i1"))
(it "i3" (push! stack "i3")) (it "i2" (push! stack "i2"))
) (it "i3" (push! stack "i3")))))
(with-output-to-null (reverse stack))
run-suites)
(reverse stack)))
equal? equal?
'("b1" "b2" "b3" "i1" '("b1" "b2" "b3" "i1"
"b1" "b2" "b3" "i2" "b1" "b2" "b3" "i2"
Expand All @@ -49,19 +28,17 @@
(describe "after" (describe "after"
(it "should be evaluate after evaluating a spec" (it "should be evaluate after evaluating a spec"
(expect (expect
(parameterize ([all-suites '()]) (let1 stack '()
(let1 stack '() (with-gasmine-output-to-null
(describe "-" (lambda ()
(after (push! stack "a1")) (describe "-"
(after (push! stack "a2")) (after (push! stack "a1"))
(after (push! stack "a3")) (after (push! stack "a2"))
(it "i1" (push! stack "i1")) (after (push! stack "a3"))
(it "i2" (push! stack "i2")) (it "i1" (push! stack "i1"))
(it "i3" (push! stack "i3")) (it "i2" (push! stack "i2"))
) (it "i3" (push! stack "i3")))))
(with-output-to-null (reverse stack))
run-suites)
(reverse stack)))
equal? equal?
'("i1" "a1" "a2" "a3" '("i1" "a1" "a2" "a3"
"i2" "a1" "a2" "a3" "i2" "a1" "a2" "a3"
Expand Down
73 changes: 41 additions & 32 deletions t/evaluation-order.t
@@ -1,43 +1,52 @@
#!/usr/bin/env gosh #!/usr/bin/env gosh


(add-load-path ".") (add-load-path ".")
(use gauche.parameter)
(use test.gasmine) (use test.gasmine)


(define stack '()) (define (with-output-to-null thunk)

(let1 result #f
(describe "suite 1" (with-output-to-string
(push! stack "1") (lambda ()
(it "is dummy" (set! result (thunk))))
(push! stack "1-1")) result))
(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")))


(describe "suite evaluation order" (describe "suite evaluation order"
(it "should evaluate suites and specs in order of definition" (it "should evaluate suites and specs in order of definition"
(expect (reverse stack) equal? '("1" "2" "3" (expect
"1-1" "1-2" "1-3" (let1 stack '()
"2-1" "2-2" "2-3" (with-gasmine-output-to-null
"3-1" "3-2" "3-3")))) (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) (run-suites)


Expand Down
72 changes: 30 additions & 42 deletions t/it-syntax.t
Expand Up @@ -10,26 +10,22 @@


(it "should output its description" (it "should output its description"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should succeed"
(it "should succeed" (expect #t eq? #t)))))
(expect #t eq? #t)))
(run-suites))))
equal? equal?
(unlines "ok 1 - should succeed" (unlines "ok 1 - should succeed"
"1..1")) "1..1"))
) )
(it "should output details about failure with expected value" (it "should output details about failure with expected value"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should fail"
(it "should fail" (expect '(#t) equal? '(#f))))))
(expect '(#t) equal? '(#f))))
(run-suites))))
equal? equal?
(unlines "not ok 1 - should fail" (unlines "not ok 1 - should fail"
"# Expected '(#t) equal? '(#f)" "# Expected '(#t) equal? '(#f)"
Expand All @@ -39,14 +35,12 @@
) )
(it "should output details about failure without expected value" (it "should output details about failure without expected value"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should match"
(it "should match" (define (foo) "foo")
(define (foo) "foo") (expect (foo) #/^bar$/)))))
(expect (foo) #/^bar$/)))
(run-suites))))
equal? equal?
(unlines "not ok 1 - should match" (unlines "not ok 1 - should match"
"# Expected (foo) #/^bar$/" "# Expected (foo) #/^bar$/"
Expand All @@ -55,16 +49,14 @@
) )
(it "should output details about evaluation failure" (it "should output details about evaluation failure"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should fail"
(it "should fail" (expect (#t) equal? '(#f))))
(expect (#t) equal? '(#f)))) (describe "-"
(describe "-" (it "should fail"
(it "should fail" (expect '(#t) equal? (#f))))))
(expect '(#t) equal? (#f))))
(run-suites))))
equal? equal?
(unlines "not ok 1 - should fail" (unlines "not ok 1 - should fail"
"# Expected (#t) equal? '(#f)" "# Expected (#t) equal? '(#f)"
Expand All @@ -80,28 +72,24 @@
) )
(it "should output its description with SKIP message" (it "should output its description with SKIP message"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should succeed"
(it "should succeed" (SKIP "required tools not found")))))
(SKIP "required tools not found")))
(run-suites))))
equal? equal?
(unlines "ok 1 - # SKIP should succeed (required tools not found)" (unlines "ok 1 - # SKIP should succeed (required tools not found)"
"1..1")) "1..1"))
) )
(it "should output its description with TODO message" (it "should output its description with TODO message"
(expect (expect
(with-output-to-string (with-gasmine-output-to-string
(lambda () (lambda ()
(parameterize ([all-suites '()]) (describe "-"
(describe "-" (it "should succeed"
(it "should succeed" (TODO))
(TODO)) (it "should succeed"
(it "should succeed" (TODO "known breakage")))))
(TODO "known breakage")))
(run-suites))))
equal? equal?
(unlines "not ok 1 - # TODO should succeed" (unlines "not ok 1 - # TODO should succeed"
"not ok 2 - # TODO should succeed (known breakage)" "not ok 2 - # TODO should succeed (known breakage)"
Expand Down

0 comments on commit d6ef4f6

Please sign in to comment.