Hi Shriram,
If you think you would find this useful, I'll make a point to do the Scribble this weekend.
Here's the synopsis statement:
;;======================================================================
;; The racket testing module has a few things I wish it did differently:
;;
;; 1) The test function names are verbose and redundant. check-this, check-that, etc
;;
;; 2) The test functions display nothing on success. There's no way
;; to tell the difference between "no tests ran" and "all tests
;; succeeded"
;;
;; 3) The tests return nothing. You can't do conditional tests like:
;; (unless (is os 'windows) (ok test-that-won't-pass-on-windows))
Some quick examples; there's quite a lot more that can be done with it if this looks useful. The output is shown after the code.
#lang racket
(require handy/test-more)
(expect-n-tests 4)
(test-suite
"examples"
(struct person (name age) #:transparent)
(define people (hash 'alice (person "alice" 19) 'bob (person "bob" 17)))
; basic equality testing
(is (* 1 2) 2 "(* 1 2) = 2")
(is-false (hash-has-key? people 'charlie) "as expected, don't know charlie")
(isnt (hash-has-key? people 'charlie) "same as above")
; Tests return values so you can chain them or nest them
(lives
(thunk
(and (ok (hash-has-key? people 'alice) "we have an entry for alice")
(let ([alice (hash-ref people 'alice)])
(is (person-age alice) 19 "alice is 19")
(like (person-name alice) #px"^alice$" "alice's name is string, lowercase, trimmed"))))
"alice-related tests did not raise exception")
; exceptions
(define thnk (thunk (+ 1 "foo")))
(dies thnk "it died, that's all I care about")
(throws thnk exn:fail:contract? "match against an arbitrary predicate")
(throws thnk #px"expected: number.+\"foo\"" "match against a regex")
(is (throws thnk (lambda (e) 'ok) "throws can pass exn to arbitrary one-arg proc for testing")
'ok
#:op (lambda (got expected)
(if (exn? got) 'ok 'nope))
"tested 'throws' with hand-rolled predicate, then chained into `is` using hand-rolled equality testing (the equality test is illustrative but not sensible)")
)
When you run the above code, the following will be sent to STDOUT. Note that it tracks the number of tests it runs, numbers them, and warns you that you didn't run the expected number.
######## (START test-suite: examples)
ok 1 - (* 1 2) = 2
ok 2 - as expected, don't know charlie
ok 3
ok 4 - we have an entry for alice
ok 5 - alice is 19
ok 6 - alice's name is string, lowercase, trimmed
ok 7 - alice-related tests did not raise exception
ok 8 - it died, that's all I care about
ok 9 - match against an arbitrary predicate
ok 10 - match against a regex
ok 11 - throws can pass exn to arbitrary one-arg proc for testing
ok 12 - tested 'throws' with hand-rolled predicate, then chained into `is` using hand-rolled e$
ok 13 - test-suite completed without throwing uncaught exception
Total tests passed so far: 13
Total tests failed so far: 0
######## (END test-suite: examples)
!!ERROR!!: Expected 4 tests, actually saw 13