鉴于这一守则:
#lang racket/base
(module+ test
(require rackunit rackunit/text-ui)
(provide suite)
(define suite
(test-suite
"test tests"
(test-equal? "test string test"
"string"
"string")))
(run-tests suite))
;(require 'test)
;(suite)如果保留最后两行注释,并使用raco test test.rkt运行该文件,则将输出
raco test: (submod "test.rkt" test)
1 success(es) 0 failure(s) 0 error(s) 1 test(s) run
0
1 test passed这是意料之中的。
当文件只是作为脚本运行,而不是由raco运行时,我如何让它运行它的测试?
我以为后面的两行注释行会做我想做的事情:导入子模块,然后调用函数,
(require 'test)
(suite)但我得到的是:
$ racket test.rkt
require: unknown module
module name: #<resolved-module-path:'test>
context...:
standard-module-name-resolver在Y分钟内学习球拍似乎说'test作为一个'symbol是用于子模块的,但可能不是。
发布于 2016-04-06 19:13:53
用module+和module*声明的子模块在其包含的模块中不能用于require,因为它们可以依赖于它们的包含模块,并且不允许模块依赖图中的循环。(相反,用module声明的子模块不能依赖它们的包含模块,但是它们的包含模块可以require它们。)
尝试添加一个main子模块;当文件作为脚本运行时,应该会运行该子模块:
(module+ main
(require (submod ".." test))
(run-tests suite))顺便说一句,Racket约定是由test子模块运行测试,而不仅仅是定义测试。添加一个main子模块可能会使raco test停止为您的脚本工作;修复方法是将(run-tests suite)调用移动到test子模块。
https://stackoverflow.com/questions/36459070
复制相似问题