@@ -18,6 +18,9 @@ import Distribution.ModuleName (ModuleName)
1818import Distribution.Types.BuildInfo
1919import qualified Distribution.Types.BuildInfo.Lens as L
2020import Distribution.Types.TestSuite
21+ import Distribution.Parsec
22+ import Distribution.Fields.ParseResult
23+ import Distribution.Pretty (prettyShow )
2124import Distribution.Types.TestSuiteInterface
2225import Distribution.Types.TestType
2326import Distribution.Utils.Path
@@ -40,7 +43,39 @@ instance NFData TestSuiteStanza where rnf = genericRnf
4043instance 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
4479convertTestSuite :: TestSuiteStanza -> TestSuite
4580convertTestSuite stanza = case _testStanzaTestType stanza of
4681 Nothing -> basicTestSuite
0 commit comments