Skip to content

@jeapostrophe /fac.rkt
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Test collecting macro
#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)))))
~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
--------------------
#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))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.