diff --git a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs index daddbc6bd1b..47eba1ebbe5 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs @@ -324,8 +324,8 @@ testSuiteFieldGrammar = TestSuiteStanza <*> monoidalFieldAla "code-generators" (alaList' CommaFSep Token) testStanzaCodeGenerators ^^^ availableSince CabalSpecV3_8 [] -validateTestSuite :: Position -> TestSuiteStanza -> ParseResult TestSuite -validateTestSuite pos stanza = case testSuiteType of +validateTestSuite :: CabalSpecVersion -> Position -> TestSuiteStanza -> ParseResult TestSuite +validateTestSuite cabalSpecVersion pos stanza = case testSuiteType of Nothing -> pure basicTestSuite Just tt@(TestTypeUnknown _ _) -> @@ -357,9 +357,10 @@ validateTestSuite pos stanza = case testSuiteType of { testInterface = TestSuiteLibV09 ver module_ } where - testSuiteType = - _testStanzaTestType stanza - <|> testTypeExe <$ _testStanzaMainIs stanza + testSuiteType = _testStanzaTestType stanza <|> do + guard (cabalSpecVersion >= CabalSpecV3_8) + + testTypeExe <$ _testStanzaMainIs stanza <|> testTypeLib <$ _testStanzaTestModule stanza missingField name tt = "The '" ++ name ++ "' field is required for the " @@ -446,8 +447,8 @@ benchmarkFieldGrammar = BenchmarkStanza <*> optionalField "benchmark-module" benchmarkStanzaBenchmarkModule <*> blurFieldGrammar benchmarkStanzaBuildInfo buildInfoFieldGrammar -validateBenchmark :: Position -> BenchmarkStanza -> ParseResult Benchmark -validateBenchmark pos stanza = case benchmarkStanzaType of +validateBenchmark :: CabalSpecVersion -> Position -> BenchmarkStanza -> ParseResult Benchmark +validateBenchmark cabalSpecVersion pos stanza = case benchmarkStanzaType of Nothing -> pure emptyBenchmark { benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza } @@ -474,9 +475,10 @@ validateBenchmark pos stanza = case benchmarkStanzaType of } where - benchmarkStanzaType = - _benchmarkStanzaBenchmarkType stanza - <|> benchmarkTypeExe <$ _benchmarkStanzaMainIs stanza + benchmarkStanzaType = _benchmarkStanzaBenchmarkType stanza <|> do + guard (cabalSpecVersion >= CabalSpecV3_8) + + benchmarkTypeExe <$ _benchmarkStanzaMainIs stanza missingField name tt = "The '" ++ name ++ "' field is required for the " ++ prettyShow tt ++ " benchmark type." diff --git a/Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs b/Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs index 6b0a90d9ee2..15f8ff19c30 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs @@ -314,7 +314,7 @@ goSections specVer = traverse_ process commonStanzas <- use stateCommonStanzas name' <- parseUnqualComponentName pos args testStanza <- lift $ parseCondTree' testSuiteFieldGrammar (fromBuildInfo' name') commonStanzas fields - testSuite <- lift $ traverse (validateTestSuite pos) testStanza + testSuite <- lift $ traverse (validateTestSuite specVer pos) testStanza let hasType ts = testInterface ts /= testInterface mempty unless (onAllBranches hasType testSuite) $ lift $ parseFailure pos $ concat @@ -330,7 +330,7 @@ goSections specVer = traverse_ process commonStanzas <- use stateCommonStanzas name' <- parseUnqualComponentName pos args benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar (fromBuildInfo' name') commonStanzas fields - bench <- lift $ traverse (validateBenchmark pos) benchStanza + bench <- lift $ traverse (validateBenchmark specVer pos) benchStanza let hasType ts = benchmarkInterface ts /= benchmarkInterface mempty unless (onAllBranches hasType bench) $ lift $ parseFailure pos $ concat diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-5055.expr b/Cabal-tests/tests/ParserTests/regressions/issue-5055.expr index 648ee1f4f76..be5e955442b 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-5055.expr +++ b/Cabal-tests/tests/ParserTests/regressions/issue-5055.expr @@ -213,9 +213,11 @@ GenericPackageDescription { condTreeData = TestSuite { testName = UnqualComponentName "", - testInterface = TestSuiteExeV10 - (mkVersion [1, 0]) - "FirstMain.hs", + testInterface = + TestSuiteUnsupported + (TestTypeUnknown + "" + (mkVersion [])), testBuildInfo = BuildInfo { buildable = True, buildTools = [], diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-5055.format b/Cabal-tests/tests/ParserTests/regressions/issue-5055.format index 3e186e2391d..5aa4a1288f6 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-5055.format +++ b/Cabal-tests/tests/ParserTests/regressions/issue-5055.format @@ -19,5 +19,3 @@ test-suite flag-cabal-test build-depends: base >=4.8 && <5 if os(windows) - type: exitcode-stdio-1.0 - main-is: FirstMain.hs diff --git a/cabal-install/tests/IntegrationTests2/targets/benchmarks-disabled/p.cabal b/cabal-install/tests/IntegrationTests2/targets/benchmarks-disabled/p.cabal index c20518f8579..9dde50d8620 100644 --- a/cabal-install/tests/IntegrationTests2/targets/benchmarks-disabled/p.cabal +++ b/cabal-install/tests/IntegrationTests2/targets/benchmarks-disabled/p.cabal @@ -1,7 +1,7 @@ +cabal-version: 3.8 name: p version: 0.1 build-type: Simple -cabal-version: >= 1.10 benchmark solver-disabled type: exitcode-stdio-1.0 diff --git a/cabal-install/tests/IntegrationTests2/targets/multiple-tests/p.cabal b/cabal-install/tests/IntegrationTests2/targets/multiple-tests/p.cabal index 9d444f9e25d..653fc9bf7bd 100644 --- a/cabal-install/tests/IntegrationTests2/targets/multiple-tests/p.cabal +++ b/cabal-install/tests/IntegrationTests2/targets/multiple-tests/p.cabal @@ -1,7 +1,7 @@ +cabal-version: 3.8 name: p version: 0.1 build-type: Simple -cabal-version: >= 1.10 test-suite p1 main-is: P1.hs diff --git a/cabal-install/tests/IntegrationTests2/targets/variety/p.cabal b/cabal-install/tests/IntegrationTests2/targets/variety/p.cabal index 2eb084fc274..de0d2c26b85 100644 --- a/cabal-install/tests/IntegrationTests2/targets/variety/p.cabal +++ b/cabal-install/tests/IntegrationTests2/targets/variety/p.cabal @@ -1,7 +1,7 @@ +cabal-version: 3.8 name: p version: 0.1 build-type: Simple -cabal-version: >= 1.10 library exposed-modules: P diff --git a/cabal-testsuite/PackageTests/DuplicateModuleName/DuplicateModuleName.cabal b/cabal-testsuite/PackageTests/DuplicateModuleName/DuplicateModuleName.cabal index 63cfe4b4a25..228277d6f55 100644 --- a/cabal-testsuite/PackageTests/DuplicateModuleName/DuplicateModuleName.cabal +++ b/cabal-testsuite/PackageTests/DuplicateModuleName/DuplicateModuleName.cabal @@ -1,10 +1,10 @@ +cabal-version: 3.8 name: DuplicateModuleName version: 0.1.0.0 -license: BSD3 +license: BSD-3-Clause author: Edward Z. Yang maintainer: ezyang@cs.stanford.edu build-type: Simple -cabal-version: >=1.10 library exposed-modules: Foo diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/MultipleBenchmarks/MultipleBenchmarks.cabal b/cabal-testsuite/PackageTests/NewBuild/CmdBench/MultipleBenchmarks/MultipleBenchmarks.cabal index 1c2112d783e..6673e0a032e 100644 --- a/cabal-testsuite/PackageTests/NewBuild/CmdBench/MultipleBenchmarks/MultipleBenchmarks.cabal +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/MultipleBenchmarks/MultipleBenchmarks.cabal @@ -1,7 +1,7 @@ +cabal-version: 3.8 name: MultipleBenchmarks version: 1.0 build-type: Simple -cabal-version: >= 1.10 benchmark foo main-is: Foo.hs diff --git a/changelog.d/pr-8115 b/changelog.d/pr-8115 index 24ebd1b0cf3..8fd2214e89c 100644 --- a/changelog.d/pr-8115 +++ b/changelog.d/pr-8115 @@ -4,7 +4,7 @@ prs: #8115 issues: #7459 description: { -Allow the ommission of the `type` field in `test-suite` and `benchmark` stanzas +Allow the omission of the `type` field in `test-suite` and `benchmark` stanzas when the type can be inferred by the presence of `main-is` or `test-module`. } diff --git a/doc/file-format-changelog.rst b/doc/file-format-changelog.rst index b1e1af2ce31..f1bb178a7f1 100644 --- a/doc/file-format-changelog.rst +++ b/doc/file-format-changelog.rst @@ -49,6 +49,8 @@ relative to the respective preceding *published* version. allowed of the form ``foo/**/literalFile``. Prior, double-star wildcards required the trailing filename itself be a wildcard. +* Allow the omission of the `type` field in `test-suite` and `benchmark` stanzas + when the type can be inferred by the presence of `main-is` or `test-module`. ``cabal-version: 3.6`` ----------------------