Debian Codegraph @

test-suite/tests/srfi-64-test.scm

raw
1 ;;;
2 ;;; This is a test suite written in the notation of
3 ;;; SRFI-64, A Scheme API for test suites
4 ;;;
5
6 (test-begin "SRFI 64 - Meta-Test Suite")
7
8 ;;;
9 ;;; Ironically, in order to set up the meta-test environment,
10 ;;; we have to invoke one of the most sophisticated features:
11 ;;; custom test runners
12 ;;;
13
14 ;;; The `prop-runner' invokes `thunk' in the context of a new
15 ;;; test runner, and returns the indicated properties of the
16 ;;; last-executed test result.
17
18 (define (prop-runner props thunk)
19 (let ((r (test-runner-null))
20 (plist '()))
21 ;;
22 (test-runner-on-test-end!
23 r
24 (lambda (runner)
25 (set! plist (test-result-alist runner))))
26 ;;
27 (test-with-runner r (thunk))
28 ;; reorder the properties so they are in the order
29 ;; given by `props'. Note that any property listed in `props'
30 ;; that is not in the property alist will occur as #f
31 (map (lambda (k)
32 (assq k plist))
33 props)))
34
35 ;;; `on-test-runner' creates a null test runner and then
36 ;;; arranged for `visit' to be called with the runner
37 ;;; whenever a test is run. The results of the calls to
38 ;;; `visit' are returned in a list
39
40 (define (on-test-runner thunk visit)
41 (let ((r (test-runner-null))
42 (results '()))
43 ;;
44 (test-runner-on-test-end!
45 r
46 (lambda (runner)
47 (set! results (cons (visit r) results))))
48 ;;
49 (test-with-runner r (thunk))
50 (reverse results)))
51
52 ;;;
53 ;;; The `triv-runner' invokes `thunk'
54 ;;; and returns a list of 6 lists, the first 5 of which
55 ;;; are a list of the names of the tests that, respectively,
56 ;;; PASS, FAIL, XFAIL, XPASS, and SKIP.
57 ;;; The last item is a list of counts.
58 ;;;
59
60 (define (triv-runner thunk)
61 (let ((r (test-runner-null))
62 (accum-pass '())
63 (accum-fail '())
64 (accum-xfail '())
65 (accum-xpass '())
66 (accum-skip '()))
67 ;;
68 (test-runner-on-bad-count!
69 r
70 (lambda (runner count expected-count)
71 (error (string-append "bad count " (number->string count)
72 " but expected "
73 (number->string expected-count)))))
74 (test-runner-on-bad-end-name!
75 r
76 (lambda (runner begin end)
77 (error (string-append "bad end group name " end
78 " but expected " begin))))
79 (test-runner-on-test-end!
80 r
81 (lambda (runner)
82 (let ((n (test-runner-test-name runner)))
83 (case (test-result-kind runner)
84 ((pass) (set! accum-pass (cons n accum-pass)))
85 ((fail) (set! accum-fail (cons n accum-fail)))
86 ((xpass) (set! accum-xpass (cons n accum-xpass)))
87 ((xfail) (set! accum-xfail (cons n accum-xfail)))
88 ((skip) (set! accum-skip (cons n accum-skip)))))))
89 ;;
90 (test-with-runner r (thunk))
91 (list (reverse accum-pass) ; passed as expected
92 (reverse accum-fail) ; failed, but was expected to pass
93 (reverse accum-xfail) ; failed as expected
94 (reverse accum-xpass) ; passed, but was expected to fail
95 (reverse accum-skip) ; was not executed
96 (list (test-runner-pass-count r)
97 (test-runner-fail-count r)
98 (test-runner-xfail-count r)
99 (test-runner-xpass-count r)
100 (test-runner-skip-count r)))))
101
102 (define (path-revealing-runner thunk)
103 (let ((r (test-runner-null))
104 (seq '()))
105 ;;
106 (test-runner-on-test-end!
107 r
108 (lambda (runner)
109 (set! seq (cons (list (test-runner-group-path runner)
110 (test-runner-test-name runner))
111 seq))))
112 (test-with-runner r (thunk))
113 (reverse seq)))
114
115 ;;;
116 ;;; Now we can start testing compliance with SRFI-64
117 ;;;
118
119 (test-begin "1. Simple test-cases")
120
121 (test-begin "1.1. test-assert")
122
123 (define (t)
124 (triv-runner
125 (lambda ()
126 (test-assert "a" #t)
127 (test-assert "b" #f))))
128
129 (test-equal
130 "1.1.1. Very simple"
131 '(("a") ("b") () () () (1 1 0 0 0))
132 (t))
133
134 (test-equal
135 "1.1.2. A test with no name"
136 '(("a") ("") () () () (1 1 0 0 0))
137 (triv-runner (lambda () (test-assert "a" #t) (test-assert #f))))
138
139 (test-equal
140 "1.1.3. Tests can have the same name"
141 '(("a" "a") () () () () (2 0 0 0 0))
142 (triv-runner (lambda () (test-assert "a" #t) (test-assert "a" #t))))
143
144 (define (choke)
145 (vector-ref '#(1 2) 3))
146
147 (test-equal
148 "1.1.4. One way to FAIL is to throw an error"
149 '(() ("a") () () () (0 1 0 0 0))
150 (triv-runner (lambda () (test-assert "a" (choke)))))
151
152 (test-end);1.1
153
154 (test-begin "1.2. test-eqv")
155
156 (define (mean x y)
157 (/ (+ x y) 2.0))
158
159 (test-equal
160 "1.2.1. Simple numerical equivalence"
161 '(("c") ("a" "b") () () () (1 2 0 0 0))
162 (triv-runner
163 (lambda ()
164 (test-eqv "a" (mean 3 5) 4)
165 (test-eqv "b" (mean 3 5) 4.5)
166 (test-eqv "c" (mean 3 5) 4.0))))
167
168 (test-end);1.2
169
170 (test-end "1. Simple test-cases")
171
172 ;;;
173 ;;;
174 ;;;
175
176 (test-begin "2. Tests for catching errors")
177
178 (test-begin "2.1. test-error")
179
180 (test-equal
181 "2.1.1. Baseline test; PASS with no optional args"
182 '(("") () () () () (1 0 0 0 0))
183 (triv-runner
184 (lambda ()
185 ;; PASS
186 (test-error (vector-ref '#(1 2) 9)))))
187
188 (test-equal
189 "2.1.2. Baseline test; FAIL with no optional args"
190 '(() ("") () () () (0 1 0 0 0))
191 (triv-runner
192 (lambda ()
193 ;; FAIL: the expr does not raise an error and `test-error' is
194 ;; claiming that it will, so this test should FAIL
195 (test-error (vector-ref '#(1 2) 0)))))
196
197 (test-equal
198 "2.1.3. PASS with a test name and error type"
199 '(("a") () () () () (1 0 0 0 0))
200 (triv-runner
201 (lambda ()
202 ;; PASS
203 (test-error "a" #t (vector-ref '#(1 2) 9)))))
204
205 (test-end "2.1. test-error")
206
207 (test-end "2. Tests for catching errors")
208
209 ;;;
210 ;;;
211 ;;;
212
213 (test-begin "3. Test groups and paths")
214
215 (test-equal
216 "3.1. test-begin with unspecific test-end"
217 '(("b") () () () () (1 0 0 0 0))
218 (triv-runner
219 (lambda ()
220 (test-begin "a")
221 (test-assert "b" #t)
222 (test-end))))
223
224 (test-equal
225 "3.2. test-begin with name-matching test-end"
226 '(("b") () () () () (1 0 0 0 0))
227 (triv-runner
228 (lambda ()
229 (test-begin "a")
230 (test-assert "b" #t)
231 (test-end "a"))))
232
233 ;;; since the error raised by `test-end' on a mismatch is not a test
234 ;;; error, we actually expect the triv-runner itself to fail
235
236 (test-error
237 "3.3. test-begin with mismatched test-end"
238 #t
239 (triv-runner
240 (lambda ()
241 (test-begin "a")
242 (test-assert "b" #t)
243 (test-end "x"))))
244
245 (test-equal
246 "3.4. test-begin with name and count"
247 '(("b" "c") () () () () (2 0 0 0 0))
248 (triv-runner
249 (lambda ()
250 (test-begin "a" 2)
251 (test-assert "b" #t)
252 (test-assert "c" #t)
253 (test-end "a"))))
254
255 ;; similarly here, a mismatched count is a lexical error
256 ;; and not a test failure...
257
258 (test-error
259 "3.5. test-begin with mismatched count"
260 #t
261 (triv-runner
262 (lambda ()
263 (test-begin "a" 99)
264 (test-assert "b" #t)
265 (test-end "a"))))
266
267 (test-equal
268 "3.6. introspecting on the group path"
269 '((() "w")
270 (("a" "b") "x")
271 (("a" "b") "y")
272 (("a") "z"))
273 ;;
274 ;; `path-revealing-runner' is designed to return a list
275 ;; of the tests executed, in order. Each entry is a list
276 ;; (GROUP-PATH TEST-NAME), and each GROUP-PATH is a list
277 ;; of test groups starting from the topmost
278 ;;
279 (path-revealing-runner
280 (lambda ()
281 (test-assert "w" #t)
282 (test-begin "a")
283 (test-begin "b")
284 (test-assert "x" #t)
285 (test-assert "y" #t)
286 (test-end)
287 (test-assert "z" #t))))
288
289
290 (test-end "3. Test groups and paths")
291
292 ;;;
293 ;;;
294 ;;;
295
296 (test-begin "4. Handling set-up and cleanup")
297
298 (test-equal "4.1. Normal exit path"
299 '(in 1 2 out)
300 (let ((ex '()))
301 (define (do s)
302 (set! ex (cons s ex)))
303 ;;
304 (triv-runner
305 (lambda ()
306 (test-group-with-cleanup
307 "foo"
308 (do 'in)
309 (do 1)
310 (do 2)
311 (do 'out))))
312 (reverse ex)))
313
314 (test-equal "4.2. Exception exit path"
315 '(in 1 out)
316 (let ((ex '()))
317 (define (do s)
318 (set! ex (cons s ex)))
319 ;;
320 ;; the outer runner is to run the `test-error' in, to
321 ;; catch the exception raised in the inner runner,
322 ;; since we don't want to depend on any other
323 ;; exception-catching support
324 ;;
325 (triv-runner
326 (lambda ()
327 (test-error
328 (triv-runner
329 (lambda ()
330 (test-group-with-cleanup
331 "foo"
332 (do 'in) (test-assert #t)
333 (do 1) (test-assert #t)
334 (choke) (test-assert #t)
335 (do 2) (test-assert #t)
336 (do 'out)))))))
337 (reverse ex)))
338
339 (test-end "4. Handling set-up and cleanup")
340
341 ;;;
342 ;;;
343 ;;;
344
345 (test-begin "5. Test specifiers")
346
347 (test-begin "5.1. test-match-named")
348
349 (test-equal "5.1.1. match test names"
350 '(("y") () () () ("x") (1 0 0 0 1))
351 (triv-runner
352 (lambda ()
353 (test-skip (test-match-name "x"))
354 (test-assert "x" #t)
355 (test-assert "y" #t))))
356
357 (test-equal "5.1.2. but not group names"
358 '(("z") () () () () (1 0 0 0 0))
359 (triv-runner
360 (lambda ()
361 (test-skip (test-match-name "x"))
362 (test-begin "x")
363 (test-assert "z" #t)
364 (test-end))))
365
366 (test-end)
367
368 (test-begin "5.2. test-match-nth")
369 ;; See also: [6.4. Short-circuit evaluation]
370
371 (test-equal "5.2.1. skip the nth one after"
372 '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
373 (triv-runner
374 (lambda ()
375 (test-assert "v" #t)
376 (test-skip (test-match-nth 2))
377 (test-assert "w" #t) ; 1
378 (test-assert "x" #t) ; 2 SKIP
379 (test-assert "y" #t) ; 3
380 (test-assert "z" #t)))) ; 4
381
382 (test-equal "5.2.2. skip m, starting at n"
383 '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
384 (triv-runner
385 (lambda ()
386 (test-assert "v" #t)
387 (test-skip (test-match-nth 2 2))
388 (test-assert "w" #t) ; 1
389 (test-assert "x" #t) ; 2 SKIP
390 (test-assert "y" #t) ; 3 SKIP
391 (test-assert "z" #t)))) ; 4
392
393 (test-end)
394
395 (test-begin "5.3. test-match-any")
396 (test-equal "5.3.1. basic disjunction"
397 '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
398 (triv-runner
399 (lambda ()
400 (test-assert "v" #t)
401 (test-skip (test-match-any (test-match-nth 3)
402 (test-match-name "x")))
403 (test-assert "w" #t) ; 1
404 (test-assert "x" #t) ; 2 SKIP(NAME)
405 (test-assert "y" #t) ; 3 SKIP(COUNT)
406 (test-assert "z" #t)))) ; 4
407
408 (test-equal "5.3.2. disjunction is commutative"
409 '(("v" "w" "z") () () () ("x" "y") (3 0 0 0 2))
410 (triv-runner
411 (lambda ()
412 (test-assert "v" #t)
413 (test-skip (test-match-any (test-match-name "x")
414 (test-match-nth 3)))
415 (test-assert "w" #t) ; 1
416 (test-assert "x" #t) ; 2 SKIP(NAME)
417 (test-assert "y" #t) ; 3 SKIP(COUNT)
418 (test-assert "z" #t)))) ; 4
419
420 (test-end)
421
422 (test-begin "5.4. test-match-all")
423 (test-equal "5.4.1. basic conjunction"
424 '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
425 (triv-runner
426 (lambda ()
427 (test-assert "v" #t)
428 (test-skip (test-match-all (test-match-nth 2 2)
429 (test-match-name "x")))
430 (test-assert "w" #t) ; 1
431 (test-assert "x" #t) ; 2 SKIP(NAME) & SKIP(COUNT)
432 (test-assert "y" #t) ; 3 SKIP(COUNT)
433 (test-assert "z" #t)))) ; 4
434
435 (test-equal "5.4.2. conjunction is commutative"
436 '(("v" "w" "y" "z") () () () ("x") (4 0 0 0 1))
437 (triv-runner
438 (lambda ()
439 (test-assert "v" #t)
440 (test-skip (test-match-all (test-match-name "x")
441 (test-match-nth 2 2)))
442 (test-assert "w" #t) ; 1
443 (test-assert "x" #t) ; 2 SKIP(NAME) & SKIP(COUNT)
444 (test-assert "y" #t) ; 3 SKIP(COUNT)
445 (test-assert "z" #t)))) ; 4
446
447 (test-end)
448
449 (test-end "5. Test specifiers")
450
451 ;;;
452 ;;;
453 ;;;
454
455 (test-begin "6. Skipping selected tests")
456
457 (test-equal
458 "6.1. Skip by specifier - match-name"
459 '(("x") () () () ("y") (1 0 0 0 1))
460 (triv-runner
461 (lambda ()
462 (test-begin "a")
463 (test-skip (test-match-name "y"))
464 (test-assert "x" #t) ; PASS
465 (test-assert "y" #f) ; SKIP
466 (test-end))))
467
468 (test-equal
469 "6.2. Shorthand specifiers"
470 '(("x") () () () ("y") (1 0 0 0 1))
471 (triv-runner
472 (lambda ()
473 (test-begin "a")
474 (test-skip "y")
475 (test-assert "x" #t) ; PASS
476 (test-assert "y" #f) ; SKIP
477 (test-end))))
478
479 (test-begin "6.3. Specifier Stack")
480
481 (test-equal
482 "6.3.1. Clearing the Specifier Stack"
483 '(("x" "x") ("y") () () ("y") (2 1 0 0 1))
484 (triv-runner
485 (lambda ()
486 (test-begin "a then b")
487 (test-begin "a")
488 (test-skip "y")
489 (test-assert "x" #t) ; PASS
490 (test-assert "y" #f) ; SKIP
491 (test-end)
492 (test-begin "b")
493 (test-assert "x" #t) ; PASS
494 (test-assert "y" #f) ; FAIL
495 (test-end)
496 (test-end))))
497
498 (test-equal
499 "6.3.2. Inheriting the Specifier Stack"
500 '(("x" "x") () () () ("y" "y") (2 0 0 0 2))
501 (triv-runner
502 (lambda ()
503 (test-begin "a then b")
504 (test-skip "y")
505 (test-begin "a")
506 (test-assert "x" #t) ; PASS
507 (test-assert "y" #f) ; SKIP
508 (test-end)
509 (test-begin "b")
510 (test-assert "x" #t) ; PASS
511 (test-assert "y" #f) ; SKIP
512 (test-end)
513 (test-end))))
514
515 (test-end);6.3
516
517 (test-begin "6.4. Short-circuit evaluation")
518
519 (test-equal
520 "6.4.1. In test-match-all"
521 '(("x") ("y" "x" "z") () () ("y") (1 3 0 0 1))
522 (triv-runner
523 (lambda ()
524 (test-begin "a")
525 (test-skip (test-match-all "y" (test-match-nth 2)))
526 ;; let's label the substructure forms so we can
527 ;; see which one `test-match-nth' is going to skip
528 ;; ; # "y" 2 result
529 (test-assert "x" #t) ; 1 - #f #f PASS
530 (test-assert "y" #f) ; 2 - #t #t SKIP
531 (test-assert "y" #f) ; 3 - #t #f FAIL
532 (test-assert "x" #f) ; 4 - #f #f FAIL
533 (test-assert "z" #f) ; 5 - #f #f FAIL
534 (test-end))))
535
536 (test-equal
537 "6.4.2. In separate skip-list entries"
538 '(("x") ("x" "z") () () ("y" "y") (1 2 0 0 2))
539 (triv-runner
540 (lambda ()
541 (test-begin "a")
542 (test-skip "y")
543 (test-skip (test-match-nth 2))
544 ;; let's label the substructure forms so we can
545 ;; see which one `test-match-nth' is going to skip
546 ;; ; # "y" 2 result
547 (test-assert "x" #t) ; 1 - #f #f PASS
548 (test-assert "y" #f) ; 2 - #t #t SKIP
549 (test-assert "y" #f) ; 3 - #t #f SKIP
550 (test-assert "x" #f) ; 4 - #f #f FAIL
551 (test-assert "z" #f) ; 5 - #f #f FAIL
552 (test-end))))
553
554 (test-begin "6.4.3. Skipping test suites")
555
556 (test-equal
557 "6.4.3.1. Introduced using 'test-begin'"
558 '(("x") () () () () (1 0 0 0 0))
559 (triv-runner
560 (lambda ()
561 (test-begin "a")
562 (test-skip "b")
563 (test-begin "b") ; not skipped
564 (test-assert "x" #t)
565 (test-end "b")
566 (test-end "a"))))
567
568 (test-expect-fail 1) ;; ???
569 (test-equal
570 "6.4.3.2. Introduced using 'test-group'"
571 '(() () () () () (0 0 0 0 1))
572 (triv-runner
573 (lambda ()
574 (test-begin "a")
575 (test-skip "b")
576 (test-group
577 "b" ; skipped
578 (test-assert "x" #t))
579 (test-end "a"))))
580
581 (test-equal
582 "6.4.3.3. Non-skipped 'test-group'"
583 '(("x") () () () () (1 0 0 0 0))
584 (triv-runner
585 (lambda ()
586 (test-begin "a")
587 (test-skip "c")
588 (test-group "b" (test-assert "x" #t))
589 (test-end "a"))))
590
591 (test-end) ; 6.4.3
592
593 (test-end);6.4
594
595 (test-end "6. Skipping selected tests")
596
597 ;;;
598 ;;;
599 ;;;
600
601 (test-begin "7. Expected failures")
602
603 (test-equal "7.1. Simple example"
604 '(() ("x") ("z") () () (0 1 1 0 0))
605 (triv-runner
606 (lambda ()
607 (test-assert "x" #f)
608 (test-expect-fail "z")
609 (test-assert "z" #f))))
610
611 (test-equal "7.2. Expected exception"
612 '(() ("x") ("z") () () (0 1 1 0 0))
613 (triv-runner
614 (lambda ()
615 (test-assert "x" #f)
616 (test-expect-fail "z")
617 (test-assert "z" (choke)))))
618
619 (test-equal "7.3. Unexpectedly PASS"
620 '(() () ("y") ("x") () (0 0 1 1 0))
621 (triv-runner
622 (lambda ()
623 (test-expect-fail "x")
624 (test-expect-fail "y")
625 (test-assert "x" #t)
626 (test-assert "y" #f))))
627
628
629
630 (test-end "7. Expected failures")
631
632 ;;;
633 ;;;
634 ;;;
635
636 (test-begin "8. Test-runner")
637
638 ;;;
639 ;;; Because we want this test suite to be accurate even
640 ;;; when the underlying implementation chooses to use, e.g.,
641 ;;; a global variable to implement what could be thread variables
642 ;;; or SRFI-39 parameter objects, we really need to save and restore
643 ;;; their state ourselves
644 ;;;
645 (define (with-factory-saved thunk)
646 (let* ((saved (test-runner-factory))
647 (result (thunk)))
648 (test-runner-factory saved)
649 result))
650
651 (test-begin "8.1. test-runner-current")
652 (test-assert "8.1.1. automatically restored"
653 (let ((a 0)
654 (b 1)
655 (c 2))
656 ;
657 (triv-runner
658 (lambda ()
659 (set! a (test-runner-current))
660 ;;
661 (triv-runner
662 (lambda ()
663 (set! b (test-runner-current))))
664 ;;
665 (set! c (test-runner-current))))
666 ;;
667 (and (eq? a c)
668 (not (eq? a b)))))
669
670 (test-end)
671
672 (test-begin "8.2. test-runner-simple")
673 ;; Procedure equality is explicitly unspecified by R6RS.
674 ;; (test-assert "8.2.1. default on-test hook"
675 ;; (eq? (test-runner-on-test-end (test-runner-simple))
676 ;; test-on-test-end-simple))
677 ;; (test-assert "8.2.2. default on-final hook"
678 ;; (eq? (test-runner-on-final (test-runner-simple))
679 ;; test-on-final-simple))
680 (test-end)
681
682 (test-begin "8.3. test-runner-factory")
683
684 ;; Procedure equality is explicitly unspecified by R6RS.
685 ;; (test-assert "8.3.1. default factory"
686 ;; (eq? (test-runner-factory) test-runner-simple))
687
688 (test-assert "8.3.2. settable factory"
689 (with-factory-saved
690 (lambda ()
691 (test-runner-factory test-runner-null)
692 ;; we have no way, without bringing in other SRFIs,
693 ;; to make sure the following doesn't print anything,
694 ;; but it shouldn't:
695 (test-with-runner
696 (test-runner-create)
697 (lambda ()
698 (test-begin "a")
699 (test-assert #t) ; pass
700 (test-assert #f) ; fail
701 (test-assert (vector-ref '#(3) 10)) ; fail with error
702 (test-end "a")))
703 (eq? (test-runner-factory) test-runner-null))))
704
705 (test-end)
706
707 ;;; This got tested about as well as it could in 8.3.2
708
709 (test-begin "8.4. test-runner-create")
710 (test-end)
711
712 ;;; This got tested about as well as it could in 8.3.2
713
714 (test-begin "8.5. test-runner-factory")
715 (test-end)
716
717 (test-begin "8.6. test-apply")
718 (test-equal "8.6.1. Simple (form 1) test-apply"
719 '(("w" "p" "v") () () () () (3 0 0 0 0))
720 (triv-runner
721 (lambda ()
722 (test-begin "a")
723 (test-assert "w" #t)
724 (test-apply
725 (test-match-name "p")
726 (lambda ()
727 (test-begin "p")
728 (test-assert "x" #t)
729 (test-end)
730 (test-begin "z")
731 (test-assert "p" #t) ; only this one should execute in here
732 (test-end)))
733 (test-assert "v" #t))))
734
735 (test-equal "8.6.2. Simple (form 2) test-apply"
736 '(("w" "p" "v") () () () () (3 0 0 0 0))
737 (triv-runner
738 (lambda ()
739 (test-begin "a")
740 (test-assert "w" #t)
741 (test-apply
742 (test-runner-current)
743 (test-match-name "p")
744 (lambda ()
745 (test-begin "p")
746 (test-assert "x" #t)
747 (test-end)
748 (test-begin "z")
749 (test-assert "p" #t) ; only this one should execute in here
750 (test-end)))
751 (test-assert "v" #t))))
752
753 (test-expect-fail 1) ;; depends on all test-match-nth being called.
754 (test-equal "8.6.3. test-apply with skips"
755 '(("w" "q" "v") () () () ("x" "p" "x") (3 0 0 0 3))
756 (triv-runner
757 (lambda ()
758 (test-begin "a")
759 (test-assert "w" #t)
760 (test-skip (test-match-nth 2))
761 (test-skip (test-match-nth 4))
762 (test-apply
763 (test-runner-current)
764 (test-match-name "p")
765 (test-match-name "q")
766 (lambda ()
767 ; only execute if SKIP=no and APPLY=yes
768 (test-assert "x" #t) ; # 1 SKIP=no APPLY=no
769 (test-assert "p" #t) ; # 2 SKIP=yes APPLY=yes
770 (test-assert "q" #t) ; # 3 SKIP=no APPLY=yes
771 (test-assert "x" #f) ; # 4 SKIP=yes APPLY=no
772 0))
773 (test-assert "v" #t))))
774
775 ;;; Unfortunately, since there is no way to UNBIND the current test runner,
776 ;;; there is no way to test the behavior of `test-apply' in the absence
777 ;;; of a current runner within our little meta-test framework.
778 ;;;
779 ;;; To test the behavior manually, you should be able to invoke:
780 ;;;
781 ;;; (test-apply "a" (lambda () (test-assert "a" #t)))
782 ;;;
783 ;;; from the top level (with SRFI 64 available) and it should create a
784 ;;; new, default (simple) test runner.
785
786 (test-end)
787
788 ;;; This entire suite depends heavily on 'test-with-runner'. If it didn't
789 ;;; work, this suite would probably go down in flames
790 (test-begin "8.7. test-with-runner")
791 (test-end)
792
793 ;;; Again, this suite depends heavily on many of the test-runner
794 ;;; components. We'll just test those that aren't being exercised
795 ;;; by the meta-test framework
796 (test-begin "8.8. test-runner components")
797
798 (define (auxtrack-runner thunk)
799 (let ((r (test-runner-null)))
800 (test-runner-aux-value! r '())
801 (test-runner-on-test-end! r (lambda (r)
802 (test-runner-aux-value!
803 r
804 (cons (test-runner-test-name r)
805 (test-runner-aux-value r)))))
806 (test-with-runner r (thunk))
807 (reverse (test-runner-aux-value r))))
808
809 (test-equal "8.8.1. test-runner-aux-value"
810 '("x" "" "y")
811 (auxtrack-runner
812 (lambda ()
813 (test-assert "x" #t)
814 (test-begin "a")
815 (test-assert #t)
816 (test-assert "y" #f)
817 (test-end))))
818
819 (test-end) ; 8.8
820
821 (test-end "8. Test-runner")
822
823 (test-begin "9. Test Result Properties")
824
825 (test-begin "9.1. test-result-alist")
826
827 (define (symbol-alist? l)
828 (if (null? l)
829 #t
830 (and (pair? l)
831 (pair? (car l))
832 (symbol? (caar l))
833 (symbol-alist? (cdr l)))))
834
835 ;;; check the various syntactic forms
836
837 (test-assert (symbol-alist?
838 (car (on-test-runner
839 (lambda ()
840 (test-assert #t))
841 (lambda (r)
842 (test-result-alist r))))))
843
844 (test-assert (symbol-alist?
845 (car (on-test-runner
846 (lambda ()
847 (test-assert #t))
848 (lambda (r)
849 (test-result-alist r))))))
850
851 ;;; check to make sure the required properties are returned
852
853 (test-equal '((result-kind . pass))
854 (prop-runner
855 '(result-kind)
856 (lambda ()
857 (test-assert #t)))
858 )
859
860 (test-equal
861 '((result-kind . fail)
862 (expected-value . 2)
863 (actual-value . 3))
864 (prop-runner
865 '(result-kind expected-value actual-value)
866 (lambda ()
867 (test-equal 2 (+ 1 2)))))
868
869 (test-end "9.1. test-result-alist")
870
871 (test-begin "9.2. test-result-ref")
872
873 (test-equal '(pass)
874 (on-test-runner
875 (lambda ()
876 (test-assert #t))
877 (lambda (r)
878 (test-result-ref r 'result-kind))))
879
880 (test-equal '(pass)
881 (on-test-runner
882 (lambda ()
883 (test-assert #t))
884 (lambda (r)
885 (test-result-ref r 'result-kind))))
886
887 (test-equal '(fail pass)
888 (on-test-runner
889 (lambda ()
890 (test-assert (= 1 2))
891 (test-assert (= 1 1)))
892 (lambda (r)
893 (test-result-ref r 'result-kind))))
894
895 (test-end "9.2. test-result-ref")
896
897 (test-begin "9.3. test-result-set!")
898
899 (test-equal '(100 100)
900 (on-test-runner
901 (lambda ()
902 (test-assert (= 1 2))
903 (test-assert (= 1 1)))
904 (lambda (r)
905 (test-result-set! r 'foo 100)
906 (test-result-ref r 'foo))))
907
908 (test-end "9.3. test-result-set!")
909
910 (test-end "9. Test Result Properties")
911
912 ;;;
913 ;;;
914 ;;;
915
916 #| Time to stop having fun...
917
918 (test-begin "9. For fun, some meta-test errors")
919
920 (test-equal
921 "9.1. Really PASSes, but test like it should FAIL"
922 '(() ("b") () () ())
923 (triv-runner
924 (lambda ()
925 (test-assert "b" #t))))
926
927 (test-expect-fail "9.2. Expect to FAIL and do so")
928 (test-expect-fail "9.3. Expect to FAIL but PASS")
929 (test-skip "9.4. SKIP this one")
930
931 (test-assert "9.2. Expect to FAIL and do so" #f)
932 (test-assert "9.3. Expect to FAIL but PASS" #t)
933 (test-assert "9.4. SKIP this one" #t)
934
935 (test-end)
936 |#
937
938 (test-end "SRFI 64 - Meta-Test Suite")
939
940 ;;;