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文件中的每個模塊。用戶指南中的相關行:[「軟件包中的每個模塊必須列在其中一個模塊,外露模塊或主要字段中。」](https://downloads.haskell.org/~ghc/7.0 .4/docs/html/Cabal/authors.html#buildinfo) – user2407038
這似乎真的很笨重。我是否認爲我的項目佈局遵循Haskell最佳實踐?我真的會在Cabal中列出每個源文件嗎? – Feenaboccles