Skip to content

Commit 3a0989d

Browse files
authored
Merge pull request #8115 from cydparser/optional-type
Make `type` field optional for tests and benchmarks
2 parents 1b7162f + 0675627 commit 3a0989d

File tree

18 files changed

+58
-55
lines changed

18 files changed

+58
-55
lines changed

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ testSuiteFieldGrammar = TestSuiteStanza
325325
^^^ availableSince CabalSpecV3_6 [] -- TODO 3_8
326326

327327
validateTestSuite :: Position -> TestSuiteStanza -> ParseResult TestSuite
328-
validateTestSuite pos stanza = case _testStanzaTestType stanza of
328+
validateTestSuite pos stanza = case testSuiteType of
329329
Nothing -> pure basicTestSuite
330330

331331
Just tt@(TestTypeUnknown _ _) ->
@@ -357,6 +357,11 @@ validateTestSuite pos stanza = case _testStanzaTestType stanza of
357357
{ testInterface = TestSuiteLibV09 ver module_ }
358358

359359
where
360+
testSuiteType =
361+
_testStanzaTestType stanza
362+
<|> testTypeExe <$ _testStanzaMainIs stanza
363+
<|> testTypeLib <$ _testStanzaTestModule stanza
364+
360365
missingField name tt = "The '" ++ name ++ "' field is required for the "
361366
++ prettyShow tt ++ " test suite type."
362367

@@ -442,7 +447,7 @@ benchmarkFieldGrammar = BenchmarkStanza
442447
<*> blurFieldGrammar benchmarkStanzaBuildInfo buildInfoFieldGrammar
443448

444449
validateBenchmark :: Position -> BenchmarkStanza -> ParseResult Benchmark
445-
validateBenchmark pos stanza = case _benchmarkStanzaBenchmarkType stanza of
450+
validateBenchmark pos stanza = case benchmarkStanzaType of
446451
Nothing -> pure emptyBenchmark
447452
{ benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza }
448453

@@ -469,6 +474,10 @@ validateBenchmark pos stanza = case _benchmarkStanzaBenchmarkType stanza of
469474
}
470475

471476
where
477+
benchmarkStanzaType =
478+
_benchmarkStanzaBenchmarkType stanza
479+
<|> benchmarkTypeExe <$ _benchmarkStanzaMainIs stanza
480+
472481
missingField name tt = "The '" ++ name ++ "' field is required for the "
473482
++ prettyShow tt ++ " benchmark type."
474483

Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,8 @@ goSections specVer = traverse_ process
319319
let hasType ts = testInterface ts /= testInterface mempty
320320
unless (onAllBranches hasType testSuite) $ lift $ parseFailure pos $ concat
321321
[ "Test suite " ++ show (prettyShow name')
322-
, " is missing required field \"type\" or the field "
323-
, "is not present in all conditional branches. The "
324-
, "available test types are: "
325-
, intercalate ", " (map prettyShow knownTestTypes)
322+
, " is missing required field \"main-is\" or the field "
323+
, "is not present in all conditional branches."
326324
]
327325

328326
-- TODO check duplicate name here?
@@ -337,10 +335,8 @@ goSections specVer = traverse_ process
337335
let hasType ts = benchmarkInterface ts /= benchmarkInterface mempty
338336
unless (onAllBranches hasType bench) $ lift $ parseFailure pos $ concat
339337
[ "Benchmark " ++ show (prettyShow name')
340-
, " is missing required field \"type\" or the field "
341-
, "is not present in all conditional branches. The "
342-
, "available benchmark types are: "
343-
, intercalate ", " (map prettyShow knownBenchmarkTypes)
338+
, " is missing required field \"main-is\" or the field "
339+
, "is not present in all conditional branches."
344340
]
345341

346342
-- TODO check duplicate name here?

Cabal-syntax/src/Distribution/Types/BenchmarkInterface.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import Distribution.Compat.Prelude
1111
import Distribution.Types.BenchmarkType
1212
import Distribution.Version
1313

14-
-- | The benchmark interfaces that are currently defined. Each
15-
-- benchmark must specify which interface it supports.
14+
-- | The benchmark interfaces that are currently defined.
1615
--
1716
-- More interfaces may be defined in future, either new revisions or
1817
-- totally new interfaces.

Cabal-syntax/src/Distribution/Types/BenchmarkType.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Distribution.Types.BenchmarkType (
66
BenchmarkType(..),
77
knownBenchmarkTypes,
8+
benchmarkTypeExe,
89
) where
910

1011
import Distribution.Compat.Prelude
@@ -28,7 +29,10 @@ instance Structured BenchmarkType
2829
instance NFData BenchmarkType where rnf = genericRnf
2930

3031
knownBenchmarkTypes :: [BenchmarkType]
31-
knownBenchmarkTypes = [ BenchmarkTypeExe (mkVersion [1,0]) ]
32+
knownBenchmarkTypes = [ benchmarkTypeExe ]
33+
34+
benchmarkTypeExe :: BenchmarkType
35+
benchmarkTypeExe = BenchmarkTypeExe (mkVersion [1,0])
3236

3337
instance Pretty BenchmarkType where
3438
pretty (BenchmarkTypeExe ver) = text "exitcode-stdio-" <<>> pretty ver

Cabal-syntax/src/Distribution/Types/TestSuiteInterface.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import Distribution.Types.TestType
1212
import Distribution.ModuleName
1313
import Distribution.Version
1414

15-
-- | The test suite interfaces that are currently defined. Each test suite must
16-
-- specify which interface it supports.
15+
-- | The test suite interfaces that are currently defined.
1716
--
1817
-- More interfaces may be defined in future, either new revisions or totally
1918
-- new interfaces.

Cabal-syntax/src/Distribution/Types/TestType.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
module Distribution.Types.TestType (
66
TestType(..),
77
knownTestTypes,
8+
testTypeExe,
9+
testTypeLib,
810
) where
911

1012
import Distribution.Compat.Prelude
@@ -28,8 +30,15 @@ instance Structured TestType
2830
instance NFData TestType where rnf = genericRnf
2931

3032
knownTestTypes :: [TestType]
31-
knownTestTypes = [ TestTypeExe (mkVersion [1,0])
32-
, TestTypeLib (mkVersion [0,9]) ]
33+
knownTestTypes = [ testTypeExe
34+
, testTypeLib
35+
]
36+
37+
testTypeExe :: TestType
38+
testTypeExe = TestTypeExe (mkVersion [1,0])
39+
40+
testTypeLib :: TestType
41+
testTypeLib = TestTypeLib (mkVersion [0,9])
3342

3443
instance Pretty TestType where
3544
pretty (TestTypeExe ver) = text "exitcode-stdio-" <<>> pretty ver
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
VERSION: Just (mkVersion [2,0])
2-
issue-5055-2.cabal:15:1: Test suite "flag-cabal-test" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
2+
issue-5055-2.cabal:15:1: Test suite "flag-cabal-test" is missing required field "main-is" or the field is not present in all conditional branches.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
VERSION: Just (mkVersion [2,0])
2-
issue-5055.cabal:15:1: Test suite "flag-cabal-test" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
2+
issue-5055.cabal:15:1: Test suite "flag-cabal-test" is missing required field "main-is" or the field is not present in all conditional branches.

Cabal-tests/tests/ParserTests/regressions/issue-5055.expr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,9 @@ GenericPackageDescription {
213213
condTreeData = TestSuite {
214214
testName = UnqualComponentName
215215
"",
216-
testInterface =
217-
TestSuiteUnsupported
218-
(TestTypeUnknown
219-
""
220-
(mkVersion [])),
216+
testInterface = TestSuiteExeV10
217+
(mkVersion [1, 0])
218+
"FirstMain.hs",
221219
testBuildInfo = BuildInfo {
222220
buildable = True,
223221
buildTools = [],

Cabal-tests/tests/ParserTests/regressions/issue-5055.format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ test-suite flag-cabal-test
1919
build-depends: base >=4.8 && <5
2020

2121
if os(windows)
22+
type: exitcode-stdio-1.0
23+
main-is: FirstMain.hs

0 commit comments

Comments
 (0)