example.scm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ;; Here is some example macro for defining tests:
  2. ;; (define-syntax test-check
  3. ;; (syntax-rules ()
  4. ;; ((_ title tested-expression expected-result)
  5. ;; (begin
  6. ;; (format #t "* Checking ~s\n" title)
  7. ;; (let* ((expected expected-result)
  8. ;; (produced tested-expression))
  9. ;; (if (not (equal? expected produced))
  10. ;; (begin (format #t "Expected: ~s\n" expected)
  11. ;; (format #t "Computed: ~s\n" produced))))))))
  12. ;; It can be used as follows:
  13. ;; (test-check "TITLE OF TEST"
  14. ;; expression
  15. ;; expected-result)
  16. ;; However, what other unit-testing facilities does Guile offer?
  17. ;; =======
  18. ;; SRFI-64
  19. ;; =======
  20. ;; The official Guile manual links to SRFI 64.
  21. (use-modules (srfi srfi-64))
  22. ;; Example from the docs:
  23. ;; Initialize and give a name to a simple testsuite.
  24. (test-begin "vec-test")
  25. (test-group
  26. "vec-test"
  27. (define v (make-vector 5 99))
  28. ;; Require that an expression evaluate to true.
  29. (test-assert (vector? v))
  30. ;; Test that an expression is eqv? to some other expression.
  31. (test-eqv 99 (vector-ref v 2))
  32. (vector-set! v 2 7)
  33. (test-eqv 7 (vector-ref v 2)))
  34. ;; Finish the testsuite, and report results.
  35. (test-end "vec-test")