1 ;;;; srfi-34.test --- test suite for SRFI-34 -*- scheme -*-
3 ;;;; Copyright (C) 2003 Free Software Foundation, Inc.
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
10 ;;;; This program is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 ;;;; Boston, MA 02111-1307 USA
20 (define-module (test-suite test-srfi-34)
21 :use-module (test-suite lib)
22 :use-module (srfi srfi-13)
23 :use-module (srfi srfi-34))
25 (define (expr-prints-and-evals-to? expr printout result)
26 (let ((actual-result *unspecified*))
27 (let ((actual-printout
29 (with-output-to-string
32 (eval expr (current-module))))))))
33 ;;(write (list actual-printout printout actual-result result))
35 (and (equal? actual-printout printout)
36 (equal? actual-result result)))))
38 (with-test-prefix "SRFI 34"
41 (expr-prints-and-evals-to?
42 '(call-with-current-continuation
44 (with-exception-handler (lambda (x)
45 (display "condition: ")
50 (+ 1 (raise 'an-error))))))
54 ;; SRFI 34 specifies that the behaviour of the call/cc expression
55 ;; after printing "something went wrong" is unspecified, which is
56 ;; tricky to test for in a positive way ... Guile behaviour at time
57 ;; of writing is to signal a "lazy-catch handler did return" error,
58 ;; which feels about right to me.
60 (expr-prints-and-evals-to?
62 (call-with-current-continuation
64 (with-exception-handler (lambda (x)
65 (display "something went wrong")
69 (+ 1 (raise 'an-error)))))))
70 "something went wrong"
74 (expr-prints-and-evals-to?
77 (display "condition: ")
81 (+ 1 (raise 'an-error)))
86 (expr-prints-and-evals-to?
89 (display "something went wrong")
92 (+ 1 (raise 'an-error)))
93 "something went wrong"
97 (expr-prints-and-evals-to?
98 '(call-with-current-continuation
100 (with-exception-handler (lambda (x)
101 (display "reraised ") (write x) (newline)
105 ((positive? condition) 'positive)
106 ((negative? condition) 'negative))
112 (expr-prints-and-evals-to?
113 '(call-with-current-continuation
115 (with-exception-handler (lambda (x)
116 (display "reraised ") (write x) (newline)
120 ((positive? condition) 'positive)
121 ((negative? condition) 'negative))
127 (expr-prints-and-evals-to?
128 '(call-with-current-continuation
130 (with-exception-handler (lambda (x)
131 (display "reraised ") (write x) (newline)
135 ((positive? condition) 'positive)
136 ((negative? condition) 'negative))
142 (expr-prints-and-evals-to?
144 ((assq 'a condition) => cdr)
145 ((assq 'b condition)))
146 (raise (list (cons 'a 42))))
151 (expr-prints-and-evals-to?
153 ((assq 'a condition) => cdr)
154 ((assq 'b condition)))
155 (raise (list (cons 'b 23))))