运行 其他模块的子模块

Running other modules' submodules

我想有选择地 运行 来自另一个模块的 Racket 模块的子模块。请帮我填空!

文件 1

#lang racket/base

;; <big file, lots of code>

(module+ small-tests
   ;; basic correctness checks
   (displayln "Small tests pass!")
)

(module+ big-tests
   ;; heavy duty stress tests
   (displayln "Big tests pass!")
)

文件 2

#lang racket/base

(module+ main
  ;; Trigger either the small-tests or the big-tests,
  ;; depending on what's written here.
  (require '???)
)

如果 运行 大测试也会自动 运行 小测试,那就太好了。

submod 形式用于要求模块的子模块。

举个例子:

#lang racket

(module A racket
  (module+ main
    (displayln "Hello World")))

(module B racket
  (require (submod ".." A main)))

(require 'B)

感谢 Leif 和 A​​lexis 的提示,将 File 2 到 运行 small-tests 子模块的方法是将 '??? 替换为:

(submod "file1.rkt" small-tests)

此外,编辑 big-tests 子模块以包含以下行:

(require (submod ".." small-tests))
文件 2 执行 (require (submod "file1.rkt" big-tests)).

时,

将导致小型和大型测试 运行