srcprop.test 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ;;;; srcprop.test --- test Guile source properties -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2003, 2006, 2009 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-srcprop)
  19. :use-module (test-suite lib))
  20. ;;;
  21. ;;; source-properties
  22. ;;;
  23. (with-test-prefix "source-properties"
  24. (pass-if "no props"
  25. (null? (source-properties (list 1 2 3))))
  26. (read-enable 'positions)
  27. (let ((s (read (open-input-string "(1 . 2)"))))
  28. (pass-if "read properties"
  29. (not (null? (source-properties s))))))
  30. ;;;
  31. ;;; set-source-property!
  32. ;;;
  33. (with-test-prefix "set-source-property!"
  34. (read-enable 'positions)
  35. (pass-if "setting the breakpoint property works"
  36. (let ((s (read (open-input-string "(+ 3 4)"))))
  37. (throw 'unresolved)
  38. (set-source-property! s 'breakpoint #t)
  39. (let ((current-trap-opts (evaluator-traps-interface))
  40. (current-debug-opts (debug-options-interface))
  41. (trap-called #f))
  42. (trap-set! enter-frame-handler (lambda _ (set! trap-called #t)))
  43. (trap-enable 'traps)
  44. (debug-enable 'debug)
  45. (debug-enable 'breakpoints)
  46. (with-traps (lambda ()
  47. (primitive-eval s)))
  48. (evaluator-traps-interface current-trap-opts)
  49. (debug-options-interface current-debug-opts)
  50. trap-called))))
  51. ;;;
  52. ;;; set-source-properties!
  53. ;;;
  54. (with-test-prefix "set-source-properties!"
  55. (read-enable 'positions)
  56. (pass-if "setting the breakpoint property works"
  57. (let ((s (read (open-input-string "(+ 3 4)"))))
  58. (throw 'unresolved)
  59. (set-source-properties! s '((breakpoint #t)))
  60. (let ((current-trap-opts (evaluator-traps-interface))
  61. (current-debug-opts (debug-options-interface))
  62. (trap-called #f))
  63. (trap-set! enter-frame-handler (lambda _ (set! trap-called #t)))
  64. (trap-enable 'traps)
  65. (debug-enable 'debug)
  66. (debug-enable 'breakpoints)
  67. (with-traps (lambda ()
  68. (primitive-eval s)))
  69. (evaluator-traps-interface current-trap-opts)
  70. (debug-options-interface current-debug-opts)
  71. trap-called)))
  72. (let ((s (read (open-input-string "(1 . 2)"))))
  73. (with-test-prefix "copied props"
  74. (pass-if "visible to source-property"
  75. (let ((t (cons 3 4)))
  76. (set-source-properties! t (source-properties s))
  77. (number? (source-property t 'line))))
  78. (pass-if "visible to source-properties"
  79. (let ((t (cons 3 4)))
  80. (set-source-properties! t (source-properties s))
  81. (not (null? (source-properties t))))))))