如何使用堆栈在 ghci 中加载测试

How to load tests in ghci with stack

我用堆栈创建了一个非常简单的项目。它包含:一个可执行文件、一个库和相关 cabal 文件中的测试目标。当我通过堆栈 ghci 将代码加载到 ghci 时,我无法在那里访问测试,即使它们位于单独的模块中。有什么方法可以这样使用吗?

尝试stack ghci (your project name):(the test suite name)。然后你应该能够输入 main 并且你的测试将 运行.

示例:

如果您的 .cabal 项目文件具有以下值:

name: ExampleProject
...
test-suite Example-test

那么 运行 的命令将是 stack ghci ExampleProject:Example-test

(@Chris Stryczynski 建议编辑)

观看 testsrc 目录,以便在您使用 :r、运行:

重新加载时更新它们
stack ghci --ghci-options -isrc --ghci-options -itest ExampleProduct:Example-test