将球拍测试的输出记录到文件

Logging Output from Racket Tests to File

我正在尝试设置服务器以针对 Racket 程序进行 运行 广泛的随机测试,并希望将这些测试的输出发送到文件中的日志。如何将测试输出记录到文件中?

来自 rackunit return #<void> 的测试,不是字符串,因此尝试对测试使用 (call-with-output-file ... 只会将 #<void> 添加到输出文件.

(call-with-output-file "testing.txt"
    (λ (out)
      (display <TESTS> out))
  #:exists 'append)

输出文件应记录测试结果或错误(如果有)。感谢任何帮助。

而不是 运行 自己检查,打印到 stderr 和 return #<void>,将检查放在测试套件中,这样你就可以使用 run-tests 来自 rackunit/text-ui.

#lang racket
(require rackunit rackunit/text-ui)

(define-test-suite testing
  <TESTS>)

(.... something something (run-tests testing) ....)

然而,run-tests 函数似乎使用 current-error-port,而不是 current-output-port 来打印测试失败,所以在你的 call-with-output-file 中,你需要设置 current-error-portout.

(call-with-output-file "testing.txt"
  (λ (out)
    (parameterize ([current-error-port out])
      (run-tests testing)))
  #:exists 'append)