Reputation: 15471
My .cabal
file contains the following hspec configuration:
-- The name of the package.
name: MyModule
version: 0.1.0.0
cabal-version: >=1.10
...
test-suite my-tests
ghc-options: -Wall -Werror
cpp-options: -DTEST
default-extensions: OverloadedStrings
type: exitcode-stdio-1.0
main-is: HSpecTests.hs
hs-source-dirs: tests
build-depends: MyModule, base >= 4.8 && < 4.9, containers >= 0.5 && <0.6, split >= 0.2 && < 0.3, hspec
default-language: Haskell2010
My directory structure is as follows:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
when I run cabal build
, my source build succesfully to an executable ./dist/build/myproj/myproj
.
cabal build
then fails with:
cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, tests
Inspecting the build
directory shows that the my-tests
directory is missing.
changing the hs-source-dirs
to src/tests
produces:
cabal: can't find source for HSpecTests in
dist/build/my-tests/my-tests-tmp, src/tests
While moving all tests to the top level under root/tests, and changing the .cabal
file to hs-source-dirs: tests
produces:
<command line>: cannot satisfy -package-id MyModule-0.1.0.0-inplace
(use -v for more information)
How have I misconfigured this?
Upvotes: 0
Views: 157
Reputation: 15471
There was two things wrong:
1) (thanks to @Zeta for getting me on track with my file structure), the tests needed to be in a tests directory at the root level
2) As documented here: Error while creating test suites: "cannot satisfy -package-id" my tests could not depend on an executable and required the creation of a library
Upvotes: 0
Reputation: 105886
Your hs-source-dirs
is wrong:
hs-source-dirs: tests
Given that HSpecTests
's path is src/tests/HSpecTests.hs
, it should be
hs-source-dirs: src/tests
However, keep in mind that tests
are usually in the top-level folder:
MyProject
| - src
| - Main.hs
| - Other.hs
| - tests
| -HSpecTests.hs
| - dist
| - MyProj.cabal
Upvotes: 2