Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify tests with-gasmine-output-to-port etc

  • Loading branch information...
commit d6ef4f607e6af5a86aec30a62a3b2b73318a8f16 1 parent 91d2e7c
@kana authored
Showing with 93 additions and 119 deletions.
  1. +22 −45 t/before-after.t
  2. +41 −32 t/evaluation-order.t
  3. +30 −42 t/it-syntax.t
View
67 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"
View
73 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)
View
72 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)"
Please sign in to comment.
Something went wrong with that request. Please try again.