@@ -8,8 +8,9 @@ module TestDocs where
8import Prelude ()
8import Prelude ()
9import Prelude.Compat
9import Prelude.Compat
11−import Data.Version (Version(..))
11+import Control.Arrow (first)
13+import Data.Version (Version(..))
13import Data.Monoid
14import Data.Monoid
14import Data.Maybe (fromMaybe)
15import Data.Maybe (fromMaybe)
15import Data.List ((\\))
16import Data.List ((\\))
@@ -24,6 +25,8 @@ import Language.PureScript.Docs.AsMarkdown (codeToString)
24import qualified Language.PureScript.Publish as Publish
25import qualified Language.PureScript.Publish as Publish
25import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
26import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
28+import Web.Bower.PackageMeta (parsePackageName)
27import TestUtils
30import TestUtils
29publishOpts :: Publish.PublishOptions
32publishOpts :: Publish.PublishOptions
@@ -73,6 +76,9 @@ data Assertion
73 -- | Assert that a documented declaration includes a documentation comment
76 -- | Assert that a documented declaration includes a documentation comment
74 -- containing a particular string
77 -- containing a particular string
75 | ShouldHaveDocComment P.ModuleName Text Text
78 | ShouldHaveDocComment P.ModuleName Text Text
79+ -- | Assert that there should be some declarations re-exported from a
80+ -- particular module in a particular package.
81+ | ShouldHaveReExport (Docs.InPackage P.ModuleName)
76 deriving (Show)
82 deriving (Show)
78newtype ShowFn a = ShowFn a
84newtype ShowFn a = ShowFn a
@@ -105,8 +111,11 @@ data AssertionFailure
105 -- Fields: module name, declaration name, expected rendering, actual rendering
111 -- Fields: module name, declaration name, expected rendering, actual rendering
106 | TypeSynonymMismatch P.ModuleName Text Text Text
112 | TypeSynonymMismatch P.ModuleName Text Text Text
107 -- | A doc comment was not found or did not match what was expected
113 -- | A doc comment was not found or did not match what was expected
108− -- Fields: declaration title, expected substring, actual comments
114+ -- Fields: module name, expected substring, actual comments
109 | DocCommentMissing P.ModuleName Text (Maybe Text)
115 | DocCommentMissing P.ModuleName Text (Maybe Text)
116+ -- | A module was missing re-exports from a particular module.
117+ -- Fields: module name, expected re-export, actual re-exports.
118+ | ReExportMissing P.ModuleName (Docs.InPackage P.ModuleName) [Docs.InPackage P.ModuleName]
110 deriving (Show)
119 deriving (Show)
112data AssertionResult
121data AssertionResult
@@ -194,11 +203,19 @@ runAssertion assertion Docs.Module{..} =
194 then Pass
203 then Pass
195 else Fail (DocCommentMissing mn decl declComments)
204 else Fail (DocCommentMissing mn decl declComments)
206+ ShouldHaveReExport reExp ->
208+ reExps = map fst modReExports
210+ if reExp `elem` reExps
212+ else Fail (ReExportMissing modName reExp reExps)
198 declarationsFor mn =
215 declarationsFor mn =
199 if mn == modName
216 if mn == modName
200 then modDeclarations
217 then modDeclarations
201− else fromMaybe [] (lookup mn modReExports)
218+ else fromMaybe [] (lookup mn (map (first Docs.ignorePackage) modReExports))
203 findChildren title =
220 findChildren title =
204 fmap childrenTitles . find ((==) title . Docs.declTitle)
221 fmap childrenTitles . find ((==) title . Docs.declTitle)
@@ -247,7 +264,12 @@ testCases =
247 -- From local files
264 -- From local files
248 , ShouldBeDocumented (n "Example2") "one" []
265 , ShouldBeDocumented (n "Example2") "one" []
249 , ShouldNotBeDocumented (n "Example2") "two"
266 , ShouldNotBeDocumented (n "Example2") "two"
269+ , ShouldHaveReExport (Docs.FromDep (pkg "purescript-prelude") (n "Prelude"))
270+ , ShouldHaveReExport (Docs.Local (n "Example2"))
251 , ("Example2",
273 , ("Example2",
252 [ ShouldBeDocumented (n "Example2") "one" []
274 [ ShouldBeDocumented (n "Example2") "one" []
253 , ShouldBeDocumented (n "Example2") "two" []
275 , ShouldBeDocumented (n "Example2") "two" []
@@ -336,6 +358,7 @@ testCases =
338 n = P.moduleNameFromString . T.pack
360 n = P.moduleNameFromString . T.pack
361+ pkg str = let Right p = parsePackageName str in p
340 hasTypeVar varName =
363 hasTypeVar varName =
341 getAny . P.everythingOnTypes (<>) (Any . isVar varName)
364 getAny . P.everythingOnTypes (<>) (Any . isVar varName)