error-reporting.scm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
  2. ;; Copyright (C) 2021 GNUnet e.V.
  3. ;;
  4. ;; scheme-GNUnet is free software: you can redistribute it and/or modify it
  5. ;; under the terms of the GNU Affero General Public License as published
  6. ;; by the Free Software Foundation, either version 3 of the License,
  7. ;; or (at your option) any later version.
  8. ;;
  9. ;; scheme-GNUnet is distributed in the hope that it will be useful, but
  10. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Affero General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Affero General Public License
  15. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ;;
  17. ;; SPDX-License-Identifier: AGPL-3.0-or-later
  18. (import (gnu gnunet mq error-reporting)
  19. (srfi srfi-43)
  20. (only (rnrs base) assert))
  21. (test-begin "error-reporting")
  22. (define %errors
  23. '((connection:connected)
  24. (connection:interrupted)
  25. (input:regular-end-of-file)
  26. (input:premature-end-of-file)
  27. (input:overly-small 1 3)
  28. (input:overly-small #f 3)
  29. (logic:no-handler 5)
  30. (logic:ill-formed 6)
  31. (some unexpected error !)))
  32. (test-assert "report-error doesn't fail"
  33. (begin
  34. (for-each (lambda (x)
  35. (apply report-error x))
  36. %errors)
  37. #t))
  38. (test-assert "report-error-textually ends with a newline"
  39. (for-each
  40. (lambda (x)
  41. (pk 'x x)
  42. (assert (string-suffix? "\n"
  43. (call-with-output-string
  44. (lambda (port)
  45. (apply report-error-textually port x)))))
  46. #t)
  47. %errors))
  48. (test-equal "report-error output can be redirected"
  49. (call-with-output-string
  50. (lambda (port)
  51. (parameterize ((textual-error-reporting-port port))
  52. (apply report-error '(logic:no-handler 1)))))
  53. (call-with-output-string
  54. (lambda (port)
  55. (parameterize ((current-error-port port))
  56. (apply report-error '(logic:no-handler 1))))))
  57. (test-end "error-reporting")