~ chicken-core (chicken-5) /tests/scrutinizer-tests.scm
Trap1;;; scrutinizer unit tests23(import-for-syntax4 (chicken format)5 (chicken compiler scrutinizer))67(define-for-syntax success #t)89(define-syntax test10 (er-macro-transformer11 (lambda (expr rename _)12 (define extra-fail-info '())13 (define (add-fail-info msg)14 (set! extra-fail-info (cons (string-append " " msg) extra-fail-info))15 #f)16 (define pass17 (let loop ((e (cadr expr)))18 (case (car e)19 ;; invert test20 ((not) (not (loop (cadr e))))21 ;; subtype or type equality22 ((<=) (and (type<=? (cadr e) (caddr e))23 (match-types (caddr e) (cadr e))))24 ;; subtype25 ((<) (and (or (type<=? (cadr e) (caddr e))26 (add-fail-info "<= returned #f"))27 (or (match-types (caddr e) (cadr e))28 (add-fail-info ">= returned #f"))29 (or (not (type<=? (caddr e) (cadr e)))30 (add-fail-info "not >= returned #f"))))31 ;; type equality32 ((=) (and (or (type<=? (cadr e) (caddr e))33 (add-fail-info "<= failed"))34 (or (type<=? (caddr e) (cadr e))35 (add-fail-info ">= failed"))))36 ;; fuzzy match (both directions)37 ((?) (and (match-types (cadr e) (caddr e))38 (match-types (caddr e) (cadr e))))39 ;; fuzzy non-match (both directions)40 ((!) (and (or (not (match-types (cadr e) (caddr e)))41 (add-fail-info ">= was true"))42 (or (not (match-types (caddr e) (cadr e)))43 (add-fail-info "<= was true"))))44 ;; strict non-match (both directions)45 ((><) (and (not (type<=? (cadr e) (caddr e)))46 (not (type<=? (caddr e) (cadr e)))))47 ;; A refined with B gives C48 ((~>) (let ((t (refine-types (cadr e) (caddr e))))49 (or (equal? t (cadddr e))50 (add-fail-info51 (format "Refined to `~a', but expected `~a'" t (cadddr e)) )))))))52 (printf "[~a] ~a~n" (if pass " OK " "FAIL") (cadr expr))53 (unless pass54 (for-each print extra-fail-info))55 (when (not pass) (set! success #f))56 (rename '(void)))))5758;;; wildcards5960(test (= * *))61(test (< x *))6263;;; structs6465(test (= (struct x) (struct x)))66(test (! (struct x) (struct y)))6768;;; undefined6970(test (= undefined undefined))71(test (< undefined *))7273;;; noreturn7475(test (= noreturn noreturn))76(test (< noreturn *))77(test (! undefined noreturn))7879;;; booleans8081(test (= boolean boolean))82(test (< true boolean))83(test (< false boolean))84(test (= (or true false) boolean))8586;;; numbers8788(test (= number number))89(test (< fixnum number))90(test (< float number))91(test (< bignum number))92(test (< ratnum number))93(test (< cplxnum number))94(test (< integer number))95(test (= (or fixnum float bignum ratnum cplxnum) number))9697(test (= integer integer))98(test (< fixnum integer))99(test (< bignum integer))100(test (not (<= float integer)))101(test (not (<= ratnum integer)))102(test (not (<= cplxnum integer)))103(test (= (or fixnum bignum) integer))104105;;; vectors106107(test (= vector vector))108(test (= vector (vector-of *)))109(test (< (vector-of x) (vector-of *)))110111(test (= (vector *) (vector *)))112(test (= (vector x) (vector x)))113(test (< (vector x) (vector *)))114(test (< (vector *) (vector-of *)))115(test (< (vector x) (vector-of *)))116(test (< (vector x) (vector-of x)))117118(test (? (vector *) (vector-of x)))119(test (>< (vector *) (vector-of x)))120121(test (>< (vector *) (vector * *)))122(test (>< (vector x) (vector * *)))123(test (>< (vector *) (vector x x)))124(test (>< (vector x) (vector x x)))125126;;; pairs127128(test (= pair pair))129(test (= pair (pair * *)))130(test (< (pair x *) pair))131(test (< (pair * x) pair))132(test (< (pair x x) pair))133134;;; lists135136(test (= null null))137(test (? null list))138(test (? null (list-of x)))139(test (! null (list x)))140(test (! null pair))141142(test (= list list))143(test (= list (list-of *)))144(test (< (list-of x) (list-of *)))145146(test (= (list *) (list *)))147(test (= (list x) (list x)))148(test (< (list x) (list *)))149(test (< (list *) (list-of *)))150(test (< (list x) (list-of *)))151(test (< (list x) (list-of x)))152153(test (? (list *) (list-of x)))154(test (>< (list *) (list-of x)))155156(test (>< (list *) (list * *)))157(test (>< (list x) (list * *)))158(test (>< (list *) (list x x)))159(test (>< (list x) (list x x)))160161(test (? (pair * *) (list-of *)))162(test (? (pair x *) (list-of *)))163(test (! (pair * x) (list-of *)))164(test (! (pair x x) (list-of *)))165(test (? (pair * *) (list-of x)))166(test (? (pair x *) (list-of x)))167(test (! (pair * x) (list-of x)))168(test (! (pair x x) (list-of x)))169170;;; ports171172(test (= port port))173(test (= (refine (input) port) (refine (input) port)))174(test (= (refine (input output) port) (refine (input output) port)))175(test (= (refine (output) port) (refine (output) port)))176177(test (< (refine (input) port) port))178(test (< (refine (input output) port) port))179(test (< (refine (output) port) port))180(test (< (refine (input output) port) (refine (input) port)))181(test (< (refine (input output) port) (refine (output) port)))182(test (? (refine (input) port) (refine (output) port)))183184;;; unions185186(test (< x (or x y)))187(test (< y (or x y)))188189(test (= (or x number) (or x number)))190(test (< (or x number) (or x number string)))191(test (>< (or x number) (or y string)))192193;;; negative types194195(test (< (not x) *))196(test (! (not x) x))197198(test (< x (not y)))199(test (< x (not (not x))))200(test (< x (not (not (not y)))))201202(test (< x (or (not x) x)))203(test (< x (or (not x) (not y))))204205(test (! x (not x)))206(test (! x (not (not y))))207(test (! x (not (not (not x)))))208(test (! x (not (or x y))))209(test (! x (or (not x) y)))210(test (! x (not (not (not x)))))211212(test (? (not x) (not y)))213(test (? (not x) (or x y)))214(test (? (not x) (or (not x) x)))215(test (? (not x) (or (not y) x)))216(test (? (not x) (or (not x) (not y))))217(test (>< (not x) (not y)))218(test (>< (not x) (or x y)))219(test (>< (not x) (or (not x) x)))220(test (>< (not x) (or (not y) x)))221(test (>< (not x) (or (not x) (not y))))222223(test (< (or (not x) y) (not x)))224(test (< (not (or x y)) (not x)))225226;;; negative wildcards (a bit weird...)227228(test (< (not *) *))229(test (< (not (not *)) *))230(test (< (not (not (not *))) *))231232(test (! (not *) x))233(test (< (not *) (not x)))234235;;; procedures236237(test (= (procedure ()) (procedure ())))238(test (= (procedure (x)) (procedure (x))))239(test (= (procedure (#!rest x)) (procedure (#!rest x))))240241(test (= (procedure ()) (procedure ())))242(test (= (procedure () x) (procedure () x)))243;; FIXME244;(test (= (procedure () . x) (procedure () . x)))245246(test (>< (procedure (x)) (procedure (y))))247(test (>< (procedure () x) (procedure () y)))248249(test (? (procedure (x)) (procedure (*))))250(test (? (procedure () x) (procedure () *)))251252(test (! (procedure (x)) (procedure ())))253(test (! (procedure (x)) (procedure (x y))))254(test (? (procedure (x)) (procedure (x #!rest y))))255256(test (! (procedure () x) (procedure ())))257(test (! (procedure () x) (procedure () x y)))258;; s.a.259;(test (? (procedure () x) (procedure () x . y)))260261;;; refinements262263(test (= (refine (a) x) (refine (a) x)))264(test (< (refine (a b) x) (refine (a) x)))265(test (= (refine (a b) x) (refine (a b) x)))266267(test (? (refine (a) x) (refine (b) x)))268(test (>< (refine (a) x) (refine (b) x)))269270(test (~> x y y))271(test (~> x (or x y) x))272(test (~> (or x y) x x))273(test (~> (or x y) (or y z) y))274275(test (~> * (refine (a) x) (refine (a) x)))276(test (~> (refine (a) *) x (refine (a) x)))277(test (~> x (refine (a) *) (refine (a) x)))278(test (~> (refine (a) x) * (refine (a) x)))279(test (~> (refine (a) x) (refine (b) *) (refine (a b) x)))280(test (~> (refine (a) x) (refine (b) *) (refine (a b) x)))281282(test (~> (refine (a) x) y y))283(test (~> x (refine (a) y) (refine (a) y)))284(test (~> (refine (a) x) (refine (b) y) (refine (b) y)))285286(test (~> (list fixnum number)287 (list number fixnum)288 (list fixnum fixnum)))289(test (~> (vector x)290 (vector (refine (a) x))291 (vector (refine (a) x))))292(test (~> (list x)293 (list (refine (a) x))294 (list (refine (a) x))))295(test (~> (list x (list x))296 (list (refine (a) *) (list (refine (b) *)))297 (list (refine (a) x) (list (refine (b) x)))))298(test (~> (list * (list *))299 (list (refine (a) x) (list (refine (b) x)))300 (list (refine (a) x) (list (refine (b) x)))))301(test (~> (list (refine (a) x))302 (refine (a) (list (refine (b) x)))303 (refine (a) (list (refine (a b) x)))))304(test (~> (list (refine (a) x))305 (refine (a) (list (refine (b) y)))306 (refine (a) (list (refine (b) y)))))307(test (~> (or pair null) list list))308309(begin-for-syntax310 (when (not success) (exit 1)))