From 977de79170c7c585d17cf726a52bd076bd208cca Mon Sep 17 00:00:00 2001 From: Emily Pillmore <emilypi@cohomolo.gy> Date: Wed, 5 May 2021 11:52:30 -0400 Subject: [PATCH] add formatters + fix text for extra doc + extra src files --- .../src/Distribution/Client/Init/Defaults.hs | 2 +- .../src/Distribution/Client/Init/Format.hs | 12 +-- .../Distribution/Client/Init/Interactive.hs | 83 ++++++++++++++++++- .../Client/Init/NonInteractive.hs | 2 +- .../cabal-lib-and-exe-no-comments.golden | 5 +- .../cabal-lib-and-exe-with-comments.golden | 7 +- .../golden/cabal/cabal-lib-no-comments.golden | 5 +- .../cabal/cabal-lib-with-comments.golden | 7 +- .../pkg-desc/pkg-old-cabal-with-flags.golden | 7 +- .../golden/pkg-desc/pkg-with-comments.golden | 7 +- .../golden/pkg-desc/pkg-with-flags.golden | 7 +- .../fixtures/init/golden/pkg-desc/pkg.golden | 7 +- 12 files changed, 125 insertions(+), 26 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Init/Defaults.hs b/cabal-install/src/Distribution/Client/Init/Defaults.hs index f58bdf89a3..4af745ac92 100644 --- a/cabal-install/src/Distribution/Client/Init/Defaults.hs +++ b/cabal-install/src/Distribution/Client/Init/Defaults.hs @@ -127,7 +127,7 @@ defaultCategories = defaultCabalVersions :: [CabalSpecVersion] defaultCabalVersions = - [ CabalSpecV1_10 + [ CabalSpecV1_24 , CabalSpecV2_0 , CabalSpecV2_2 , CabalSpecV2_4 diff --git a/cabal-install/src/Distribution/Client/Init/Format.hs b/cabal-install/src/Distribution/Client/Init/Format.hs index 8ad1f4908e..714a4497e7 100644 --- a/cabal-install/src/Distribution/Client/Init/Format.hs +++ b/cabal-install/src/Distribution/Client/Init/Format.hs @@ -328,14 +328,10 @@ mkPkgDescription opts pkgDesc = True opts - , case _pkgExtraSrcFiles pkgDesc of - fs - | null fs -> PrettyEmpty - | otherwise -> - field "extra-source-files" formatExtraSourceFiles (toList fs) - ["Extra source files to be distributed with the package, such as examples, or a tutorial module."] - True - opts + , field "extra-source-files" formatExtraSourceFiles (toList $ _pkgExtraSrcFiles pkgDesc) + ["Extra source files to be distributed with the package, such as examples, or a tutorial module."] + True + opts ] where cabalSpec = _pkgCabalVersion pkgDesc diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs index 9a650b3a4a..c058793ae5 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs @@ -56,13 +56,13 @@ createProjectTest -> TestTree createProjectTest pkgIx srcDb = testGroup "createProject tests" [ testGroup "with flags" - [ testCase "Check the non-interactive workflow" $ do + [ testCase "Check the interactive workflow" $ do let dummyFlags' = dummyFlags { packageType = Flag LibraryAndExecutable , minimal = Flag False , overwrite = Flag False , packageDir = Flag "/home/test/test-package" - , extraSrc = Flag ["CHANGELOG.md"] + , extraSrc = NoFlag , exposedModules = Flag [] , otherModules = Flag [] , otherExts = Flag [] @@ -474,6 +474,85 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" test @?= Nothing Left e -> assertFailure $ show e + , testCase "Check the interactive library workflow - cabal < 1.18" $ do + let inputs = fromList + -- package type + [ "1" + -- package dir + , "test-package" + -- package description + -- cabal version + , "4" + -- package name + , "test-package" + , "test-package" + -- version + , "3.1.2.3" + -- license + , "3" + -- author + , "Foobar" + -- email + , "foobar@qux.com" + -- homepage + , "qux.com" + -- synopsis + , "Qux's package" + -- category + , "3" + -- library target + -- source dir + , "1" + -- language + , "2" + -- test suite + , "n" + -- comments + , "y" + ] + + flags = emptyFlags + { cabalVersion = Flag CabalSpecV1_10 + , extraDoc = Flag [defaultChangelog] + , extraSrc = Flag ["README.md"] + } + + case (_runPrompt $ createProject silent pkgIx srcDb flags) inputs of + Right (ProjectSettings opts desc (Just lib) Nothing Nothing, _) -> do + _optOverwrite opts @?= False + _optMinimal opts @?= False + _optNoComments opts @?= False + _optVerbosity opts @?= silent + _optPkgDir opts @?= "/home/test/test-package" + _optPkgType opts @?= Library + _optPkgName opts @?= mkPackageName "test-package" + + _pkgCabalVersion desc @?= CabalSpecV1_10 + _pkgName desc @?= mkPackageName "test-package" + _pkgVersion desc @?= mkVersion [3,1,2,3] + _pkgLicense desc @?! SPDX.NONE + _pkgAuthor desc @?= "Foobar" + _pkgEmail desc @?= "foobar@qux.com" + _pkgHomePage desc @?= "qux.com" + _pkgSynopsis desc @?= "Qux's package" + _pkgCategory desc @?= "Control" + _pkgExtraSrcFiles desc @?= Set.fromList [defaultChangelog, "README.md"] + _pkgExtraDocFiles desc @?= Nothing + + _libSourceDirs lib @?= ["src"] + _libLanguage lib @?= Haskell98 + _libExposedModules lib @?= myLibModule :| [] + _libOtherModules lib @?= [] + _libOtherExts lib @?= [] + _libDependencies lib @?! [] + _libBuildTools lib @?= [] + + Right (ProjectSettings _ _ lib exe test, _) -> do + lib @?! Nothing + exe @?= Nothing + test @?= Nothing + Left e -> assertFailure $ show e + , testCase "Check the interactive executable workflow" $ do let inputs = fromList -- package type diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs index 3acea74015..e0337f343f 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/NonInteractive.hs @@ -31,7 +31,7 @@ tests -> SourcePackageDb -> TestTree tests _v _initFlags comp pkgIx srcDb = - testGroup "cabal init non-interactive" + testGroup "Distribution.Client.Init.NonInteractive.Command" [ testGroup "driver function test" [ driverFunctionTest pkgIx srcDb comp ] diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-no-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-no-comments.golden index 8c75394d2c..72b5c6a3db 100644 --- a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-no-comments.golden +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-no-comments.golden @@ -15,7 +15,10 @@ maintainer: foo-kmett@kmett.kmett -- copyright: category: Data build-type: Simple -extra-source-files: CHANGELOG.md +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: library exposed-modules: MyLib diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-with-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-with-comments.golden index f0b2b216bd..0addbe1cca 100644 --- a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-with-comments.golden +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-and-exe-with-comments.golden @@ -42,8 +42,11 @@ maintainer: foo-kmett@kmett.kmett category: Data build-type: Simple --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: library -- Modules exported by the library. diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-no-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-no-comments.golden index 336bd3fb21..d67fd8cfb3 100644 --- a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-no-comments.golden +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-no-comments.golden @@ -15,7 +15,10 @@ maintainer: foo-kmett@kmett.kmett -- copyright: category: Data build-type: Simple -extra-source-files: CHANGELOG.md +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: library exposed-modules: MyLib diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-with-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-with-comments.golden index 14b06a911c..e3b335e0cb 100644 --- a/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-with-comments.golden +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-lib-with-comments.golden @@ -42,8 +42,11 @@ maintainer: foo-kmett@kmett.kmett category: Data build-type: Simple --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: library -- Modules exported by the library. diff --git a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-old-cabal-with-flags.golden b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-old-cabal-with-flags.golden index 776f6abd32..799181abd6 100644 --- a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-old-cabal-with-flags.golden +++ b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-old-cabal-with-flags.golden @@ -41,5 +41,8 @@ maintainer: foobar@qux.com -- copyright: category: Control --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: diff --git a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-comments.golden b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-comments.golden index 47924235c7..56c3d29642 100644 --- a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-comments.golden +++ b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-comments.golden @@ -42,5 +42,8 @@ maintainer: foo-kmett@kmett.kmett category: Data build-type: Simple --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: diff --git a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-flags.golden b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-flags.golden index 52613c0f0d..643d538c8e 100644 --- a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-flags.golden +++ b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg-with-flags.golden @@ -42,5 +42,8 @@ maintainer: foobar@qux.com category: Control build-type: Simple --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: diff --git a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg.golden b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg.golden index 47924235c7..56c3d29642 100644 --- a/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg.golden +++ b/cabal-install/tests/fixtures/init/golden/pkg-desc/pkg.golden @@ -42,5 +42,8 @@ maintainer: foo-kmett@kmett.kmett category: Data build-type: Simple --- Extra files to be distributed with the package, such as examples or a README. -extra-source-files: CHANGELOG.md +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: -- GitLab