【问题标题】:Haskell stack not building test executableHaskell 堆栈未构建测试可执行文件
【发布时间】:2015-09-08 19:43:03
【问题描述】:

背景

我正在 Haskell 中构建一个日志文件解析器。我正在使用堆栈来构建它。运行stack build 命令运行愉快,我的项目编译。但是,运行 stack test 会产生以下错误:

parser-test: executable not found

我在错误消息上方看到以下警告,但我不知道如何避免它所引用的重定向。

Warning: output was redirected with -o, but no output will be generated because there is no Main module.

相关文件

我还没有编写任何测试,所以测试文件是由stack new 创建的。我的 cabal 文件如下所示:

...
category:            Executable
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

library
hs-source-dirs:      src
exposed-modules:     LogParser
build-depends:       base >= 4.7 && < 5
                    , attoparsec
                    , bytestring
                    , old-locale
                    , time
default-language:    Haskell2010

executable parser-exe
hs-source-dirs:      app
main-is:             Main.hs
ghc-options:         -threaded -rtsopts -with-rtsopts=-N
build-depends:       base
                    , attoparsec
                    , bytestring
                    , old-locale
                    , time
                    , parser
default-language:    Haskell2010

test-suite parser-test
type:                exitcode-stdio-1.0
hs-source-dirs:      test
main-is:             Spec.hs
build-depends:       base
                    , attoparsec
                    , bytestring
                    , hspec
                    , hspec-attoparsec
                    , old-locale
                    , time
                    , parser
ghc-options:         -threaded -rtsopts -with-rtsopts=-N
default-language:    Haskell2010

source-repository head
type:     git
...

我想我遗漏了一些东西,但我找不到我遗漏的记录在哪里。

期望的行为

我应该看到stack documentation 中概述的Test suite not yet implemented 消息。

【问题讨论】:

  • 看来我可以通过将测试模块重命名为“主”来解决这个问题,即使我已经有一个“主”模块。对我来说似乎有点违反直觉,所以我要提出一个问题,看看是否有人同意。
  • 我怀疑他们会同意。 main-is的含义是quite clear in the documentation。

标签: haskell cabal haskell-stack


【解决方案1】:

模板中test/Spec.hs文件的内容是:

main :: IO ()
main = putStrLn "Test suite not yet implemented"

您可以在commercialhaskell/stack-templatesnew-template.hsfiles 中查看此内容。

我不确定module ParserSpec where 行来自哪里(在the Github issue 中提出),但它不是模板的一部分。在我的系统上,stack new bar &amp;&amp; cd bar &amp;&amp; stack test 成功。

关于 Main 模块要求背后的原因:它来自 Cabal 库,据我了解,它是由于 Cabal 支持的其他编译器的限制而添加的。换句话说,GHC 在技术上可以允许此代码编译,但 Cabal 不会传入这些参数以保持与其他编译器的兼容性。

【讨论】:

  • 是的,我也无法复制。在任何提交之前,我必须不假思索地将模块行添加到 Spec。我把这归结为脑放屁。很抱歉浪费了您的时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
  • 2016-07-08
  • 2019-05-19
相关资源
最近更新 更多