haskell - How to use HUnit in Stack -
i have stackproject stapro
file app/main.hs
module main import lib main = putstrln "this main" foo::int ->int foo = (+1)
and file test/spec.hs
module spec import test.hunit import main (foo) main :: io () main = putstrln "test suite not yet implemented" testfoo :: test testfoo = testcase $ assertequal "should return 2" 2 (foo 1)
when try execute tests however
$ stack test while constructing buildplan following exceptions encountered: -- while attempting add dependency, not find package main in known packages -- failure when adding dependencies: main: needed (-any), stack configuration has no specified version needed package stapro-0.1.0.0
my .cabal file is
name: stapro version: 0.1.0.0 ... build-type: simple -- extra-source-files: cabal-version: >=1.10 library hs-source-dirs: src exposed-modules: lib build-depends: base >= 4.7 && < 5 default-language: haskell2010 executable stapro-exe hs-source-dirs: app main-is: main.hs ghc-options: -threaded -rtsopts -with-rtsopts=-n build-depends: base , stapro default-language: haskell2010 test-suite stapro-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: spec.hs build-depends: base , stapro , hunit , main ghc-options: -threaded -rtsopts -with-rtsopts=-n default-language: haskell2010 ...
it looks you're trying depend on executable (main
in build-depends
of test-suite
section), can test in test suite. doesn't work, in fact can't test executable @ all.
remove main
build-depends
. move code want test library.
Comments
Post a Comment