我怎样才能为CabalStack包指定比hs-source-dirssource-dirs更多控制的源文件?

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

我有一个使用Stack(因此是Cabal)构建的Haskell项目,现在我有src目录和测试目录,但是我想把测试和源文件混合在一起,这意味着所有的东西都会进入src目录。

为此,我需要定义我的 tests build-info源文件是指src中扩展名为.test.hs的文件。然而,似乎定义源文件的唯一选择就是 source-dirshs-source-dirs 意思是说,我必须把 src 作为 source-dirs,这似乎是错误的,因为它也在捕获正常的源文件。

这是我的package.yaml.的一部分。

tests:
  myapp-test:
    main:                Main.hs
    source-dirs:         test
    ...

我希望它是这样的:

tests:
  myapp-test:
    main:                Main.hs
    source-files:         src/**/*.test.hs
    ...

有没有类似的选项,比如source -files,或者其他的方式来实现?谢谢!我有一个Haskell项目,它是由一个Haskell文件组成的。

haskell testing cabal haskell-stack
1个回答
0
投票

分开 srctests dir是惯例,但不是必须的。hs-source-dirs 默认为 ..

Cabal可以自己找到所有的源文件,否则就会出现以下情况。extra-source-files.

你的选择是在模块层面。exposed-modules, other-modules.你可以将它们用于库和可执行文件。

在你的 .cabal 文件。

  • 用一个 executable <name> 每个可执行文件的条目。main-is 是指文件中含有 module Main where ....
  • 使用一个 library <name> 每个图书馆。
  • 使用一个 test-suite <name> 每项测试应用都需要参赛。

    • type 是必须的(如 type: exitcode-stdio-1.0).
    • main-is 是测试文件。
    • ghc-options: -main-is <your.hs>
    • 在测试文件中也有一个
      main :: IO ()
      main = hspec spec -- or: spec1 >> spec2
    

卡巴尔的用法。

  cabal new-build
  cabal new-test [<which test>]
  cabal new-run <file without path>

深入 dist-newstyle 你会发现

  • 下的可执行文件 x 目录
  • 下的测试可执行文件。t 目录
  • 图书馆 .so 归档 l 目录

链接:

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