I'm trying to set up a server to run extensive random tests against a Racket program, and want to have output from these tests sent to logs in files. How can I log output from tests to a file?
Tests from rackunit
return #<void>
, not a string, so trying to use (call-with-output-file ...
with the tests only adds #<void>
to the output file.
(call-with-output-file "testing.txt"
(λ (out)
(display <TESTS> out))
#:exists 'append)
The output file should log the test results or errors if there are any. Any help is appreciated.
Instead of running checks by themselves, which print to stderr
and return #<void>
, put the checks in a test suite, so that you can use run-tests
from rackunit/text-ui
.
#lang racket
(require rackunit rackunit/text-ui)
(define-test-suite testing
<TESTS>)
(.... something something (run-tests testing) ....)
However, the run-tests
function seems to use current-error-port
, not current-output-port
, to print test failures, so within your call-with-output-file
, you need to set the current-error-port
to out
.
(call-with-output-file "testing.txt"
(λ (out)
(parameterize ([current-error-port out])
(run-tests testing)))
#:exists 'append)