common-test.scm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;;; common-test.scm --
  2. ;;;
  3. ;; Slightly modified for Guile by Ludovic Courtès <ludo@gnu.org>, 2010.
  4. (use-modules (system base lalr)
  5. (ice-9 pretty-print))
  6. (define *error* '())
  7. (define-syntax check
  8. (syntax-rules (=>)
  9. ((_ ?expr => ?expected-result)
  10. (check ?expr (=> equal?) ?expected-result))
  11. ((_ ?expr (=> ?equal) ?expected-result)
  12. (let ((result ?expr)
  13. (expected ?expected-result))
  14. (set! *error* '())
  15. (when (not (?equal result expected))
  16. (display "Failed test: \n")
  17. (pretty-print (quote ?expr))(newline)
  18. (display "\tresult was: ")
  19. (pretty-print result)(newline)
  20. (display "\texpected: ")
  21. (pretty-print expected)(newline)
  22. (exit 1))))))
  23. ;;; --------------------------------------------------------------------
  24. (define (display-result v)
  25. (if v
  26. (begin
  27. (display "==> ")
  28. (display v)
  29. (newline))))
  30. (define eoi-token
  31. (make-lexical-token '*eoi* #f #f))
  32. (define (make-lexer tokens)
  33. (lambda ()
  34. (if (null? tokens)
  35. eoi-token
  36. (let ((t (car tokens)))
  37. (set! tokens (cdr tokens))
  38. t))))
  39. (define (error-handler message . args)
  40. (set! *error* (cons `(error-handler ,message . ,(if (pair? args)
  41. (lexical-token-category (car args))
  42. '()))
  43. *error*))
  44. (cons message args))
  45. ;;; end of file