diff --git a/collects/tests/mzscheme/basic.ss b/collects/tests/mzscheme/basic.ss index b9a180f304..b71c80a31b 100644 --- a/collects/tests/mzscheme/basic.ss +++ b/collects/tests/mzscheme/basic.ss @@ -1,6 +1,16 @@ (load-relative "loadtest.ss") +(test "bbb" regexp-replace* "a" "aaa" "b") + +(define (test-weird-offset regexp-match regexp-match-positions) + (test #f regexp-match "e" (open-input-string "")) + (test #f regexp-match "e" (open-input-string "") (expt 2 100)) + (test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101)) + (test '((3 . 4)) regexp-match-positions "e" (open-input-string "eaae") 2 (expt 2 101))) +(test-weird-offset regexp-match regexp-match-positions) + + (test '() 'null null) (test '() 'null ()) @@ -1726,8 +1736,8 @@ procedure-arity (case-lambda [(x) 0] [(x y z) 1] [(x y z w u . rest) 2])) (test (make-arity-at-least 0) procedure-arity (lambda x 1)) (test (list 0 (make-arity-at-least 0)) procedure-arity (case-lambda - [() 10] - [x 1])) + [() 10] + [x 1])) (test (make-arity-at-least 0) procedure-arity (lambda x x)) (arity-test procedure-arity 1 1) diff --git a/collects/tests/mzscheme/contmark.ss b/collects/tests/mzscheme/contmark.ss index b73c4b12ae..c0037c6739 100644 --- a/collects/tests/mzscheme/contmark.ss +++ b/collects/tests/mzscheme/contmark.ss @@ -19,132 +19,166 @@ (syntax-test #'(with-continuation-mark 1 2 3 4)) (syntax-test #'(with-continuation-mark 1 2 3 . 4)) -(test '(10) 'wcm (with-continuation-mark 'key 10 - (extract-current-continuation-marks 'key))) -(test '(#(10 #f)) 'wcm (with-continuation-mark 'key 10 - (continuation-mark-set->list* (current-continuation-marks) '(key no-key)))) -(test '(#(#f 10)) 'wcm (with-continuation-mark 'key 10 - (continuation-mark-set->list* (current-continuation-marks) '(no-key key)))) -(test '(#(nope 10)) 'wcm (with-continuation-mark 'key 10 - (continuation-mark-set->list* (current-continuation-marks) '(no-key key) 'nope))) +(define (wcm f) (f)) -(test '(#(10 12)) 'wcm (with-continuation-mark 'key1 10 - (with-continuation-mark 'key2 12 - (continuation-mark-set->list* (current-continuation-marks) '(key1 key2))))) -(test '(#(#f 12) #(10 #f)) 'wcm - (with-continuation-mark 'key1 10 - (let ([x (with-continuation-mark 'key2 12 - (continuation-mark-set->list* (current-continuation-marks) '(key1 key2)))]) - (if (void? x) - x - x)))) +;; Test with an without wrapping `lambda', mainly to +;; test JIT interactions. +(define-syntax wcm-test + (syntax-rules (lambda) + [(_ expect orig) + (begin + (test expect wcm orig) + (test expect 'wcm (orig)))])) + -(test '(11) 'wcm (with-continuation-mark 'key 10 - (with-continuation-mark 'key 11 - (extract-current-continuation-marks 'key)))) -(test '(9) 'wcm (with-continuation-mark 'key 10 - (with-continuation-mark 'key2 9 - (with-continuation-mark 'key 11 - (extract-current-continuation-marks 'key2))))) -(test '() 'wcm (with-continuation-mark 'key 10 - (with-continuation-mark 'key2 9 - (with-continuation-mark 'key 11 - (extract-current-continuation-marks 'key3))))) +(wcm-test '(10) (lambda () + (with-continuation-mark 'key 10 + (extract-current-continuation-marks 'key)))) +(wcm-test '(#(10 #f)) (lambda () + (with-continuation-mark 'key 10 + (continuation-mark-set->list* (current-continuation-marks) '(key no-key))))) +(wcm-test '(#(#f 10)) (lambda () + (with-continuation-mark 'key 10 + (continuation-mark-set->list* (current-continuation-marks) '(no-key key))))) +(wcm-test '(#(nope 10)) (lambda () + (with-continuation-mark 'key 10 + (continuation-mark-set->list* (current-continuation-marks) '(no-key key) 'nope)))) -(test '() 'wcm (let ([x (with-continuation-mark 'key 10 (list 100))]) - (extract-current-continuation-marks 'key))) +(wcm-test '(#(10 12)) (lambda () + (with-continuation-mark 'key1 10 + (with-continuation-mark 'key2 12 + (continuation-mark-set->list* (current-continuation-marks) '(key1 key2)))))) +(wcm-test '(#(#f 12) #(10 #f)) + (lambda () + (with-continuation-mark 'key1 10 + (let ([x (with-continuation-mark 'key2 12 + (continuation-mark-set->list* (current-continuation-marks) '(key1 key2)))]) + (if (void? x) + x + x))))) -(test '(11) 'wcm (with-continuation-mark 'key 11 - (let ([x (with-continuation-mark 'key 10 (extract-current-continuation-marks 'key))]) - (extract-current-continuation-marks 'key)))) +(wcm-test '(11) (lambda () + (with-continuation-mark 'key 10 + (with-continuation-mark 'key 11 + (extract-current-continuation-marks 'key))))) +(wcm-test '(9) (lambda () (with-continuation-mark 'key 10 + (with-continuation-mark 'key2 9 + (with-continuation-mark 'key 11 + (extract-current-continuation-marks 'key2)))))) +(wcm-test '() (lambda () (with-continuation-mark 'key 10 + (with-continuation-mark 'key2 9 + (with-continuation-mark 'key 11 + (extract-current-continuation-marks 'key3)))))) -(test '((11) (10 11) (11)) 'wcm (with-continuation-mark 'key 11 - (list (extract-current-continuation-marks 'key) - (with-continuation-mark 'key 10 (extract-current-continuation-marks 'key)) - (extract-current-continuation-marks 'key)))) +(wcm-test '() (lambda () + (let ([x (with-continuation-mark 'key 10 (list 100))]) + (extract-current-continuation-marks 'key)))) -(test '(11) 'wcm-invoke/tail (with-continuation-mark 'x 10 - (invoke-unit - (unit - (import) - (export) - - (with-continuation-mark 'x 11 - (continuation-mark-set->list - (current-continuation-marks) - 'x)))))) +(wcm-test '(11) (lambda () + (with-continuation-mark 'key 11 + (let ([x (with-continuation-mark 'key 10 (extract-current-continuation-marks 'key))]) + (extract-current-continuation-marks 'key))))) -(test '(11 10) 'wcm-invoke/nontail (with-continuation-mark 'x 10 - (invoke-unit - (unit - (import) - (export) - - (define l (with-continuation-mark 'x 11 - (continuation-mark-set->list - (current-continuation-marks) - 'x))) - l)))) +(wcm-test '((11) (10 11) (11)) (lambda () + (with-continuation-mark 'key 11 + (list (extract-current-continuation-marks 'key) + (with-continuation-mark 'key 10 (extract-current-continuation-marks 'key)) + (extract-current-continuation-marks 'key))))) -(test '(11 10) 'wcm-begin0 (with-continuation-mark 'x 10 - (begin0 - (with-continuation-mark 'x 11 - (extract-current-continuation-marks 'x)) - (+ 2 3)))) -(test '(11 10) 'wcm-begin0/const (with-continuation-mark 'x 10 - (begin0 - (with-continuation-mark 'x 11 - (extract-current-continuation-marks 'x)) - 'constant))) +(wcm-test '(11) + (lambda () + (with-continuation-mark 'x 10 + (invoke-unit + (unit + (import) + (export) + + (with-continuation-mark 'x 11 + (continuation-mark-set->list + (current-continuation-marks) + 'x))))))) + +(wcm-test '(11 10) + (lambda () + (with-continuation-mark 'x 10 + (invoke-unit + (unit + (import) + (export) + + (define l (with-continuation-mark 'x 11 + (continuation-mark-set->list + (current-continuation-marks) + 'x))) + l))))) + +(wcm-test '(11 10) + (lambda () + (with-continuation-mark 'x 10 + (begin0 + (with-continuation-mark 'x 11 + (extract-current-continuation-marks 'x)) + (+ 2 3))))) +(wcm-test '(11 10) + (lambda () + (with-continuation-mark 'x 10 + (begin0 + (with-continuation-mark 'x 11 + (extract-current-continuation-marks 'x)) + 'constant)))) ;; full continuation, same thread -(test '(11 10) 'wcm-begin0 - (let ([k (with-continuation-mark 'x 10 - (begin0 - (with-continuation-mark 'x 11 - (let/cc k k)) - (+ 2 3)))]) - (continuation-mark-set->list - (continuation-marks k) - 'x))) +(wcm-test '(11 10) + (lambda () + (let ([k (with-continuation-mark 'x 10 + (begin0 + (with-continuation-mark 'x 11 + (let/cc k k)) + (+ 2 3)))]) + (continuation-mark-set->list + (continuation-marks k) + 'x)))) ;; full continuation, another thread -(test '(11 10) 'wcm-begin0 - (let ([k (with-continuation-mark 'x 10 - (begin0 - (with-continuation-mark 'x 11 - (let/cc k k)) - (+ 2 3)))]) - (continuation-mark-set->list - (let ([v #f]) - (thread-wait (thread (lambda () - (set! v (continuation-marks k))))) - v) - 'x))) +(wcm-test '(11 10) + (lambda () + (let ([k (with-continuation-mark 'x 10 + (begin0 + (with-continuation-mark 'x 11 + (let/cc k k)) + (+ 2 3)))]) + (continuation-mark-set->list + (let ([v #f]) + (thread-wait (thread (lambda () + (set! v (continuation-marks k))))) + v) + 'x)))) ;; escape continuation, same thread -(test '(11 10) 'wcm-begin0 - (let ([m (with-continuation-mark 'x 10 - (begin0 - (with-continuation-mark 'x 11 - (let/ec k - (begin0 - (with-continuation-mark 'x 12 - (continuation-marks k)) - (+ 17 7)))) - (+ 2 3)))]) - (continuation-mark-set->list m 'x))) +(wcm-test '(11 10) + (lambda () + (let ([m (with-continuation-mark 'x 10 + (begin0 + (with-continuation-mark 'x 11 + (let/ec k + (begin0 + (with-continuation-mark 'x 12 + (continuation-marks k)) + (+ 17 7)))) + (+ 2 3)))]) + (continuation-mark-set->list m 'x)))) ;; escape continuation, another thread => not allowed -(test #f 'wcm-begin0 - (with-continuation-mark 'x 10 - (let/ec k - (with-continuation-mark 'x 12 - (let ([v #f]) - (thread-wait - (thread (lambda () - (set! v (continuation-marks k))))) - v))))) +(wcm-test #f + (lambda () + (with-continuation-mark 'x 10 + (let/ec k + (with-continuation-mark 'x 12 + (let ([v #f]) + (thread-wait + (thread (lambda () + (set! v (continuation-marks k))))) + v)))))) ;; escape continuation, dead (err/rt-test (continuation-marks (let/ec k k)) exn:application:mismatch?) diff --git a/collects/tests/mzscheme/optimize.ss b/collects/tests/mzscheme/optimize.ss index 09f92e0fe4..95b847097f 100644 --- a/collects/tests/mzscheme/optimize.ss +++ b/collects/tests/mzscheme/optimize.ss @@ -9,16 +9,29 @@ (define maybe-different-depths? #f) (define (comp=? c1 c2) - (let ([s1 (open-output-string)] - [s2 (open-output-string)]) + (let ([s1 (open-output-bytes)] + [s2 (open-output-bytes)]) (write c1 s1) (write c2 s2) - (let ([t1 (get-output-string s1)] - [t2 (get-output-string s2)]) - (or (string=? t1 t2) + (let ([t1 (get-output-bytes s1)] + [t2 (get-output-bytes s2)] + [skip-byte (+ 2 ; #~ + 1 ; version length + (string-length (version)) + 1 ; symtab count + 1 ; length + 1 ; CPT_MARSHALLED for top + 1)]) + (or (bytes=? t1 t2) (and maybe-different-depths? - (string=? (substring t1 5 (string-length t1)) - (substring t2 5 (string-length t2)))))))) + (bytes=? (subbytes t1 0 (sub1 skip-byte)) + (subbytes t2 0 (sub1 skip-byte))) + (bytes=? (subbytes t1 skip-byte) + (subbytes t2 skip-byte))) + (begin + (printf "~s\n~s\n" t1 t2) + #f + ))))) (define test-comp (case-lambda @@ -101,6 +114,10 @@ '(expt 5 (* 5 6))) (test-comp 88 '(if (pair? null) 89 88)) +(test-comp '(if _x_ 2 1) + '(if (not _x_) 1 2)) +(test-comp '(if _x_ 2 1) + '(if (not (not (not _x_))) 1 2)) (test-comp '(let ([x 3]) x) '((lambda (x) x) 3)) diff --git a/collects/tests/mzscheme/syntax.ss b/collects/tests/mzscheme/syntax.ss index 89adbc3b7e..ee05b947a4 100644 --- a/collects/tests/mzscheme/syntax.ss +++ b/collects/tests/mzscheme/syntax.ss @@ -16,9 +16,10 @@ (positive? (lambda (x) 'positive))) (raise 1))) (test 5 'with-handlers - (with-handlers ([void (lambda (x) 5)]) - (with-handlers ((zero? (lambda (x) 'zero))) - (/ 0)))) + (with-handlers ([void (lambda (x) 5)]) + (with-handlers ((zero? (lambda (x) 'zero))) + (/ 0)))) + (error-test #'(with-handlers () (/ 0)) exn:fail:contract:divide-by-zero?) @@ -29,6 +30,7 @@ (boolean? (lambda (x) 'boolean))) (/ 0)) exn:application:type?) + (syntax-test #'with-handlers) (syntax-test #'(with-handlers)) (syntax-test #'(with-handlers . 1)) @@ -59,7 +61,7 @@ arity?) (test-values '(1 2) (lambda () (with-handlers ([void void]) - (values 1 2)))) + (values 1 2)))) (SECTION 4 1 2) (test '(quote a) 'quote (quote 'a)) diff --git a/collects/tests/mzscheme/testing.ss b/collects/tests/mzscheme/testing.ss index 3f94686f15..6eaab59005 100644 --- a/collects/tests/mzscheme/testing.ss +++ b/collects/tests/mzscheme/testing.ss @@ -117,6 +117,7 @@ transcript. (set! number-of-error-tests (add1 number-of-error-tests)) (write expr) (display " =e=> ") + (flush-output) (call/ec (lambda (escape) (let* ([old-esc-handler (error-escape-handler)] [old-handler (current-exception-handler)]