我正在寻找有关如何编写Main模块中定义的Haskell代码的测试的帮助.
我想测试的项目是一个cabal包,我在其中定义了多个可执行文件.每个可执行代码只声明一个文件(每个项目euler问题一个),我通常使用该cabal run
命令单独运行它们.
我曾尝试在Main模块中编写测试,但在编译时,找不到我要测试的函数("不在范围内"错误).
在这种情况下编写测试的正确方法是什么?
有关信息,以下是我的项目的目录布局:
pe/ # root pe.cabal src/ Util.hs Problem001.hs # "module Main where" and declares a main function Problem002.hs # "module Main where" and declares a main function (...) test/ TestProblem001.hs # "module Main where" and declares a main function
以下是pe.cabal的摘录:
test-suite test-all hs-source-dirs: test type: exitcode-stdio-1.0 main-is: TestProblem001.hs build-depends: base, HUnit, Cabal >= 1.9.2 executable problem-001 hs-source-dirs: src main-is: Problem001.hs build-depends: base ghc-options: -Wall -Werror -O2
[编辑]
由于我找不到任何资源来满足这个要求,我选择了一个更容易测试的项目架构:问题被定义为库而不是单个可执行文件.