我有一个相当简单的haskell项目设置,我只想让框架在我开始编码之前使用测试等等。我在/src
目录中有可执行文件的源文件(其中/
是项目的根目录),我的测试在/testsuite
目录中。 /testsuite
包含一个名为TestSuite.hs
的简单测试文件,main = Test.Framework.defautMain tests
作为main的实现。问题是,当我运行
cabal clean && cabal configure --enable-tests && cabal build
我收到了警告
output was redirected with -o, but no output will be generated because there is no main module.
当我没有指定--enable-tests
时,构建工作正常。我的cabal文件是:
Name: Example
Version: 0.1
Synopsis: Synopsis
Description:
Long description.
License: GPL
License-File: LICENSE
Author: SeanK
Maintainer: email@example.com
Category: Development
Build-Type: Simple
Cabal-Version: >= 1.8
Test-Suite test
Type: exitcode-stdio-1.0
Main-Is: TestSuite.hs
Build-Depends: base >= 3 && < 5,
test-framework,
test-framework-quickcheck
-- QuickCheck
Hs-Source-Dirs: src,
testsuite
Executable example
Main-Is: Main.hs
-- Other-Modules:
Build-Depends: base >= 3 && < 5,
haskell98
Hs-Source-Dirs: src
Ghc-Options: -Wall
我已禁用QuickCheck因为我目前没有使用(==&gt;),这是我目前唯一需要的功能。其余的应该是直截了当的。任何帮助将不胜感激。
答案 0 :(得分:16)
您应该将TestSuite.hs
文件中的模块名称定义为Main
,例如there。
来自The Haskell 98 Report的引用:
Haskell程序是模块的集合,按照惯例,其中一个必须被称为Main,并且必须导出值main。
答案 1 :(得分:3)
而不是将TestSuite
模块重命名为Fedor建议您可以添加GHC选项以将主模块的名称设置为您的Cabal文件:
Test-Suite testFedor
ghc-options: -main-is TestSuite
显然,Cabal main-is
和GHC main-is
是不同的。我不知道怎么做。