continuations.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ;;;; -*- scheme -*-
  2. ;;;; continuations.test --- test suite for continutations
  3. ;;;;
  4. ;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  5. ;;;;
  6. ;;;; This program is free software; you can redistribute it and/or modify
  7. ;;;; it under the terms of the GNU General Public License as published by
  8. ;;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;;; any later version.
  10. ;;;;
  11. ;;;; This program is distributed in the hope that it will be useful,
  12. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;;; GNU General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU General Public License
  17. ;;;; along with this software; see the file COPYING. If not, write to
  18. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. ;;;; Boston, MA 02110-1301 USA
  20. (define-module (test-suite test-continuations)
  21. :use-module (test-suite lib))
  22. (define (block-reentry body)
  23. (let ((active #f))
  24. (dynamic-wind
  25. (lambda ()
  26. (if active
  27. (throw 'no-reentry)))
  28. (lambda ()
  29. (set! active #t)
  30. (body))
  31. (lambda () #f))))
  32. (define (catch-tag body)
  33. (catch #t
  34. body
  35. (lambda (tag . args) tag)))
  36. (define (check-cont)
  37. (catch-tag
  38. (lambda ()
  39. (block-reentry (lambda () (call/cc identity))))))
  40. (define (dont-crash-please)
  41. (let ((k (check-cont)))
  42. (if (procedure? k)
  43. (k 12)
  44. k)))
  45. (with-test-prefix "continuations"
  46. (pass-if "throwing to a rewound catch context"
  47. (eq? (dont-crash-please) 'no-reentry))
  48. (with-debugging-evaluator
  49. (pass-if "make a stack from a continuation"
  50. (stack? (call-with-current-continuation make-stack)))
  51. (pass-if "get a continuation's stack ID"
  52. (let ((id (call-with-current-continuation stack-id)))
  53. (or (boolean? id) (symbol? id))))
  54. (pass-if "get a continuation's innermost frame"
  55. (pair? (call-with-current-continuation last-stack-frame))))
  56. )