/trunk/Examples/test-suite/guile/testsuite.scm
Lisp | 37 lines | 30 code | 6 blank | 1 comment | 0 complexity | 818689b709ad889397aa95f86c93f3c8 MD5 | raw file
1;; Little helper functions and macros for the run tests 2 3(use-modules (ice-9 format)) 4 5(define (test-error error-format . args) 6 (display "Runtime check failed. ") 7 (apply format #t error-format args) 8 (newline) 9 (exit 1)) 10 11(define-macro (expect-true form) 12 `(if (not ,form) 13 (test-error "Expected true value of ~A" ',form))) 14 15(define-macro (expect-false form) 16 `(if ,form 17 (test-error "Expected false value of ~A" ',form))) 18 19(define-macro (expect-result expected-result-form equal? form) 20 `(let ((expected-result ,expected-result-form) 21 (result ,form)) 22 (if (not (,equal? result expected-result)) 23 (test-error "The result of ~A was ~A, expected ~A, which is not ~A" 24 ',form result expected-result ',equal?)))) 25 26(define-macro (expect-throw tag-form form) 27 `(let ((tag ,tag-form)) 28 (if (catch #t 29 (lambda () 30 ,form 31 #t) 32 (lambda (key . args) 33 (if (eq? key ,tag-form) 34 #f 35 (test-error "The form ~A threw to ~A (expected a throw to ~A)" 36 ',form key tag)))) 37 (test-error "The form ~A returned normally (expected a throw to ~A)"))))