diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs index 8bf66089bb8eebcf70073a34df938ebc38fe8be5..6c90582e7ffb56d4dc3038b4b29d6452bcdfd995 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs @@ -11,7 +11,7 @@ import Test.Tasty.HUnit import qualified Data.ByteString.Lazy.Char8 as BS8 import Data.List.NonEmpty (fromList) -import Data.List.NonEmpty as NEL (NonEmpty) +import Data.List.NonEmpty as NEL (NonEmpty, drop) #if __GLASGOW_HASKELL__ < 804 import Data.Semigroup ((<>)) #endif @@ -214,6 +214,16 @@ goldenTestTests v pkgIx pkgDir pkgName = testGroup "test golden tests" (goldenTest "test-build-tools-with-comments.golden") $ let opts = WriteOpts False False False v pkgDir Library pkgName defaultCabalVersion in runGoldenTest opts testArgs (emptyFlags {buildTools = Flag ["happy"]}) + + , goldenVsString "Standalone tests, empty flags, not simple, no options" + (goldenTest "standalone-test.golden") $ + let opts = WriteOpts False False True v pkgDir TestSuite pkgName defaultCabalVersion + in runGoldenTest opts testArgs emptyFlags + + , goldenVsString "Standalone tests, empty flags, not simple, with comments + no minimal" + (goldenTest "standalone-test-with-comments.golden") $ + let opts = WriteOpts False False False v pkgDir TestSuite pkgName defaultCabalVersion + in runGoldenTest opts testArgs emptyFlags ] where runGoldenTest opts args flags = @@ -245,6 +255,14 @@ goldenCabalTests v pkgIx srcDb = testGroup ".cabal file golden tests" , goldenVsString "Library, empty flags, not simple, no comments + no minimal" (goldenCabal "cabal-lib-no-comments.golden") $ runGoldenTest (libProjArgs "N") emptyFlags + + , goldenVsString "Test suite, empty flags, not simple, with comments + no minimal" + (goldenCabal "cabal-test-suite-with-comments.golden") $ + runGoldenTest (testProjArgs "Y") emptyFlags + + , goldenVsString "Test suite, empty flags, not simple, no comments + no minimal" + (goldenCabal "cabal-test-suite-no-comments.golden") $ + runGoldenTest (testProjArgs "N") emptyFlags ] where runGoldenTest args flags = @@ -265,6 +283,12 @@ goldenCabalTests v pkgIx srcDb = testGroup ".cabal file golden tests" testStanza = mkTestStanza opts $ testTarget {_testDependencies = mangleBaseDep testTarget _testDependencies} mkStanza $ pkgFields ++ [libStanza, testStanza] + + (Right (ProjectSettings opts pkgDesc Nothing Nothing (Just testTarget), _)) -> do + let pkgFields = mkPkgDescription opts pkgDesc + testStanza = mkTestStanza opts $ testTarget {_testDependencies = mangleBaseDep testTarget _testDependencies} + + mkStanza $ pkgFields ++ [testStanza] (Right (ProjectSettings _ _ l e t, _)) -> assertFailure $ show l ++ "\n" ++ show e ++ "\n" ++ show t @@ -319,6 +343,12 @@ pkgArgs = fromList , "4" ] +testProjArgs :: String -> NonEmpty String +testProjArgs comments = fromList ["4", "foo-package"] + <> pkgArgs + <> fromList (NEL.drop 1 testArgs) + <> fromList [comments] + libProjArgs :: String -> NonEmpty String libProjArgs comments = fromList ["1", "foo-package"] <> pkgArgs diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-no-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-no-comments.golden new file mode 100644 index 0000000000000000000000000000000000000000..72b75365c04b9918a2662e72ccce6665f19ba782 --- /dev/null +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-no-comments.golden @@ -0,0 +1,34 @@ +cabal-version: 3.0 +name: y +version: 0.1.0.0 +synopsis: synopsis + +-- A longer description of the package. +-- description: +homepage: home +license: BSD-3-Clause +license-file: LICENSE +author: foo-kmett +maintainer: foo-kmett@kmett.kmett + +-- A copyright notice. +-- copyright: +category: Data +build-type: Simple +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: + +test-suite y-test + default-language: Haskell2010 + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + build-depends: base diff --git a/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-with-comments.golden b/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-with-comments.golden new file mode 100644 index 0000000000000000000000000000000000000000..c9639bdf9e1a5f142f3af6bbf81a17b1260e556d --- /dev/null +++ b/cabal-install/tests/fixtures/init/golden/cabal/cabal-test-suite-with-comments.golden @@ -0,0 +1,71 @@ +cabal-version: 3.0 + +-- Initial package description 'y' generated by +-- 'cabal init'. For further documentation, see: +-- http://haskell.org/cabal/users-guide/ +-- +-- The name of the package. +name: y + +-- The package version. +-- See the Haskell package versioning policy (PVP) for standards +-- guiding when and how versions should be incremented. +-- https://pvp.haskell.org +-- PVP summary: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.1.0.0 + +-- A short (one-line) description of the package. +synopsis: synopsis + +-- A longer description of the package. +-- description: + +-- URL for the project homepage or repository. +homepage: home + +-- The license under which the package is released. +license: BSD-3-Clause + +-- The file containing the license text. +license-file: LICENSE + +-- The package author(s). +author: foo-kmett + +-- An email address to which users can send suggestions, bug reports, and patches. +maintainer: foo-kmett@kmett.kmett + +-- A copyright notice. +-- copyright: +category: Data +build-type: Simple + +-- 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: + +test-suite y-test + -- Base language which the package is written in. + default-language: Haskell2010 + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- The interface type and version of the test suite. + type: exitcode-stdio-1.0 + + -- Directories containing source files. + hs-source-dirs: test + + -- The entrypoint to the test suite. + main-is: Main.hs + + -- Test dependencies. + build-depends: base diff --git a/cabal-install/tests/fixtures/init/golden/test/standalone-test-with-comments.golden b/cabal-install/tests/fixtures/init/golden/test/standalone-test-with-comments.golden new file mode 100644 index 0000000000000000000000000000000000000000..2381ebd092e32214f7055b061e1df073b4e3c77e --- /dev/null +++ b/cabal-install/tests/fixtures/init/golden/test/standalone-test-with-comments.golden @@ -0,0 +1,21 @@ +test-suite y-test + -- Base language which the package is written in. + default-language: Haskell2010 + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + + -- The interface type and version of the test suite. + type: exitcode-stdio-1.0 + + -- Directories containing source files. + hs-source-dirs: test + + -- The entrypoint to the test suite. + main-is: Main.hs + + -- Test dependencies. + build-depends: base diff --git a/cabal-install/tests/fixtures/init/golden/test/standalone-test.golden b/cabal-install/tests/fixtures/init/golden/test/standalone-test.golden new file mode 100644 index 0000000000000000000000000000000000000000..7a36e096fb25a7103b1a697bfc620fa7bafbdea3 --- /dev/null +++ b/cabal-install/tests/fixtures/init/golden/test/standalone-test.golden @@ -0,0 +1,12 @@ +test-suite y-test + default-language: Haskell2010 + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + -- other-extensions: + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + build-depends: base