Gar*_*rns 7 haskell cabal haskell-stack
我正在Haskell中构建一个日志文件解析器.我正在使用堆栈来构建它.运行stack build命令很愉快,我的项目编译.stack test但是,运行会产生以下错误:
parser-test: executable not found
Run Code Online (Sandbox Code Playgroud)
我在错误消息上方看到以下警告,但我不知道如何避免它引用的重定向.
Warning: output was redirected with -o, but no output will be generated because there is no Main module.
Run Code Online (Sandbox Code Playgroud)
我还没有编写任何测试,所以测试文件是由它创建的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
...
Run Code Online (Sandbox Code Playgroud)
我认为我错过了一些东西,但我无法找到我所缺少的东西.
我应该看到堆栈文档中Test suite not yet implemented列出的消息.
test/Spec.hs模板文件的内容是:
main :: IO ()
main = putStrLn "Test suite not yet implemented"
Run Code Online (Sandbox Code Playgroud)
您可以在Commercialhaskell/stack-templates的new-template.hsfiles中看到此内容。
我不确定该行来自哪里(如Github 问题module ParserSpec where中所述),但它不是模板的一部分。在我的系统上,成功了。stack new bar && cd bar && stack test
至于Main模块要求背后的原因:它来自 Cabal 库,据我了解,它是由于 Cabal 支持的其他编译器的限制而添加的。换句话说,GHC 在技术上可以允许此代码进行编译,但 Cabal 不会传递这些参数以保持与其他编译器的兼容性。