-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FileCreators.generateCabalFile unit tests.
- Loading branch information
Showing
7 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
module UnitTests.Distribution.Client.Init.FileCreators ( | ||
tests | ||
) where | ||
|
||
import Distribution.Client.Init.FileCreators | ||
( generateCabalFile ) | ||
|
||
import Test.Tasty | ||
import Test.Tasty.Golden (goldenVsString) | ||
import Test.Tasty.HUnit | ||
|
||
import System.FilePath | ||
( (</>) ) | ||
import qualified Data.ByteString.Lazy as BS | ||
import qualified Data.ByteString.Lazy.Char8 as BS8 | ||
import qualified Data.Set as Set | ||
|
||
import Distribution.Client.Init.Types | ||
( InitFlags(..), PackageType(..) ) | ||
import Distribution.Simple.Setup | ||
( Flag(..) ) | ||
|
||
import Distribution.CabalSpecVersion | ||
( CabalSpecVersion(CabalSpecV2_4) ) | ||
import Distribution.Types.Dependency | ||
( Dependency, mkDependency ) | ||
import Distribution.Types.LibraryName | ||
( LibraryName(LMainLibName) ) | ||
import Distribution.Types.PackageName | ||
( mkPackageName ) | ||
import Distribution.Types.VersionRange | ||
( majorBoundVersion ) | ||
import Distribution.Types.Version | ||
( mkVersion ) | ||
import qualified Distribution.ModuleName as ModuleName | ||
( fromString ) | ||
import qualified Distribution.SPDX as SPDX | ||
import Language.Haskell.Extension ( Language(..) ) | ||
|
||
tests :: [TestTree] | ||
tests = [ testGroup "cabal init goldens" | ||
[ checkCabalFileGolden exeFlags "exe-only.cabal" | ||
, checkCabalFileGolden libExeAndTestFlags "lib-exe-and-test.cabal" | ||
] | ||
] | ||
|
||
checkCabalFileGolden :: InitFlags -> FilePath -> TestTree | ||
checkCabalFileGolden flags goldenFileName = | ||
goldenVsString goldenFileName goldenFilePath generatedCabalFile | ||
where | ||
inGoldensDir :: FilePath -> FilePath | ||
inGoldensDir fn = | ||
"tests" </> "UnitTests" </> "Distribution" </> "Client" </> "Init" </> | ||
"goldens" </> "generateCabalFile" </> fn | ||
|
||
goldenFilePath :: FilePath | ||
goldenFilePath = inGoldensDir goldenFileName | ||
|
||
generatedCabalFile :: IO BS.ByteString | ||
generatedCabalFile = pure . BS8.pack $ generateCabalFile goldenFileName flags | ||
|
||
-- ================================================== | ||
-- Simple exe. | ||
|
||
exeFlags :: InitFlags | ||
exeFlags = InitFlags { | ||
packageName = Flag (mkPackageName "foo") | ||
, noComments = Flag False | ||
, minimal = Flag True | ||
, version = Flag (mkVersion [3,2,1]) | ||
, synopsis = Flag "The foo package" | ||
, homepage = Flag "https://github.com/foo/foo" | ||
, license = Flag SPDX.NONE | ||
, author = Flag "me" | ||
, email = Flag "me@me.me" | ||
, category = Flag (Left "SomeCat") | ||
, cabalVersion = Flag CabalSpecV2_4 | ||
, extraSrc = Just ["CHANGELOG.md"] | ||
, interactive = Flag False | ||
, mainIs = Flag "Main.hs" | ||
, otherModules = Nothing | ||
, otherExts = Nothing | ||
, applicationDirs = Just ["app"] | ||
, language = Flag Haskell2010 | ||
, buildTools = Nothing | ||
, packageType = Flag Executable | ||
, initializeTestSuite = Flag False | ||
, exposedModules = Nothing | ||
, sourceDirs = Nothing | ||
, testDirs = Nothing | ||
, dependencies = Just testDependencies | ||
, quiet = Flag True | ||
, packageDir = NoFlag | ||
, simpleProject = Flag False | ||
, initHcPath = NoFlag | ||
, initVerbosity = NoFlag | ||
, overwrite = NoFlag | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- Lib, exe, and test suite | ||
|
||
libExeAndTestFlags :: InitFlags | ||
libExeAndTestFlags = InitFlags { | ||
packageName = Flag (mkPackageName "foo") | ||
, noComments = Flag False | ||
, minimal = Flag True | ||
, version = Flag (mkVersion [3,2,1]) | ||
, synopsis = Flag "The foo package" | ||
, homepage = Flag "https://github.com/foo/foo" | ||
, license = Flag SPDX.NONE | ||
, author = Flag "me" | ||
, email = Flag "me@me.me" | ||
, category = Flag (Left "SomeCat") | ||
, cabalVersion = Flag CabalSpecV2_4 | ||
, extraSrc = Just ["CHANGELOG.md"] | ||
, interactive = Flag False | ||
, mainIs = Flag "Main.hs" | ||
, otherModules = Nothing | ||
, otherExts = Nothing | ||
, applicationDirs = Just ["app"] | ||
, language = Flag Haskell2010 | ||
, buildTools = Nothing | ||
, packageType = Flag LibraryAndExecutable | ||
, initializeTestSuite = Flag True | ||
, exposedModules = Just (map ModuleName.fromString ["A", "B"]) | ||
, sourceDirs = Just ["src"] | ||
, testDirs = Just ["tests"] | ||
, dependencies = Just testDependencies | ||
, quiet = Flag True | ||
, packageDir = NoFlag | ||
, simpleProject = Flag False | ||
, initHcPath = NoFlag | ||
, initVerbosity = NoFlag | ||
, overwrite = NoFlag | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- Test dependency. | ||
|
||
testDependencies :: [Dependency] | ||
testDependencies = | ||
[ mkDependency | ||
(mkPackageName "base") | ||
(majorBoundVersion (mkVersion [4,13,0,0])) | ||
(Set.singleton LMainLibName) | ||
, mkDependency | ||
(mkPackageName "containers") | ||
(majorBoundVersion (mkVersion [5,7,0,0])) | ||
(Set.singleton LMainLibName) | ||
, mkDependency | ||
(mkPackageName "unordered-containers") | ||
(majorBoundVersion (mkVersion [2,7,0,0])) | ||
(Set.singleton LMainLibName) | ||
] |
16 changes: 16 additions & 0 deletions
16
...install/tests/UnitTests/Distribution/Client/Init/goldens/generateCabalFile/exe-only.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 | ||
|
||
executable foo | ||
main-is: Main.hs | ||
build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0 | ||
hs-source-dirs: app | ||
default-language: Haskell2010 |
29 changes: 29 additions & 0 deletions
29
...tests/UnitTests/Distribution/Client/Init/goldens/generateCabalFile/lib-exe-and-test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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: A, B | ||
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 | ||
hs-source-dirs: app | ||
default-language: Haskell2010 | ||
|
||
test-suite foo-test | ||
default-language: Haskell2010 | ||
type: exitcode-stdio-1.0 | ||
hs-source-dirs: tests | ||
main-is: MyLibTest.hs | ||
build-depends: base ^>=4.13.0.0, containers ^>=5.7.0.0, unordered-containers ^>=2.7.0.0 |