From f6cccfb501175ba15a1bd529c7228c22c57152a9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 28 Jul 2022 19:55:37 -0700 Subject: Improve the strings API. I'm just copying the go strings library API. --- csc/testing.csc | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'csc/testing.csc') 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"))))) -- cgit v1.3.1