assert.scm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ; Assert macro.
  2. ; (c) Daniel Llorens - 2012-2013
  3. ; This library is free software; you can redistribute it and/or modify it under
  4. ; the terms of the GNU General Public License as published by the Free
  5. ; Software Foundation; either version 3 of the License, or (at your option) any
  6. ; later version.
  7. (define-module (ploy assert))
  8. (define (xassert c . args)
  9. (or c (apply error args)))
  10. (define-syntax assert
  11. (lambda (x)
  12. (syntax-case x ()
  13. (_ (identifier? x) #'xassert)
  14. ((_ c arg ...) #'(or c (error arg ...))))))
  15. (define-syntax assert-fail
  16. (syntax-rules ()
  17. ((_ stat)
  18. (assert (catch #t (lambda () stat #f)
  19. (lambda x #t))))
  20. ((_ stat fail-msg)
  21. (assert (catch #t (lambda () stat #f)
  22. (lambda x #t))
  23. fail-msg))
  24. ((_ stat fail-msg suceed-msg)
  25. (assert (catch #t (lambda () stat #f)
  26. (lambda x (format #t suceed-msg)
  27. (newline)
  28. (force-output) #t))
  29. fail-msg))))
  30. (export assert assert-fail)