【发布时间】:2015-11-09 23:19:35
【问题描述】:
TLDR:是否可以使用模块重新导出来避免“暴露”所有可测试模块?
我在我的 Haskell 项目中使用了类似于 Chris Done 模板的东西。我的ventureforth.cabal 文件包含以下部分:
library
hs-source-dirs: src
exposed-modules: VForth,
VForth.Location
build-depends: base >= 4.7 && < 5
ghc-options: -Wall -Werror
default-language: Haskell2010
executable ventureforth
hs-source-dirs: app
main-is: Main.hs
build-depends: base >= 4.7 && < 5,
ventureforth -any
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
test-suite ventureforth-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base >= 4.7 && < 5,
ventureforth -any,
doctest >= 0.9 && < 0.11,
hspec -any
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
我的代码布局为
ventureforth/
|
+- ventureforth.cabal
+- app/
| |
| +- Main.hs
|
+- src/
| |
| +- VForth.hs
| +- VForth/
| |
| +- Location.hs
|
+- test/
| |
| +- Spec.hs
| +- VForth
| |
| +- LocationSpec.hs
我已设置VForth.hs 重新导出VForth.Location
module VForth (
module VForth.Location
) where
import VForth.Location
在VForth.LocationSpec 单元测试中,我只需要import VForth 来测试Location 类型。
但是,除非我将添加 VForth.Location 添加到“公开模块”列表中,否则在尝试运行 cabal test 时会遇到链接器错误。
我曾认为公开一个模块 VForth,它重新导出所有其他模块就足够了。我真的陷入了不得不在 cabal 中列出每个源文件的境地吗?
【问题讨论】:
-
如果你不想暴露一个模块,你仍然需要将它包含在
other-modules部分。除此之外,是的,你被困在 cabal 文件中列出每个模块。用户指南中的相关行:"Every module in the package must be listed in one of other-modules, exposed-modules or main-is fields." -
这看起来很笨重。我是否认为我的项目布局遵循 Haskell 最佳实践?我真的会列出 Cabal 中的每个源文件吗?
标签: haskell