I'm using stack and my Haskell project has the standard shape:
.
├── app
│ └── Main.hs
├── LICENSE
├── README.md
├── Setup.hs
├── src
│ ├── Lib.hs
│ └── ...
├── stack.yaml
├── package.yaml
├── test
│ └── Suit1.hs
│ └── Suit2.hs
│ └── TestUtility.hs
└── MyProject.cabal
I have two test suits Suit1
and Suit2
whcih share a common code in TestUtility
. However I'm failing to import this common code!
import TestUtility
Fails with Could not find module ‘TestUtility’
. Looking at the verbose output of GHC, I can tell that it's only looking at the src
and app
folders for modules. How do I tell it to look at the test
folder?
In my package.yaml
I'm using the following:
tests:
suite1:
main: Suite1.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -main-is Suite1
other-modules:
- TestUtility.hs ## Doesn't seem to be doing anything
dependencies:
- acme-missiles
So my main question is, what do I need to add so that GHC sees other files in the test directory but only for test suits (don't want to export that in the library)?
Secondary question, is why is GHC lookin in the app folder? Is that default behavior, or is is derived from where the executables are?
package.yaml
files that work, the only difference that jumps out is that mine has noother-modules
section. I think it's supposed to just pick up all the files in yourtest
folder. Have you tried to remove theother-modules
section? – Mark Seemann Feb 23 at 7:11Programs.Programs
? I'm wondering if the build error is coming at a different stage than compiling tests? – Masse Feb 23 at 7:53other-modules
has no effect. It's not looking for files in thetest
folder. – Santiago Cuellar Feb 23 at 14:28Programs.Programs
should have beenTestUtility
– Santiago Cuellar Feb 23 at 14:29