-
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
4 changed files
with
178 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
171 changes: 171 additions & 0 deletions
171
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,171 @@ | ||
module UnitTests.Distribution.Client.Init.FileCreators ( | ||
tests | ||
) where | ||
|
||
import Distribution.Client.Init.FileCreators | ||
( generateCabalFile ) | ||
|
||
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.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(..) ) | ||
|
||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
|
||
tests :: [TestTree] | ||
tests = | ||
[ testCase "generateCabalFile exe" | ||
(generateCabalFileTest "exekg" exeFlags expectedExeOutput) | ||
, testCase "generateCabalFile libExeAndTests" | ||
(generateCabalFileTest "libExeAndTestsPackage" libExeAndTestFlags expectedLibExeAndTestOutput) | ||
] | ||
|
||
generateCabalFileTest :: String -> InitFlags -> String -> Assertion | ||
generateCabalFileTest filename flags expected = | ||
assertEqual | ||
("Generated cabal file does not match: '" ++ filename ++ "'") expected actual | ||
where | ||
actual = generateCabalFile filename flags | ||
|
||
-------------------------------------------------- | ||
-- Simple exe. | ||
|
||
exeFlags :: InitFlags | ||
exeFlags = baseTestFlags { | ||
packageType = Flag Executable | ||
, applicationDirs = Just ["app"] | ||
} | ||
|
||
expectedExeOutput :: String | ||
expectedExeOutput = | ||
"cabal-version: 2.4\n" | ||
++ "name: foo\n" | ||
++ "version: 3.2.1\n" | ||
++ "synopsis: The foo package\n" | ||
++ "homepage: https://github.com/foo/foo\n" | ||
++ "license: NONE\n" | ||
++ "author: me\n" | ||
++ "maintainer: [email protected]\n" | ||
++ "category: SomeCat\n" | ||
++ "extra-source-files: CHANGELOG.md\n" | ||
++ "\n" | ||
++ "executable foo\n" | ||
++ " main-is: Main.hs\n" | ||
++ " build-depends: base:{} ^>=4.13.0.0, containers:{} ^>=5.7.0.0, unordered-containers:{} ^>=2.7.0.0\n" | ||
++ " hs-source-dirs: app\n" | ||
++ " default-language: Haskell2010\n" | ||
|
||
-- | ||
-------------------------------------------------- | ||
|
||
|
||
|
||
-------------------------------------------------- | ||
-- Lib, exe, and test suite | ||
|
||
libExeAndTestFlags :: InitFlags | ||
libExeAndTestFlags = baseTestFlags { | ||
packageType = Flag LibraryAndExecutable | ||
, initializeTestSuite = Flag True | ||
, testDirs = Just ["tests"] | ||
, exposedModules = Just (map ModuleName.fromString ["A", "B"]) | ||
, sourceDirs = Just ["lib"] | ||
, applicationDirs = Just ["app"] | ||
} | ||
|
||
expectedLibExeAndTestOutput :: String | ||
expectedLibExeAndTestOutput = | ||
"cabal-version: 2.4\n" | ||
++ "name: foo\n" | ||
++ "version: 3.2.1\n" | ||
++ "synopsis: The foo package\n" | ||
++ "homepage: https://github.com/foo/foo\n" | ||
++ "license: NONE\n" | ||
++ "author: me\n" | ||
++ "maintainer: [email protected]\n" | ||
++ "category: SomeCat\n" | ||
++ "extra-source-files: CHANGELOG.md\n" | ||
++ "\n" | ||
++ "library\n" | ||
++ " exposed-modules: A, B\n" | ||
++ " build-depends: base:{} ^>=4.13.0.0, containers:{} ^>=5.7.0.0, unordered-containers:{} ^>=2.7.0.0\n" | ||
++ " hs-source-dirs: lib\n" | ||
++ " default-language: Haskell2010\n" | ||
++ "\n" | ||
++ "executable foo\n" | ||
++ " main-is: Main.hs\n" | ||
++ " build-depends: base:{} ^>=4.13.0.0, containers:{} ^>=5.7.0.0, unordered-containers:{} ^>=2.7.0.0\n" | ||
++ " hs-source-dirs: app\n" | ||
++ " default-language: Haskell2010\n" | ||
++ "\n" | ||
++ "test-suite foo-test\n" | ||
++ " default-language: Haskell2010\n" | ||
++ " type: exitcode-stdio-1.0\n" | ||
++ " hs-source-dirs: tests\n" | ||
++ " main-is: MyLibTest.hs\n" | ||
++ " build-depends: base:{} ^>=4.13.0.0, containers:{} ^>=5.7.0.0, unordered-containers:{} ^>=2.7.0.0\n" | ||
|
||
-- | ||
-------------------------------------------------- | ||
|
||
|
||
testDependencies :: [Dependency] | ||
testDependencies = | ||
[ mkDependency (mkPackageName "base") (majorBoundVersion (mkVersion [4,13,0,0])) Set.empty | ||
, mkDependency (mkPackageName "containers") (majorBoundVersion (mkVersion [5,7,0,0])) Set.empty | ||
, mkDependency (mkPackageName "unordered-containers") (majorBoundVersion (mkVersion [2,7,0,0])) Set.empty | ||
] | ||
|
||
baseTestFlags :: InitFlags | ||
baseTestFlags = 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 "[email protected]" | ||
, category = Flag (Left "SomeCat") | ||
, cabalVersion = Flag CabalSpecV2_4 | ||
, extraSrc = Just ["CHANGELOG.md"] | ||
, interactive = Flag False | ||
, mainIs = Flag "Main.hs" | ||
, otherModules = Nothing | ||
, otherExts = Nothing | ||
, applicationDirs = Nothing | ||
, 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 | ||
} |