RandomB
RandomB

Reputation: 3737

Two executables in one cabal file; stack build does not recognize them

I'm trying to make 2 executables "project". All duplicates of this question did not help me - their answers don't fix my problem. I have .cabal file like this:

name:                int-tests
version:             0.1.0.0
synopsis:            Integration Tests Suite
description:         Integration Tests Suite
license:             AllRightsReserved
author:              Author name here
maintainer:          [email protected]
copyright:           2018 Author name here
build-type:          Custom
extra-source-files:  README.md
cabal-version:       >=1.10

library
  hs-source-dirs:      common
  exposed-modules:     Common
  build-depends:       base
                     , text
                     , aeson
                     , network-uri
  default-language:    Haskell2010
  ghc-options:         -Wall -Werror

executable api-tests-exe
  hs-source-dirs:      api
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
  build-depends:       base
                     , hspec
                     , QuickCheck
  default-language:    Haskell2010

executable e2e-tests-exe
  hs-source-dirs:      e2e
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
  build-depends:       base
                     , hspec
                     , QuickCheck
  default-language:    Haskell2010

and when I call stack ide targets I don't see these 2 targets. So, stack build api-tests and stack build e2e-tests don't work too.

How can I create 2 targets' project for stack? I tried also package.yaml but result is the same. Stack version is 1.9.1. I have folders tree like:

api/
...
e2e/
...

where are Main.hs files with content like:

module Main (main) where
main :: IO ()
main = print "Hello"

Also I tried option -main-is Main but without success. Error looks like:

Error: While constructing the build plan, the following exceptions were encountered:

Unknown package: api-tests

Upvotes: 0

Views: 157

Answers (2)

RandomB
RandomB

Reputation: 3737

Problem was in stack.yaml file, I had to add '.' folder to "packages:" section.

Upvotes: 0

Libby
Libby

Reputation: 1457

AFAIK, stack build always builds all your targets. But if you want to be run just one executable, you'll need the full name including the -exe. So, stack exec api-tests-exe and stack exec e2e-tests-exe.

But what you really want to do is make these test targets: https://www.haskell.org/cabal/users-guide/developing-packages.html#test-suites

Upvotes: 1

Related Questions