From acc561366f3fe6ec0377103f52ef0f7e923711c9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Mon, 1 Aug 2022 19:35:19 -0700 Subject: Modify the project structure. Now the lib directory contains what will eventually end up on the user's /usr/lib/csc. When I write make install, it will copy all of the .csc files from lib into the destination lib directory. This means I can start working on the standard library in lib/scheme. --- lib/csc/testing.csc | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 lib/csc/testing.csc (limited to 'lib/csc/testing.csc') diff --git a/lib/csc/testing.csc b/lib/csc/testing.csc new file mode 100644 index 0000000..68678ca --- /dev/null +++ b/lib/csc/testing.csc @@ -0,0 +1,91 @@ +(define-library (csc testing) + (export + assert + assert-equal + assert-raises + test + test-main) + (import (scheme base) + (only (scheme write) + display + write) + (only (csc compare) diff)) + (begin + + + (define *all-tests-succeeded* #t) + + + (define (set-all-succeeded! val) (set! *all-tests-succeeded* val)) + + + (define-record-type + (make-test-handle test-name) + test-handle? + (test-name test-name set-name!)) + + + (define-record-type + (make-test-error) + 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)) + (print "=== RUN " 'name "\n") + (guard (e ((test-error? e) + (print "--- FAIL: " 'name "\n") + (set-all-succeeded! #f))) + body body* ... + (print "--- PASS: " 'name "\n")))))) + + + (define-syntax assert + (syntax-rules () + ((assert expr) + (unless expr + (print (test-name *test-handle*) ": (assert " 'expr ") failed.\n") + (raise *test-error*))))) + + + (define-syntax assert-equal + (syntax-rules () + ((assert-equal left right transformers ...) + (let ((d (diff left right transformers ...))) + (unless (string=? "" d) + (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))))) + + + (define (test-main) + (if *all-tests-succeeded* + (print "PASS\n") + (print "FAIL\n"))))) -- cgit v1.3.1