Minor fixes to `tests/lazy'.

* Make each test file runnable using `module+'.

* Make the space tests not print anything (unless they fail, of course).

* Make the `first-class?' case even "more first class" by defining their
  and/or as functions.  (Doesn't make a real difference for this test,
  but nice to test more of the language.)
This commit is contained in:
Eli Barzilay 2012-05-06 05:34:37 -04:00
parent 4adc10b071
commit 3cb4552e32
5 changed files with 21 additions and 20 deletions

View File

@ -45,6 +45,7 @@
=> "#0=#s(foo 1 #0#)")))
(provide forcer-tests)
(module+ main (forcer-tests))
(define (forcer-tests)
(test do (test-lazy/force)
do (test-!list)

View File

@ -161,9 +161,7 @@
(!! (list-ref h 10000)) => 288555831593533440
(!! (take 10 FACT)) => '(1 1 2 6 24 120 720 5040 40320 362880)
(!! (take 10 (entrelacer NAT PAIR))) => '(0 0 1 2 2 4 3 6 4 8)
(!! (take 10 F)) => '(0 0 1 0 2 1 3 0 4 2)
)
)
(!! (take 10 F)) => '(0 0 1 0 2 1 3 0 4 2)))
(define (strictness-tests)
(test
@ -202,8 +200,9 @@
(! (andmap (/ 1 0) '(1))) =error> "/: division by zero"
(! (andmap 1 (/ 1 0))) =error> "/: division by zero"
))
(provide lang-tests)
(module+ main (lang-tests))
(define (lang-tests)
(! (begin (basic-tests)
(list-tests)

View File

@ -6,4 +6,3 @@
do (forcer-tests)
do (lang-tests)
do (space-tests))

View File

@ -183,6 +183,7 @@
(format "~a" p) => "#<promise!99>")))
(provide promise-tests)
(module+ main (promise-tests))
(define (promise-tests)
(test do (test-syntax)
do (test-types)

View File

@ -3,14 +3,15 @@
(require tests/eli-tester)
;; tests for space safety, especially for `or' and `and'
(provide space-tests)
(module+ main (space-tests))
(define (space-tests)
(define (one-test first-class?)
(collect-garbage)
(define mem (current-memory-use))
(define t
(thread
(lambda ()
(thread
(lambda ()
(parameterize ([current-namespace (make-base-namespace)])
(eval
`(module loop lazy
@ -20,8 +21,8 @@
empty
(cons n (list-from (add1 n)))))
,@(if first-class?
`((define my-or or)
(define my-and and))
`((define (my-or x y) (or x y))
(define (my-and x y) (and x y)))
'())
(define (has-negative? l)
(,(if first-class? 'my-and 'and)
@ -30,17 +31,17 @@
(negative? (car l))
(has-negative? (rest l)))))
(! (has-negative? (list-from 0))))))
(eval `(require 'loop))))))
(thread (lambda () (let loop ()
(sleep 0.2)
(unless ((current-memory-use) . < . (* 10 mem))
(eprintf "too much memory!")
(kill-thread t))
(when (thread-running? t)
(loop)))))
(parameterize ([current-output-port (open-output-bytes)])
(eval `(require 'loop)))))))
(thread (lambda ()
(let loop ()
(sleep 0.2)
(unless ((current-memory-use) . < . (* 10 mem))
(eprintf "too much memory!")
(kill-thread t))
(when (thread-running? t)
(loop)))))
(sync t)
(void))
(one-test #f)
(one-test #t))
(provide space-tests)