PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/guile/testsuite.scm

#
Lisp | 37 lines | 30 code | 6 blank | 1 comment | 0 complexity | 818689b709ad889397aa95f86c93f3c8 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. ;; Little helper functions and macros for the run tests
  2. (use-modules (ice-9 format))
  3. (define (test-error error-format . args)
  4. (display "Runtime check failed. ")
  5. (apply format #t error-format args)
  6. (newline)
  7. (exit 1))
  8. (define-macro (expect-true form)
  9. `(if (not ,form)
  10. (test-error "Expected true value of ~A" ',form)))
  11. (define-macro (expect-false form)
  12. `(if ,form
  13. (test-error "Expected false value of ~A" ',form)))
  14. (define-macro (expect-result expected-result-form equal? form)
  15. `(let ((expected-result ,expected-result-form)
  16. (result ,form))
  17. (if (not (,equal? result expected-result))
  18. (test-error "The result of ~A was ~A, expected ~A, which is not ~A"
  19. ',form result expected-result ',equal?))))
  20. (define-macro (expect-throw tag-form form)
  21. `(let ((tag ,tag-form))
  22. (if (catch #t
  23. (lambda ()
  24. ,form
  25. #t)
  26. (lambda (key . args)
  27. (if (eq? key ,tag-form)
  28. #f
  29. (test-error "The form ~A threw to ~A (expected a throw to ~A)"
  30. ',form key tag))))
  31. (test-error "The form ~A returned normally (expected a throw to ~A)"))))