cabal 测试找不到 Tests.hs 文件

问题描述 投票:0回答:1

我的 Haskell 项目中有以下结构:

...
test
  |
  -- Tests.hs

在我的

.cabal
文件中:

-- The entrypoint to the test suite.
    main-is: Tests.hs

我收到的错误消息是:

:错误:

使用 -o 重定向输出,但不会生成任何输出。 没有名为“Main”的模块。

但是,当我将

Tests.hs
文件中的顶部声明从

更改为
module Tests where

module Main where

并相应地更改

.cabal
文件以使测试有效。为什么
cabal
强迫我使用
Main
作为模块名称来查找测试?

haskell cabal
1个回答
0
投票

测试只是一个常规的 Haskell 程序,ghc 希望您将

main
函数放入名为
Main
的可执行文件模块中。 Main模块的
file
不需要匹配模块名称以允许多个Main模块存在于同一目录中。
您可以使用 GHC 标志 

--main-is

覆盖它,但是 cabal

main-is
选项不会设置该标志,它仅指定哪个文件包含主模块。
    

© www.soinside.com 2019 - 2024. All rights reserved.