1 ;;;; future.test --- Futures. -*- mode: scheme; coding: utf-8; -*-
3 ;;;; Ludovic Courtès <ludo@gnu.org>
5 ;;;; Copyright (C) 2010, 2012, 2013 Free Software Foundation, Inc.
7 ;;;; This library is free software; you can redistribute it and/or
8 ;;;; modify it under the terms of the GNU Lesser General Public
9 ;;;; License as published by the Free Software Foundation; either
10 ;;;; version 3 of the License, or (at your option) any later version.
12 ;;;; This library is distributed in the hope that it will be useful,
13 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;;;; Lesser General Public License for more details.
17 ;;;; You should have received a copy of the GNU Lesser General Public
18 ;;;; License along with this library; if not, write to the Free Software
19 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 (define-module (test-future)
22 #:use-module (test-suite lib)
23 #:use-module (ice-9 futures)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-26))
27 (define specific-exception-key (gensym))
29 (define specific-exception
30 (cons specific-exception-key ".*"))
33 (with-test-prefix "futures"
35 (pass-if "make-future"
36 (future? (make-future (lambda () #f))))
39 (future? (future #t)))
45 (= 5 (touch (future (+ 2 3)))))
51 (make-future (lambda () i)))
54 (pass-if "touch several times"
55 (let* ((f+ (unfold (cut >= <> 123)
67 (equal? (iota 123) r1 r2 r3)))
70 (= (touch (future (+ 2 (touch (future -2))
76 (reduce + 0 (iota 123))))
78 (pass-if "multiple values"
79 (let ((lst (iota 123)))
82 (call-with-values (cut touch f) list))
84 (future (values i i)))
87 (pass-if "no exception"
88 (future? (future (throw 'foo 'bar))))
90 (pass-if-exception "exception"
92 (touch (future (throw specific-exception-key 'test "thrown!")))))
94 (with-test-prefix "nested futures"
96 (pass-if-equal "simple" 2
97 (touch (future (1+ (touch (future (1+ (touch (future 0)))))))))
99 (pass-if-equal "loop" (map - (iota 1000))
100 (let loop ((list (iota 1000)))
104 (touch (future (loop (cdr list)))))))))