-
Notifications
You must be signed in to change notification settings - Fork 711
Add FileCreators.generateCabalFile unit tests. #6678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
151 changes: 151 additions & 0 deletions
151
cabal-install/tests/UnitTests/Distribution/Client/Init/FileCreators.hs
This file contains hidden or 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,151 @@ | ||
module UnitTests.Distribution.Client.Init.FileCreators ( | ||
tests | ||
) where | ||
|
||
import Distribution.Client.Init.FileCreators | ||
( generateCabalFile ) | ||
|
||
import Test.Tasty | ||
import Test.Tasty.Golden (goldenVsString) | ||
|
||
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(..), defaultInitFlags ) | ||
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-golden.cabal" | ||
, checkCabalFileGolden libExeAndTestFlags "lib-exe-and-test-golden.cabal" | ||
] | ||
] | ||
|
||
checkCabalFileGolden :: InitFlags -> FilePath -> TestTree | ||
checkCabalFileGolden flags goldenFileName = | ||
goldenVsString goldenFileName goldenFilePath generatedCabalFile | ||
where | ||
goldenFilePath :: FilePath | ||
goldenFilePath = "tests" </> "fixtures" </> "init" </> goldenFileName | ||
|
||
generatedCabalFile :: IO BS.ByteString | ||
generatedCabalFile = pure . BS8.pack $ generateCabalFile goldenFileName flags | ||
|
||
-- ================================================== | ||
-- Base flags to set common InitFlags values. | ||
|
||
baseFlags :: InitFlags | ||
baseFlags = defaultInitFlags { | ||
-- Values common to all (or most) test flags. | ||
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 | ||
, otherModules = Nothing | ||
, otherExts = Nothing | ||
, language = Flag Haskell2010 | ||
, buildTools = Nothing | ||
, dependencies = Just testDependencies | ||
, quiet = Flag True | ||
, packageDir = NoFlag | ||
, simpleProject = Flag False | ||
, initHcPath = NoFlag | ||
, overwrite = NoFlag | ||
|
||
-- Commonly overridden values in test InitFlags. | ||
-- It is fine to provide the same value in an overridden InitFlags | ||
-- to make it clear what that particular test case is differentiating | ||
-- from others. | ||
, packageType = Flag Executable | ||
, mainIs = Flag "Main.hs" | ||
, applicationDirs = Just ["app"] | ||
, sourceDirs = Nothing | ||
, exposedModules = Nothing | ||
, initializeTestSuite = Flag False | ||
, testDirs = Nothing | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- Simple exe. | ||
|
||
exeFlags :: InitFlags | ||
exeFlags = baseFlags { | ||
-- Create an executable only, with main living in app/Main.hs. | ||
packageType = Flag Executable | ||
, mainIs = Flag "Main.hs" | ||
, applicationDirs = Just ["app"] | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- Lib, exe, and test suite | ||
|
||
libExeAndTestFlags :: InitFlags | ||
libExeAndTestFlags = 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 modules A and B. | ||
, sourceDirs = Just ["src"] | ||
, exposedModules = Just (map ModuleName.fromString ["A", "B"]) | ||
|
||
-- Create a test suite living in tests/ | ||
, initializeTestSuite = Flag True | ||
, testDirs = Just ["tests"] | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- 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
tests/UnitTests/Distribution/Client/Init/goldens/generateCabalFile/exe-only.cabal
This file contains hidden or 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: [email protected] | ||
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 hidden or 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: [email protected] | ||
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 |
This file contains hidden or 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: [email protected] | ||
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 |
This file contains hidden or 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: [email protected] | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great 👍