srfi-17.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ;;;; srfi-17.test --- test suite for Guile's SRFI-17 functions. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2001, 2003, 2005, 2006, 2010 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library 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 GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-srfi-17)
  19. #:use-module (ice-9 regex)
  20. #:use-module (test-suite lib)
  21. #:use-module (srfi srfi-17))
  22. (pass-if "cond-expand srfi-17"
  23. (cond-expand (srfi-17 #t)
  24. (else #f)))
  25. ;;
  26. ;; car
  27. ;;
  28. (with-test-prefix "car"
  29. ;; this test failed in guile 1.8.1 and 1.6.8 and earlier, since `define'
  30. ;; didn't set a name on a procedure-with-setter
  31. (pass-if "procedure-name"
  32. (if (memq 'procnames (debug-options)) ;; enabled by default
  33. (eq? 'car (procedure-name car))
  34. (throw 'unsupported)))
  35. (pass-if "set! (car x)"
  36. (let ((lst (list 1)))
  37. (set! (car lst) 2)
  38. (eqv? 2 (car lst)))))
  39. ;;
  40. ;; set!
  41. ;;
  42. (define %some-variable #f)
  43. (define exception:bad-quote
  44. '(quote . "bad syntax"))
  45. ;; (put 'pass-if-syntax-error 'scheme-indent-function 1)
  46. (define-syntax pass-if-syntax-error
  47. (syntax-rules ()
  48. ((_ name pat exp)
  49. (pass-if name
  50. (catch 'syntax-error
  51. (lambda () exp (error "expected uri-error exception"))
  52. (lambda (k who what where form . maybe-subform)
  53. (if (if (pair? pat)
  54. (and (eq? who (car pat))
  55. (string-match (cdr pat) what))
  56. (string-match pat what))
  57. #t
  58. (error "unexpected syntax-error exception" what pat))))))))
  59. (with-test-prefix "set!"
  60. (with-test-prefix "target is not procedure with setter"
  61. (pass-if-exception "(set! (symbol->string 'x) 1)"
  62. exception:wrong-type-arg
  63. (set! (symbol->string 'x) 1))
  64. (pass-if-syntax-error "(set! '#f 1)"
  65. exception:bad-quote
  66. (eval '(set! '#f 1) (interaction-environment))))
  67. (with-test-prefix "target uses macro"
  68. (pass-if "(set! (@@ ...) 1)"
  69. (eval '(set! (@@ (test-suite test-srfi-17) %some-variable) 1)
  70. (interaction-environment))
  71. (equal? %some-variable 1))
  72. ;; The `(quote x)' below used to be memoized as an infinite list before
  73. ;; Guile 1.8.3.
  74. (pass-if-syntax-error "(set! 'x 1)"
  75. exception:bad-quote
  76. (eval '(set! 'x 1) (interaction-environment)))))
  77. ;;
  78. ;; setter
  79. ;;
  80. (with-test-prefix "setter"
  81. (pass-if-exception "set! (setter x)" (cons 'misc-error ".*")
  82. (set! (setter car) noop))
  83. (pass-if "car"
  84. (eq? set-car! (setter car))))