@@ -8,8 +8,9 @@ module TestDocs where
88import Prelude ()
99import Prelude.Compat
1010
11−import Data.Version (Version(..))
11+import Control.Arrow (first)
1212
13+import Data.Version (Version(..))
1314import Data.Monoid
1415import Data.Maybe (fromMaybe)
1516import Data.List ((\\))
@@ -24,6 +25,8 @@ import Language.PureScript.Docs.AsMarkdown (codeToString)
2425import qualified Language.PureScript.Publish as Publish
2526import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
2627
28+import Web.Bower.PackageMeta (parsePackageName)
29+
2730import TestUtils
2831
2932publishOpts :: Publish.PublishOptions
@@ -73,6 +76,9 @@ data Assertion
7376 -- | Assert that a documented declaration includes a documentation comment
7477 -- containing a particular string
7578 | 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)
7682 deriving (Show)
7783
7884newtype ShowFn a = ShowFn a
@@ -105,8 +111,11 @@ data AssertionFailure
105111 -- Fields: module name, declaration name, expected rendering, actual rendering
106112 | TypeSynonymMismatch P.ModuleName Text Text Text
107113 -- | 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
109115 | 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]
110119 deriving (Show)
111120
112121data AssertionResult
@@ -194,11 +203,19 @@ runAssertion assertion Docs.Module{..} =
194203 then Pass
195204 else Fail (DocCommentMissing mn decl declComments)
196205
206+ ShouldHaveReExport reExp ->
207+ let
208+ reExps = map fst modReExports
209+ in
210+ if reExp `elem` reExps
211+ then Pass
212+ else Fail (ReExportMissing modName reExp reExps)
213+
197214 where
198215 declarationsFor mn =
199216 if mn == modName
200217 then modDeclarations
201− else fromMaybe [] (lookup mn modReExports)
218+ else fromMaybe [] (lookup mn (map (first Docs.ignorePackage) modReExports))
202219
203220 findChildren title =
204221 fmap childrenTitles . find ((==) title . Docs.declTitle)
@@ -247,7 +264,12 @@ testCases =
247264 -- From local files
248265 , ShouldBeDocumented (n "Example2") "one" []
249266 , ShouldNotBeDocumented (n "Example2") "two"
267+
268+ -- Re-exports
269+ , ShouldHaveReExport (Docs.FromDep (pkg "purescript-prelude") (n "Prelude"))
270+ , ShouldHaveReExport (Docs.Local (n "Example2"))
250271 ])
272+
251273 , ("Example2",
252274 [ ShouldBeDocumented (n "Example2") "one" []
253275 , ShouldBeDocumented (n "Example2") "two" []
@@ -336,6 +358,7 @@ testCases =
336358
337359 where
338360 n = P.moduleNameFromString . T.pack
361+ pkg str = let Right p = parsePackageName str in p
339362
340363 hasTypeVar varName =
341364 getAny . P.everythingOnTypes (<>) (Any . isVar varName)