public
Created

Test collecting macro

  • Download Gist
fac.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#lang racket
 
(define (! n)
(if (zero? n)
1
(* n (! (sub1 n)))))
 
(module* test-manual #f
(require rackunit)
(printf "Factorial testing (manual)!\n")
(check-equal? (! 0) 1)
(check-equal? (! 1) 1)
(check-equal? (! 5) 120)
(check-equal? (! 10) 3628800)
(check-equal? (! 2) 3))
 
(require "test.rkt")
(define-test test
(require rackunit))
(test (printf "Factorial testing!\n"))
(test (check-equal? (! 0) 1))
(test (check-equal? (! 1) 1))
(test (check-equal? (! 5) 120))
(test (check-equal? (! 10) 3628800))
(test (check-equal? (! 2) 3))
 
(module* main #f
(command-line
#:args (n)
(printf "Factorial!\n")
(displayln (! (string->number n)))))
output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
~scm/usr.plt.ro/mflatt/submodules
% bin/racket tmp/fac.rkt -- 10
Factorial!
3628800
 
~scm/usr.plt.ro/mflatt/submodules
% bin/racket tmp/test.rkt -- tmp/fac.rkt
Test harness!
Factorial testing (manual)!
--------------------
FAILURE
name: check-equal?
location: (#<path:/home/jay/Dev/scm/usr.plt.ro/mflatt/submodules/tmp/fac.rkt> 15 2 276 22)
expression: (check-equal? (! 2) 3)
actual: 2
expected: 3
 
Check failure
--------------------
Factorial testing!
--------------------
FAILURE
name: check-equal?
location: (#<path:/home/jay/Dev/scm/usr.plt.ro/mflatt/submodules/tmp/fac.rkt> 25 6 536 22)
expression: (check-equal? (! 2) 3)
actual: 2
expected: 3
 
Check failure
--------------------
test.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#lang racket/base
(require (for-syntax racket/base
racket/syntax))
 
(define-syntax (define-test-module stx)
(syntax-case stx ()
[(_ id-stxs-id)
(quasisyntax/loc stx
(module* test #f
#,@(unbox (syntax-local-value #'id-stxs-id))))]))
 
(define-syntax (define-test stx)
(syntax-case stx ()
[(_ id ie ...)
(with-syntax ([id-stxs (generate-temporary 'id-stxs)])
(syntax-local-lift-module-end-declaration
(syntax/loc stx (define-test-module id-stxs)))
(syntax/loc stx
(begin
(define-syntax id-stxs
(box (list #'ie ...)))
(define-syntax (id stx)
(syntax-case stx ()
[(_ e (... ...))
(syntax/loc stx
(begin-for-syntax
(define b (syntax-local-value #'id-stxs))
(set-box! b
(append (unbox b)
(syntax->list #'(e (... ...)))))))])))))]))
 
(provide define-test)
 
(module* main racket/base
(require racket/cmdline)
(command-line
#:args fs
(printf "Test harness!\n")
(for ([f (in-list fs)])
(dynamic-require `(submod ,f test-manual) #f)
(dynamic-require `(submod ,f test) #f))))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.