【问题标题】:Logging Output from Racket Tests to File将 Racket 测试的输出记录到文件中
【发布时间】:2019-06-08 04:03:31
【问题描述】:

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

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

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

输出文件应记录测试结果或错误(如果有)。任何帮助表示赞赏。

【问题讨论】:

标签: racket rackunit


【解决方案1】:

与其自己运行检查(打印到stderr 并返回#&lt;void&gt;),不如将检查放入测试套件中,以便您可以使用rackunit/text-ui 中的run-tests

#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-port 设置为out

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    相关资源
    最近更新 更多