Skip to content

Add check tests for default-language (#6288) #6924

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 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ extra-source-files:
tests/ParserTests/regressions/issue-6083-pkg-pkg.cabal
tests/ParserTests/regressions/issue-6083-pkg-pkg.expr
tests/ParserTests/regressions/issue-6083-pkg-pkg.format
tests/ParserTests/regressions/issue-6288-a.cabal
tests/ParserTests/regressions/issue-6288-a.check
tests/ParserTests/regressions/issue-6288-b.cabal
tests/ParserTests/regressions/issue-6288-b.check
tests/ParserTests/regressions/issue-6288-c.cabal
tests/ParserTests/regressions/issue-6288-c.check
tests/ParserTests/regressions/issue-6288-d.cabal
tests/ParserTests/regressions/issue-6288-d.check
tests/ParserTests/regressions/issue-6288-e.cabal
tests/ParserTests/regressions/issue-6288-e.check
tests/ParserTests/regressions/issue-6288-f.cabal
tests/ParserTests/regressions/issue-6288-f.check
tests/ParserTests/regressions/issue-774.cabal
tests/ParserTests/regressions/issue-774.check
tests/ParserTests/regressions/issue-774.expr
Expand Down
42 changes: 27 additions & 15 deletions Cabal/Distribution/FieldGrammar/Newtypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ instance (Newtype a b, Ord a, Sep sep, Parsec b) => Parsec (Set' sep b a) where
instance (Newtype a b, Sep sep, Pretty b) => Pretty (Set' sep b a) where
pretty = prettySep (Proxy :: Proxy sep) . map (pretty . (pack :: a -> b)) . Set.toList . unpack

-------------------------------------------------------------------------------
-- Identifiers
-------------------------------------------------------------------------------

-- | Haskell string or @[^ ,]+@
newtype Token = Token { getToken :: String }

Expand Down Expand Up @@ -191,6 +195,21 @@ instance Parsec a => Parsec (MQuoted a) where
instance Pretty a => Pretty (MQuoted a) where
pretty = pretty . unpack

-- | Filepath are parsed as 'Token'.
newtype FilePathNT = FilePathNT { getFilePathNT :: String }

instance Newtype String FilePathNT

instance Parsec FilePathNT where
parsec = pack <$> parsecToken

instance Pretty FilePathNT where
pretty = showFilePath . unpack

-------------------------------------------------------------------------------
-- SpecVersion
-------------------------------------------------------------------------------

-- | Version range or just version, i.e. @cabal-version@ field.
--
-- There are few things to consider:
Expand Down Expand Up @@ -278,6 +297,10 @@ instance Pretty SpecVersion where
| csv >= CabalSpecV1_12 = text (showCabalSpecVersion csv)
| otherwise = text ">=" <<>> text (showCabalSpecVersion csv)

-------------------------------------------------------------------------------
-- SpecLicense
-------------------------------------------------------------------------------

-- | SPDX License expression or legacy license
newtype SpecLicense = SpecLicense { getSpecLicense :: Either SPDX.License License }

Expand All @@ -293,6 +316,10 @@ instance Parsec SpecLicense where
instance Pretty SpecLicense where
pretty = either pretty pretty . unpack

-------------------------------------------------------------------------------
-- TestedWith
-------------------------------------------------------------------------------

-- | Version range or just version
newtype TestedWith = TestedWith { getTestedWith :: (CompilerFlavor, VersionRange) }

Expand All @@ -305,21 +332,6 @@ instance Pretty TestedWith where
pretty x = case unpack x of
(compiler, vr) -> pretty compiler <+> pretty vr

-- | Filepath are parsed as 'Token'.
newtype FilePathNT = FilePathNT { getFilePathNT :: String }

instance Newtype String FilePathNT

instance Parsec FilePathNT where
parsec = pack <$> parsecToken

instance Pretty FilePathNT where
pretty = showFilePath . unpack

-------------------------------------------------------------------------------
-- Internal
-------------------------------------------------------------------------------

parsecTestedWith :: CabalParsing m => m (CompilerFlavor, VersionRange)
parsecTestedWith = do
name <- lexemeParsec
Expand Down
6 changes: 6 additions & 0 deletions Cabal/tests/CheckTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ checkTests = testGroup "regressions"
, checkTest "assoc-cpp-options.cabal"
, checkTest "public-multilib-1.cabal"
, checkTest "public-multilib-2.cabal"
, checkTest "issue-6288-a.cabal"
, checkTest "issue-6288-b.cabal"
, checkTest "issue-6288-c.cabal"
, checkTest "issue-6288-d.cabal"
, checkTest "issue-6288-e.cabal"
, checkTest "issue-6288-f.cabal"
]

checkTest :: FilePath -> TestTree
Expand Down
14 changes: 14 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-a.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: >=1.8
name: issue
version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD3
license-file: LICENSE
maintainer: Cabal Contributors

library
default-language: Haskell2010
exposed-modules: Foo
1 change: 1 addition & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To use the 'default-language' field the package needs to specify at least 'cabal-version: >= 1.10'.
13 changes: 13 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-b.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: >= 1.8
name: issue
version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD3
license-file: LICENSE
maintainer: Cabal Contributors

library
exposed-modules: Foo
Empty file.
14 changes: 14 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-c.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: >= 1.10
name: issue
version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD3
license-file: LICENSE
maintainer: Cabal Contributors

library
default-language: Haskell2010
exposed-modules: Foo
Empty file.
13 changes: 13 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-d.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: >=1.10
name: issue
version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD3
license-file: LICENSE
maintainer: Cabal Contributors

library
exposed-modules: Foo
1 change: 1 addition & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-d.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Packages using 'cabal-version: >= 1.10' must specify the 'default-language' field for each component (e.g. Haskell98 or Haskell2010). If a component uses different languages in different modules then list the other ones in the 'other-languages' field.
13 changes: 13 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-e.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.4
name: issue
version: 6288
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD-3-Clause
license-file: LICENSE
maintainer: Cabal Contributors

library
default-language: Haskell2010
exposed-modules: Foo
Empty file.
13 changes: 13 additions & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-f.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.4
name: issue
version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
license: BSD-3-Clause
license-file: LICENSE
maintainer: Cabal Contributors

library
exposed-modules: Foo
1 change: 1 addition & 0 deletions Cabal/tests/ParserTests/regressions/issue-6288-f.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Packages using 'cabal-version: >= 1.10' must specify the 'default-language' field for each component (e.g. Haskell98 or Haskell2010). If a component uses different languages in different modules then list the other ones in the 'other-languages' field.