aboutsummaryrefslogtreecommitdiffstats
path: root/csc/testing.csc
diff options
context:
space:
mode:
Diffstat (limited to 'csc/testing.csc')
-rw-r--r--csc/testing.csc54
1 files changed, 31 insertions, 23 deletions
diff --git a/csc/testing.csc b/csc/testing.csc
index 3fa8ad5..68678ca 100644
--- a/csc/testing.csc
+++ b/csc/testing.csc
@@ -6,10 +6,10 @@
test
test-main)
(import (scheme base)
- (only (csc compare) diff)
- (only (csc format)
- printf
- sprintf))
+ (only (scheme write)
+ display
+ write)
+ (only (csc compare) diff))
(begin
@@ -30,32 +30,41 @@
test-error?)
+ (define *test-error* (make-test-error))
+
+
(define *test-handle* (make-test-handle "global"))
+ (define (print . xs)
+ (unless (null? xs)
+ (let ((x (car xs)))
+ (if (or (string? x)
+ (symbol? x))
+ (display x)
+ (write x)))
+ (apply print (cdr xs))))
+
+
(define-syntax test
(syntax-rules ()
((test name body body* ...)
(begin
(set-name! *test-handle* (symbol->string 'name))
- (printf "=== RUN {}\n" 'name)
+ (print "=== RUN " 'name "\n")
(guard (e ((test-error? e)
- (printf "--- FAIL: {}\n" 'name)
- (set-all-succeeded! #f)))
+ (print "--- FAIL: " 'name "\n")
+ (set-all-succeeded! #f)))
body body* ...
- (printf "--- PASS: {}\n" 'name))))))
-
-
- (define (fatalf format-string . format-args)
- (printf "{}: {}\n" (test-name *test-handle*) (apply sprintf format-string format-args))
- (raise (make-test-error)))
+ (print "--- PASS: " 'name "\n"))))))
(define-syntax assert
(syntax-rules ()
((assert expr)
(unless expr
- (fatalf "(assert {}) failed." 'expr)))))
+ (print (test-name *test-handle*) ": (assert " 'expr ") failed.\n")
+ (raise *test-error*)))))
(define-syntax assert-equal
@@ -63,21 +72,20 @@
((assert-equal left right transformers ...)
(let ((d (diff left right transformers ...)))
(unless (string=? "" d)
- (fatalf "Fatal:\n {}\nis not equal to\n {}.\ndiff (-left +right):\n{}" 'left 'right d))))
- ((assert-equal left right)
- (assert-equal equal? left right))))
+ (print "Fatal:\n " 'left "\nis not equal to\n " 'right "\ndiff (-left +right):\n" d "\n")
+ (raise *test-error*))))))
(define-syntax assert-raises
(syntax-rules ()
((assert-raises predicate body body* ...)
- (assert
- (guard (e ((predicate e) #t))
- body body* ...
- #f)))))
+ (assert
+ (guard (e ((predicate e) #t))
+ body body* ...
+ #f)))))
(define (test-main)
(if *all-tests-succeeded*
- (printf "PASS\n")
- (printf "FAIL\n")))))
+ (print "PASS\n")
+ (print "FAIL\n")))))