Skip to content

Commit 1e96ce1

Browse files
committed
move TestSuiteStanza validation to its module
1 parent 920fa7f commit 1e96ce1

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -326,37 +326,6 @@ testSuiteFieldGrammar =
326326
<*> monoidalFieldAla "code-generators" (alaList' CommaFSep Token) testStanzaCodeGenerators
327327
^^^ availableSince CabalSpecV3_8 []
328328

329-
validateTestSuite :: Position -> TestSuiteStanza -> ParseResult src ()
330-
validateTestSuite pos stanza = case _testStanzaTestType stanza of
331-
Nothing -> pure ()
332-
Just (TestTypeUnknown _ _) -> pure ()
333-
Just tt | tt `notElem` knownTestTypes -> pure ()
334-
Just tt@(TestTypeExe _ver) -> case _testStanzaMainIs stanza of
335-
Nothing -> parseFailure pos (missingField "main-is" tt)
336-
Just _file ->
337-
when (isJust (_testStanzaTestModule stanza)) $
338-
parseWarning pos PWTExtraBenchmarkModule (extraField "test-module" tt)
339-
Just tt@(TestTypeLib _ver) -> case _testStanzaTestModule stanza of
340-
Nothing ->
341-
parseFailure pos (missingField "test-module" tt)
342-
Just _module ->
343-
when (isJust (_testStanzaMainIs stanza)) $
344-
parseWarning pos PWTExtraMainIs (extraField "main-is" tt)
345-
where
346-
missingField name tt =
347-
"The '"
348-
++ name
349-
++ "' field is required for the "
350-
++ prettyShow tt
351-
++ " test suite type."
352-
353-
extraField name tt =
354-
"The '"
355-
++ name
356-
++ "' field is not used for the '"
357-
++ prettyShow tt
358-
++ "' test suite type."
359-
360329
-------------------------------------------------------------------------------
361330
-- Benchmark
362331
-------------------------------------------------------------------------------

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import Distribution.ModuleName (ModuleName)
1818
import Distribution.Types.BuildInfo
1919
import qualified Distribution.Types.BuildInfo.Lens as L
2020
import Distribution.Types.TestSuite
21+
import Distribution.Parsec
22+
import Distribution.Fields.ParseResult
23+
import Distribution.Pretty (prettyShow)
2124
import Distribution.Types.TestSuiteInterface
2225
import Distribution.Types.TestType
2326
import Distribution.Utils.Path
@@ -40,7 +43,39 @@ instance NFData TestSuiteStanza where rnf = genericRnf
4043
instance L.HasBuildInfo TestSuiteStanza where
4144
buildInfo = testStanzaBuildInfo
4245

46+
validateTestSuite :: Position -> TestSuiteStanza -> ParseResult src ()
47+
validateTestSuite pos stanza = case _testStanzaTestType stanza of
48+
Nothing -> pure ()
49+
Just (TestTypeUnknown _ _) -> pure ()
50+
Just tt | tt `notElem` knownTestTypes -> pure ()
51+
Just tt@(TestTypeExe _ver) -> case _testStanzaMainIs stanza of
52+
Nothing -> parseFailure pos (missingField "main-is" tt)
53+
Just _file ->
54+
when (isJust (_testStanzaTestModule stanza)) $
55+
parseWarning pos PWTExtraBenchmarkModule (extraField "test-module" tt)
56+
Just tt@(TestTypeLib _ver) -> case _testStanzaTestModule stanza of
57+
Nothing ->
58+
parseFailure pos (missingField "test-module" tt)
59+
Just _module ->
60+
when (isJust (_testStanzaMainIs stanza)) $
61+
parseWarning pos PWTExtraMainIs (extraField "main-is" tt)
62+
where
63+
missingField name tt =
64+
"The '"
65+
++ name
66+
++ "' field is required for the "
67+
++ prettyShow tt
68+
++ " test suite type."
69+
70+
extraField name tt =
71+
"The '"
72+
++ name
73+
++ "' field is not used for the '"
74+
++ prettyShow tt
75+
++ "' test suite type."
76+
4377
-- | Convert a previously validated 'TestSuiteStanza' to 'GenericPackageDescription''s 'TestSuite' type
78+
-- We do not check the validity here
4479
convertTestSuite :: TestSuiteStanza -> TestSuite
4580
convertTestSuite stanza = case _testStanzaTestType stanza of
4681
Nothing -> basicTestSuite

0 commit comments

Comments
 (0)