From 17733f64a40c5412b51be1060082dc93e12caecf Mon Sep 17 00:00:00 2001 From: Matt Renaud Date: Sun, 12 Apr 2020 16:56:22 -0700 Subject: [PATCH] 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 = ' but with no version constraints since they are implied by the version of the current package. --- .../Distribution/Client/Init/FileCreators.hs | 24 +++++++++++++++++++ tests/fixtures/init/lib-and-exe-golden.cabal | 22 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/fixtures/init/lib-and-exe-golden.cabal diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs index f5ce0ecb235..f75b337e205 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs @@ -39,6 +39,7 @@ import Language.Haskell.Extension ( Language(..) ) tests :: [TestTree] tests = [ testGroup "cabal init goldens" [ checkCabalFileGolden exeFlags "exe-only-golden.cabal" + , checkCabalFileGolden libAndExeFlags "lib-and-exe-golden.cabal" , checkCabalFileGolden libExeAndTestFlags "lib-exe-and-test-golden.cabal" ] ] @@ -109,6 +110,29 @@ exeFlags = baseFlags { } +-- ================================================== +-- Simple lib and exe (as created by `cabal init --libandexe`). +-- +-- Specifically, having 'exposedModules = Just ["MyLib"]' is a special +-- case which results in the executable depending on the library from +-- the same package, i.e. 'build-depends = foo' with no version +-- constraints. + +libAndExeFlags :: InitFlags +libAndExeFlags = baseFlags { + -- Create a library and executable + packageType = Flag LibraryAndExecutable + + -- Main living in app/Main.hs. + , mainIs = Flag "Main.hs" + , applicationDirs = Just ["app"] + + -- Library sources live in src/ and expose the module MyLib. + , sourceDirs = Just ["src"] + , exposedModules = Just (map ModuleName.fromString ["MyLib"]) + } + + -- ================================================== -- Lib, exe, and test suite diff --git a/tests/fixtures/init/lib-and-exe-golden.cabal b/tests/fixtures/init/lib-and-exe-golden.cabal new file mode 100644 index 00000000000..31a6f88c530 --- /dev/null +++ b/tests/fixtures/init/lib-and-exe-golden.cabal @@ -0,0 +1,22 @@ +cabal-version: 2.4 +name: foo +version: 3.2.1 +synopsis: The foo package +homepage: https://github.com/foo/foo +license: NONE +author: me +maintainer: me@me.me +category: SomeCat +extra-source-files: CHANGELOG.md + +library + exposed-modules: MyLib + build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0 + hs-source-dirs: src + default-language: Haskell2010 + +executable foo + main-is: Main.hs + build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0, foo + hs-source-dirs: app + default-language: Haskell2010