run-tests-with-coverage.scm 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. ;; ===========
  2. ;; DESCRIPTION
  3. ;; ===========
  4. ;; This is a minimalistic example of running tests with coverage in Guile taken
  5. ;; from: https://github.com/a-guile-mind/coverage, slightly adapted.
  6. (use-modules (system vm coverage)
  7. (system vm vm))
  8. (define (run-test-with-coverage test)
  9. (call-with-values
  10. ;; This is the thunk for call-with-values, so that it does not immediately
  11. ;; get executed, but instead is executed in call-with-values. Delayed
  12. ;; execution.
  13. (lambda ()
  14. (with-code-coverage
  15. ;; with-code-coverage also needs a thunk. Also delayed execution.
  16. (lambda ()
  17. ;; Load (run) the given test.
  18. (load test))))
  19. ;; Here is a procedure for processing the results of the coverage run.
  20. (lambda (data result)
  21. (let ([port (open-output-file (string-append #|test|# "test.info"))])
  22. ;; Write the information to a file for later review.
  23. (coverage-data->lcov data port #|#:modules '(bit-integer-operations)|#)
  24. ;; Close the port to that file.
  25. (close port)))))
  26. (run-test-with-coverage (cadr (program-arguments)))