1{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE DataKinds #-}
10import Data.Version (Version(..))
12import Control.Monad hiding (forM_)
13import Control.Applicative
15import Data.Maybe (fromMaybe)
16import Data.List ((\\))
18import Data.Traversable
20import qualified Text.Parsec as Parsec
22import qualified Language.PureScript as P
23import qualified Language.PureScript.Docs as Docs
24import qualified Language.PureScript.Publish as Publish
26import qualified TestPscPublish
28publishOpts :: Publish.PublishOptions
29publishOpts = Publish.defaultPublishOptions
30 { Publish.publishGetVersion = return testVersion
31 , Publish.publishWorkingTreeDirty = return ()
33 where testVersion = ("v999.0.0", Version [999,0,0] [])
37 TestPscPublish.pushd "examples/docs" $ do
38 Docs.Package{..} <- Publish.preparePackage publishOpts
39 forM_ testCases $ \(mn, pragmas) ->
40 let mdl = takeJust ("module not found in docs: " ++ mn)
41 (find ((==) mn . Docs.modName) pkgModules)
42 in forM_ pragmas (flip runAssertionIO mdl)
44takeJust :: String -> Maybe a -> a
45takeJust msg = maybe (error msg) id
48 -- | Assert that a particular declaration is documented with the given
50 = ShouldBeDocumented P.ModuleName String [String]
51 -- | Assert that a particular declaration is not documented
52 | ShouldNotBeDocumented P.ModuleName String
53 -- | Assert that a particular declaration exists, but without a particular
55 | ChildShouldNotBeDocumented P.ModuleName String String
56 -- | Assert that a particular declaration has a particular type class
58 | ShouldBeConstrained P.ModuleName String String
62 -- | A declaration was not documented, but should have been
63 = NotDocumented P.ModuleName String
64 -- | A child declaration was not documented, but should have been
65 | ChildrenNotDocumented P.ModuleName String [String]
66 -- | A declaration was documented, but should not have been
67 | Documented P.ModuleName String
68 -- | A child declaration was documented, but should not have been
69 | ChildDocumented P.ModuleName String String
70 -- | A constraint was missing.
71 | ConstraintMissing P.ModuleName String String
72 -- | A declaration had the wrong "type" (ie, value, type, type class)
73 -- Fields: declaration title, expected "type", actual "type".
74 | WrongDeclarationType P.ModuleName String String String
79 | Fail AssertionFailure
82runAssertion :: Assertion -> Docs.Module -> AssertionResult
83runAssertion assertion Docs.Module{..} =
85 ShouldBeDocumented mn decl children ->
86 case findChildren decl (declarationsFor mn) of
88 Fail (NotDocumented mn decl)
89 Just actualChildren ->
90 case children \\ actualChildren of
92 cs -> Fail (ChildrenNotDocumented mn decl cs)
94 ShouldNotBeDocumented mn decl ->
95 case findChildren decl (declarationsFor mn) of
97 Fail (Documented mn decl)
101 ChildShouldNotBeDocumented mn decl child ->
102 case findChildren decl (declarationsFor mn) of
104 if child `elem` children
105 then Fail (ChildDocumented mn decl child)
108 Fail (NotDocumented mn decl)
110 ShouldBeConstrained mn decl tyClass ->
111 case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
113 Fail (NotDocumented mn decl)
114 Just Docs.Declaration{..} ->
116 Docs.ValueDeclaration ty ->
117 if checkConstrained ty tyClass
119 else Fail (ConstraintMissing mn decl tyClass)
121 Fail (WrongDeclarationType mn decl "value"
122 (Docs.declInfoToString declInfo))
126 if P.runModuleName mn == modName
128 else fromMaybe [] (lookup mn modReExports)
131 fmap childrenTitles . find ((==) title . Docs.declTitle)
133 childrenTitles = map Docs.cdeclTitle . Docs.declChildren
135checkConstrained ty tyClass =
136 -- Note that we don't recurse on ConstrainedType if none of the constraints
137 -- match; this is by design, as constraints should be moved to the front
140 P.ConstrainedType cs _ | any (matches tyClass) cs ->
143 checkConstrained ty' tyClass
148 (==) className . P.runProperName . P.disqualify . fst
150runAssertionIO :: Assertion -> Docs.Module -> IO ()
151runAssertionIO assertion mdl = do
152 putStrLn ("In " ++ Docs.modName mdl ++ ": " ++ show assertion)
153 case runAssertion assertion mdl of
159testCases :: [(String, [Assertion])]
162 [ -- From dependencies
163 ShouldBeDocumented (n "Prelude") "Unit" []
164 , ShouldNotBeDocumented (n "Prelude") "unit"
167 , ShouldBeDocumented (n "Example2") "one" []
168 , ShouldNotBeDocumented (n "Example2") "two"
171 [ ShouldBeDocumented (n "Example2") "one" []
172 , ShouldBeDocumented (n "Example2") "two" []
176 [ ShouldBeDocumented (n "UTF8") "thing" []
180 [ ShouldBeDocumented (n "Transitive2") "transitive3" []
184 [ ShouldBeDocumented (n "Prelude") "Boolean2" ["True"]
185 , ChildShouldNotBeDocumented (n "Prelude") "Boolean2" "False"
189 [ ShouldBeDocumented (n "Prelude") "Unit" []
190 , ShouldBeDocumented (n "DuplicateNames") "unit" []
191 , ShouldNotBeDocumented (n "Prelude") "unit"
195 [ ShouldBeDocumented (n "MultiVirtual1") "foo" []
196 , ShouldBeDocumented (n "MultiVirtual2") "bar" []
197 , ShouldBeDocumented (n "MultiVirtual2") "baz" []
201 [ ShouldBeDocumented (n "Clash1") "value" []
202 , ShouldBeDocumented (n "Clash1") "Type" []
203 , ShouldBeDocumented (n "Clash1") "TypeClass" ["typeClassMember"]
206 , ("SolitaryTypeClassMember",
207 [ ShouldBeDocumented (n "SomeTypeClass") "member" []
208 , ShouldNotBeDocumented (n "SomeTypeClass") "SomeClass"
209 , ShouldBeConstrained (n "SomeTypeClass") "member" "SomeClass"
212 , ("ReExportedTypeClass",
213 [ ShouldBeDocumented (n "SomeTypeClass") "SomeClass" ["member"]
216 , ("TypeClassWithoutMembers",
217 [ ShouldBeDocumented (n "Intermediate") "SomeClass" []
218 , ChildShouldNotBeDocumented (n "Intermediate") "SomeClass" "member"
221 -- Remove this after 0.9.
223 [ ShouldBeDocumented (n "OldOperators2") "(>>)" []
227 [ ShouldBeDocumented (n "NewOperators2") "(>>>)" []
232 n = P.moduleNameFromString
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list