8

I'm attempting to create a test suite for my project, HaskSplit in my .cabal configuration:

-- Initial HaskSplit.cabal generated by cabal init.  For further 
-- documentation, see http://haskell.org/cabal/users-guide/

name:                HaskSplit
version:             0.1.0.0
synopsis:            Haskell Implementation of Shamir's Secret Sharing Scheme
-- description:         
license:             MIT
license-file:        LICENSE
author:              
maintainer:          
-- copyright:           
category:            Security
build-type:          Simple
-- extra-source-files:  
cabal-version:       >=1.10

executable HaskSplit
  main-is:             Main.hs
  default-language:    Haskell2010
  -- other-modules:       
  other-extensions:    TemplateHaskell, NoImplicitPrelude, RankNTypes, OverloadedStrings
  build-depends:       base >=4.6 && <4.7,
                       resourcet >=1.1 && <1.2,
                       bytestring >=0.10 && <0.11,
                       conduit-extra >=1.1 && <1.2,
                       vector >=0.10 && <0.11,
                       conduit >=1.1 && <1.2,
                       conduit-combinators >=0.2 && <0.3,
                       mono-traversable >=0.5 && <0.6,
                       safe >=0.3 && <0.4,
                       transformers >=0.3 && <0.4,
                       filepath >= 1.3,
                       directory >=1.2,
                       Glob >= 0.7.4,
                       errors >= 1.4,
                       optparse-applicative >= 0.8
  hs-source-dirs:      src
  default-language:    Haskell2010
  ghc-options:         -Wall -fno-warn-orphans

test-suite tests
  type:                exitcode-stdio-1.0
  default-language:    Haskell2010
  hs-source-dirs:      tests
  main-is:             Test.hs
  ghc-options:         -Wall -fno-warn-orphans
  build-depends:       base == 4.*,
                       QuickCheck >=2.6 && <2.7,
                       test-framework-quickcheck2 >= 0.3.0.3,
                       HaskSplit

Looking at an example test-suite setup here, I noticed that they're specifying their own package as one of the build-depends module. Therefore I did the same, so that I can keep my build-depends list for my test-suite short.

However when I try cabal repl test:tests in commandline, I'm getting the following error:

<command line>: cannot satisfy -package-id HaskSplit-0.1.0.0-inplace

I'm not too sure what I'm missing here, can anyone help me out? Is it cyclic dependencies happening around here? Or do I need to create a library instance of my package for the build-depends to work?

Thanks!

apxcode
  • 7,696
  • 7
  • 30
  • 41
Jacob Wang
  • 4,411
  • 5
  • 29
  • 43
  • 1
    `build-depends: HaskSplit` refers to a library named `HaskSplit`, which doesn't exist. As an aside, the bounds on your packages are extremely tight. – user2407038 May 22 '14 at 13:52

2 Answers2

9

The build-depends section can only contain libraries, not modules. I suggest you add a library to your cabal file. The exposed-modules section of the library should list all of the modules that your test (or any other user of the library) might need to reference.

As an alternative to creating a library, you could simply add the modules you need to the other-modules part of the test-suite section. If you want to include a lot of modules, though, I think the library approach is nicer.

mhwombat
  • 8,026
  • 28
  • 53
  • 1
    Cheers for that. Added the library depends and it seems to build properly. However, The executable is still asking for dependence on the `vector` library, even though the only one that uses it are the algorithms that are now encapsulated in the library. Any ideas? – Jacob Wang May 23 '14 at 07:30
  • 2
    Scratch that. This [Q&A](http://stackoverflow.com/questions/10163604/how-to-reduce-duplication-in-the-build-depends-fields-of-a-cabal-file) seems to answer my question. – Jacob Wang May 23 '14 at 07:33
2

After some more tweaking, here's what I got, for completeness sake:

-- Initial HaskSplit.cabal generated by cabal init.  For further 
-- documentation, see http://haskell.org/cabal/users-guide/

name:                HaskSplit
version:             0.1.0.0
synopsis:            Haskell Implementation of Shamir's Secret Sharing Scheme
-- description:         
license:             MIT
license-file:        LICENSE
author:              
maintainer:          
-- copyright:           
category:            Security
build-type:          Simple
-- extra-source-files:  
cabal-version:       >=1.10

executable HaskSplit
  main-is:             Main.hs
  default-language:    Haskell2010
  -- other-modules:       
  other-extensions:    RankNTypes
  build-depends:       base >=4.6 && <4.7,
                       resourcet >=1.1 && <1.2,
                       bytestring >=0.10 && <0.11,
                       conduit-extra >=1.1 && <1.2,
                       conduit >=1.1 && <1.2,
                       conduit-combinators >=0.2 && <0.3,
                       mono-traversable >=0.5 && <0.6,
                       safe >=0.3 && <0.4,
                       transformers >=0.3 && <0.4,
                       filepath >= 1.3,
                       directory >=1.2,
                       Glob >= 0.7.4,
                       errors >= 1.4,
                       optparse-applicative >= 0.8,
                       random == 1.*,
                       HaskSplit
  hs-source-dirs:      src/exe
  default-language:    Haskell2010
  ghc-options:         -Wall -fno-warn-orphans

library
  Exposed-modules:     HaskSplit.Algorithm,
                       HaskSplit.Util,
                       FiniteField.GF256,
                       FiniteField.PGF256
  default-language:    Haskell2010
  hs-source-dirs:      src/lib
  build-depends:       base >=4.6 && <4.7,
                       vector >=0.10 && <0.11,
                       random == 1.*

test-suite tests
  type:                exitcode-stdio-1.0
  default-language:    Haskell2010
  hs-source-dirs:      tests
  main-is:             Test.hs
  other-extensions:    TemplateHaskell
  ghc-options:         -Wall -fno-warn-orphans
  build-depends:       base == 4.*,
                       QuickCheck >=2.6 && <2.7,
                       test-framework-quickcheck2 >= 0.3.0.3,
                       HaskSplit
Jacob Wang
  • 4,411
  • 5
  • 29
  • 43