Skip to content

Commit d7fd25a

Browse files
authored
Merge pull request #6924 from phadej/default-language-check
Add check tests for default-language (#6288)
2 parents b256029 + 0657165 commit d7fd25a

15 files changed

+128
-15
lines changed

Cabal/Cabal.cabal

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ extra-source-files:
189189
tests/ParserTests/regressions/issue-6083-pkg-pkg.cabal
190190
tests/ParserTests/regressions/issue-6083-pkg-pkg.expr
191191
tests/ParserTests/regressions/issue-6083-pkg-pkg.format
192+
tests/ParserTests/regressions/issue-6288-a.cabal
193+
tests/ParserTests/regressions/issue-6288-a.check
194+
tests/ParserTests/regressions/issue-6288-b.cabal
195+
tests/ParserTests/regressions/issue-6288-b.check
196+
tests/ParserTests/regressions/issue-6288-c.cabal
197+
tests/ParserTests/regressions/issue-6288-c.check
198+
tests/ParserTests/regressions/issue-6288-d.cabal
199+
tests/ParserTests/regressions/issue-6288-d.check
200+
tests/ParserTests/regressions/issue-6288-e.cabal
201+
tests/ParserTests/regressions/issue-6288-e.check
202+
tests/ParserTests/regressions/issue-6288-f.cabal
203+
tests/ParserTests/regressions/issue-6288-f.check
192204
tests/ParserTests/regressions/issue-774.cabal
193205
tests/ParserTests/regressions/issue-774.check
194206
tests/ParserTests/regressions/issue-774.expr

Cabal/Distribution/FieldGrammar/Newtypes.hs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ instance (Newtype a b, Ord a, Sep sep, Parsec b) => Parsec (Set' sep b a) where
158158
instance (Newtype a b, Sep sep, Pretty b) => Pretty (Set' sep b a) where
159159
pretty = prettySep (Proxy :: Proxy sep) . map (pretty . (pack :: a -> b)) . Set.toList . unpack
160160

161+
-------------------------------------------------------------------------------
162+
-- Identifiers
163+
-------------------------------------------------------------------------------
164+
161165
-- | Haskell string or @[^ ,]+@
162166
newtype Token = Token { getToken :: String }
163167

@@ -191,6 +195,21 @@ instance Parsec a => Parsec (MQuoted a) where
191195
instance Pretty a => Pretty (MQuoted a) where
192196
pretty = pretty . unpack
193197

198+
-- | Filepath are parsed as 'Token'.
199+
newtype FilePathNT = FilePathNT { getFilePathNT :: String }
200+
201+
instance Newtype String FilePathNT
202+
203+
instance Parsec FilePathNT where
204+
parsec = pack <$> parsecToken
205+
206+
instance Pretty FilePathNT where
207+
pretty = showFilePath . unpack
208+
209+
-------------------------------------------------------------------------------
210+
-- SpecVersion
211+
-------------------------------------------------------------------------------
212+
194213
-- | Version range or just version, i.e. @cabal-version@ field.
195214
--
196215
-- There are few things to consider:
@@ -278,6 +297,10 @@ instance Pretty SpecVersion where
278297
| csv >= CabalSpecV1_12 = text (showCabalSpecVersion csv)
279298
| otherwise = text ">=" <<>> text (showCabalSpecVersion csv)
280299

300+
-------------------------------------------------------------------------------
301+
-- SpecLicense
302+
-------------------------------------------------------------------------------
303+
281304
-- | SPDX License expression or legacy license
282305
newtype SpecLicense = SpecLicense { getSpecLicense :: Either SPDX.License License }
283306

@@ -293,6 +316,10 @@ instance Parsec SpecLicense where
293316
instance Pretty SpecLicense where
294317
pretty = either pretty pretty . unpack
295318

319+
-------------------------------------------------------------------------------
320+
-- TestedWith
321+
-------------------------------------------------------------------------------
322+
296323
-- | Version range or just version
297324
newtype TestedWith = TestedWith { getTestedWith :: (CompilerFlavor, VersionRange) }
298325

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

308-
-- | Filepath are parsed as 'Token'.
309-
newtype FilePathNT = FilePathNT { getFilePathNT :: String }
310-
311-
instance Newtype String FilePathNT
312-
313-
instance Parsec FilePathNT where
314-
parsec = pack <$> parsecToken
315-
316-
instance Pretty FilePathNT where
317-
pretty = showFilePath . unpack
318-
319-
-------------------------------------------------------------------------------
320-
-- Internal
321-
-------------------------------------------------------------------------------
322-
323335
parsecTestedWith :: CabalParsing m => m (CompilerFlavor, VersionRange)
324336
parsecTestedWith = do
325337
name <- lexemeParsec

Cabal/tests/CheckTests.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ checkTests = testGroup "regressions"
4242
, checkTest "assoc-cpp-options.cabal"
4343
, checkTest "public-multilib-1.cabal"
4444
, checkTest "public-multilib-2.cabal"
45+
, checkTest "issue-6288-a.cabal"
46+
, checkTest "issue-6288-b.cabal"
47+
, checkTest "issue-6288-c.cabal"
48+
, checkTest "issue-6288-d.cabal"
49+
, checkTest "issue-6288-e.cabal"
50+
, checkTest "issue-6288-f.cabal"
4551
]
4652

4753
checkTest :: FilePath -> TestTree
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: >=1.8
2+
name: issue
3+
version: 6288
4+
build-type: Simple
5+
synopsis: default-language optionality
6+
category: Test
7+
description: Field is introduced in 1.10, defaulted in 3.4
8+
license: BSD3
9+
license-file: LICENSE
10+
maintainer: Cabal Contributors
11+
12+
library
13+
default-language: Haskell2010
14+
exposed-modules: Foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To use the 'default-language' field the package needs to specify at least 'cabal-version: >= 1.10'.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cabal-version: >= 1.8
2+
name: issue
3+
version: 6288
4+
build-type: Simple
5+
synopsis: default-language optionality
6+
category: Test
7+
description: Field is introduced in 1.10, defaulted in 3.4
8+
license: BSD3
9+
license-file: LICENSE
10+
maintainer: Cabal Contributors
11+
12+
library
13+
exposed-modules: Foo

Cabal/tests/ParserTests/regressions/issue-6288-b.check

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: >= 1.10
2+
name: issue
3+
version: 6288
4+
build-type: Simple
5+
synopsis: default-language optionality
6+
category: Test
7+
description: Field is introduced in 1.10, defaulted in 3.4
8+
license: BSD3
9+
license-file: LICENSE
10+
maintainer: Cabal Contributors
11+
12+
library
13+
default-language: Haskell2010
14+
exposed-modules: Foo

Cabal/tests/ParserTests/regressions/issue-6288-c.check

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cabal-version: >=1.10
2+
name: issue
3+
version: 6288
4+
build-type: Simple
5+
synopsis: default-language optionality
6+
category: Test
7+
description: Field is introduced in 1.10, defaulted in 3.4
8+
license: BSD3
9+
license-file: LICENSE
10+
maintainer: Cabal Contributors
11+
12+
library
13+
exposed-modules: Foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cabal-version: 3.4
2+
name: issue
3+
version: 6288
4+
synopsis: default-language optionality
5+
category: Test
6+
description: Field is introduced in 1.10, defaulted in 3.4
7+
license: BSD-3-Clause
8+
license-file: LICENSE
9+
maintainer: Cabal Contributors
10+
11+
library
12+
default-language: Haskell2010
13+
exposed-modules: Foo

Cabal/tests/ParserTests/regressions/issue-6288-e.check

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cabal-version: 3.4
2+
name: issue
3+
version: 6288
4+
build-type: Simple
5+
synopsis: default-language optionality
6+
category: Test
7+
description: Field is introduced in 1.10, defaulted in 3.4
8+
license: BSD-3-Clause
9+
license-file: LICENSE
10+
maintainer: Cabal Contributors
11+
12+
library
13+
exposed-modules: Foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)