Skip to content

Commit 17733f6

Browse files
committed
Add cabal init golden test exercise --libandexe behaviour.
The key item captured in this test is that when 'cabal init --libandexe' is run in an empty directory it will result in a dependency on the library from the executable in the form of 'build-depends = <package-name>' but with no version constraints since they are implied by the version of the current package.
1 parent 7e29625 commit 17733f6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Language.Haskell.Extension ( Language(..) )
3939
tests :: [TestTree]
4040
tests = [ testGroup "cabal init goldens"
4141
[ checkCabalFileGolden exeFlags "exe-only-golden.cabal"
42+
, checkCabalFileGolden libAndExeFlags "lib-and-exe-golden.cabal"
4243
, checkCabalFileGolden libExeAndTestFlags "lib-exe-and-test-golden.cabal"
4344
]
4445
]
@@ -109,6 +110,29 @@ exeFlags = baseFlags {
109110
}
110111

111112

113+
-- ==================================================
114+
-- Simple lib and exe (as created by `cabal init --libandexe`).
115+
--
116+
-- Specifically, having 'exposedModules = Just ["MyLib"]' is a special
117+
-- case which results in the executable depending on the library from
118+
-- the same package, i.e. 'build-depends = foo' with no version
119+
-- constraints.
120+
121+
libAndExeFlags :: InitFlags
122+
libAndExeFlags = baseFlags {
123+
-- Create a library and executable
124+
packageType = Flag LibraryAndExecutable
125+
126+
-- Main living in app/Main.hs.
127+
, mainIs = Flag "Main.hs"
128+
, applicationDirs = Just ["app"]
129+
130+
-- Library sources live in src/ and expose the module MyLib.
131+
, sourceDirs = Just ["src"]
132+
, exposedModules = Just (map ModuleName.fromString ["MyLib"])
133+
}
134+
135+
112136
-- ==================================================
113137
-- Lib, exe, and test suite
114138

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cabal-version: 2.4
2+
name: foo
3+
version: 3.2.1
4+
synopsis: The foo package
5+
homepage: https://github.com/foo/foo
6+
license: NONE
7+
author: me
8+
maintainer: [email protected]
9+
category: SomeCat
10+
extra-source-files: CHANGELOG.md
11+
12+
library
13+
exposed-modules: MyLib
14+
build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0
15+
hs-source-dirs: src
16+
default-language: Haskell2010
17+
18+
executable foo
19+
main-is: Main.hs
20+
build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0, foo
21+
hs-source-dirs: app
22+
default-language: Haskell2010

0 commit comments

Comments
 (0)