1{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE DataKinds #-}
10import Data.Version (Version(..))
13import Data.Maybe (fromMaybe)
14import Data.List ((\\))
18import qualified Language.PureScript as P
19import qualified Language.PureScript.Docs as Docs
20import qualified Language.PureScript.Publish as Publish
21import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
25publishOpts :: Publish.PublishOptions
26publishOpts = Publish.defaultPublishOptions
27 { Publish.publishGetVersion = return testVersion
28 , Publish.publishWorkingTreeDirty = return ()
30 where testVersion = ("v999.0.0", Version [999,0,0] [])
33main = pushd "examples/docs" $ do
34 res <- Publish.preparePackage publishOpts
36 Left e -> Publish.printErrorToStdout e >> exitFailure
37 Right Docs.Package{..} ->
38 forM_ testCases $ \(P.moduleNameFromString -> mn, pragmas) ->
39 let mdl = takeJust ("module not found in docs: " ++ P.runModuleName mn)
40 (find ((==) mn . Docs.modName) pkgModules)
41 in forM_ pragmas (flip runAssertionIO mdl)
43takeJust :: String -> Maybe a -> a
44takeJust msg = fromMaybe (error msg)
47 -- | Assert that a particular declaration is documented with the given
49 = ShouldBeDocumented P.ModuleName String [String]
50 -- | Assert that a particular declaration is not documented
51 | ShouldNotBeDocumented P.ModuleName String
52 -- | Assert that a particular declaration exists, but without a particular
54 | ChildShouldNotBeDocumented P.ModuleName String String
55 -- | Assert that a particular declaration has a particular type class
57 | ShouldBeConstrained P.ModuleName String String
58 -- | Assert that a particular value declaration exists, and its type
59 -- satisfies the given predicate.
60 | ValueShouldHaveTypeSignature P.ModuleName String (ShowFn (P.Type -> Bool))
63newtype ShowFn a = ShowFn a
65instance Show (ShowFn a) where
69 -- | A declaration was not documented, but should have been
70 = NotDocumented P.ModuleName String
71 -- | A child declaration was not documented, but should have been
72 | ChildrenNotDocumented P.ModuleName String [String]
73 -- | A declaration was documented, but should not have been
74 | Documented P.ModuleName String
75 -- | A child declaration was documented, but should not have been
76 | ChildDocumented P.ModuleName String String
77 -- | A constraint was missing.
78 | ConstraintMissing P.ModuleName String String
79 -- | A declaration had the wrong "type" (ie, value, type, type class)
80 -- Fields: declaration title, expected "type", actual "type".
81 | WrongDeclarationType P.ModuleName String String String
82 -- | A value declaration had the wrong type (in the sense of "type
83 -- checking"), eg, because the inferred type was used when the explicit type
85 -- Fields: module name, declaration name, actual type.
86 | ValueDeclarationWrongType P.ModuleName String P.Type
91 | Fail AssertionFailure
94runAssertion :: Assertion -> Docs.Module -> AssertionResult
95runAssertion assertion Docs.Module{..} =
97 ShouldBeDocumented mn decl children ->
98 case findChildren decl (declarationsFor mn) of
100 Fail (NotDocumented mn decl)
101 Just actualChildren ->
102 case children \\ actualChildren of
104 cs -> Fail (ChildrenNotDocumented mn decl cs)
106 ShouldNotBeDocumented mn decl ->
107 case findChildren decl (declarationsFor mn) of
109 Fail (Documented mn decl)
113 ChildShouldNotBeDocumented mn decl child ->
114 case findChildren decl (declarationsFor mn) of
116 if child `elem` children
117 then Fail (ChildDocumented mn decl child)
120 Fail (NotDocumented mn decl)
122 ShouldBeConstrained mn decl tyClass ->
123 case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
125 Fail (NotDocumented mn decl)
126 Just Docs.Declaration{..} ->
128 Docs.ValueDeclaration ty ->
129 if checkConstrained ty tyClass
131 else Fail (ConstraintMissing mn decl tyClass)
133 Fail (WrongDeclarationType mn decl "value"
134 (Docs.declInfoToString declInfo))
136 ValueShouldHaveTypeSignature mn decl (ShowFn tyPredicate) ->
137 case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
139 Fail (NotDocumented mn decl)
140 Just Docs.Declaration{..} ->
142 Docs.ValueDeclaration ty ->
146 (ValueDeclarationWrongType mn decl ty)
148 Fail (WrongDeclarationType mn decl "value"
149 (Docs.declInfoToString declInfo))
155 else fromMaybe [] (lookup mn modReExports)
158 fmap childrenTitles . find ((==) title . Docs.declTitle)
160 childrenTitles = map Docs.cdeclTitle . Docs.declChildren
162checkConstrained :: P.Type -> String -> Bool
163checkConstrained ty tyClass =
164 -- Note that we don't recurse on ConstrainedType if none of the constraints
165 -- match; this is by design, as constraints should be moved to the front
168 P.ConstrainedType cs _ | any (matches tyClass) cs ->
171 checkConstrained ty' tyClass
176 (==) className . P.runProperName . P.disqualify . fst
178runAssertionIO :: Assertion -> Docs.Module -> IO ()
179runAssertionIO assertion mdl = do
180 putStrLn ("In " ++ P.runModuleName (Docs.modName mdl) ++ ": " ++ show assertion)
181 case runAssertion assertion mdl of
184 putStrLn ("Failed: " <> show reason)
187testCases :: [(String, [Assertion])]
190 [ -- From dependencies
191 ShouldBeDocumented (n "Prelude") "Unit" []
192 , ShouldNotBeDocumented (n "Prelude") "unit"
195 , ShouldBeDocumented (n "Example2") "one" []
196 , ShouldNotBeDocumented (n "Example2") "two"
199 [ ShouldBeDocumented (n "Example2") "one" []
200 , ShouldBeDocumented (n "Example2") "two" []
204 [ ShouldBeDocumented (n "UTF8") "thing" []
208 [ ShouldBeDocumented (n "Transitive2") "transitive3" []
212 [ ShouldBeDocumented (n "Prelude") "Boolean2" ["True"]
213 , ChildShouldNotBeDocumented (n "Prelude") "Boolean2" "False"
217 [ ShouldBeDocumented (n "Prelude") "Unit" []
218 , ShouldBeDocumented (n "DuplicateNames") "unit" []
219 , ShouldNotBeDocumented (n "Prelude") "unit"
223 [ ShouldBeDocumented (n "MultiVirtual1") "foo" []
224 , ShouldBeDocumented (n "MultiVirtual2") "bar" []
225 , ShouldBeDocumented (n "MultiVirtual2") "baz" []
229 [ ShouldBeDocumented (n "Clash1") "value" []
230 , ShouldBeDocumented (n "Clash1") "Type" []
231 , ShouldBeDocumented (n "Clash1") "TypeClass" ["typeClassMember"]
234 , ("SolitaryTypeClassMember",
235 [ ShouldBeDocumented (n "SomeTypeClass") "member" []
236 , ShouldNotBeDocumented (n "SomeTypeClass") "SomeClass"
237 , ShouldBeConstrained (n "SomeTypeClass") "member" "SomeClass"
240 , ("ReExportedTypeClass",
241 [ ShouldBeDocumented (n "SomeTypeClass") "SomeClass" ["member"]
244 , ("TypeClassWithoutMembers",
245 [ ShouldBeDocumented (n "Intermediate") "SomeClass" []
246 , ChildShouldNotBeDocumented (n "Intermediate") "SomeClass" "member"
249 -- Remove this after 0.9.
251 [ ShouldBeDocumented (n "OldOperators2") "(>>)" []
255 [ ShouldBeDocumented (n "NewOperators2") "(>>>)" []
258 , ("ExplicitTypeSignatures",
259 [ ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "explicit" (ShowFn (hasTypeVar "something"))
260 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn ((==) P.tyInt))
261 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn ((==) P.tyNumber))
266 n = P.moduleNameFromString
269 getAny . P.everythingOnTypes (<>) (Any . isVar varName)
271 isVar varName (P.TypeVar name) | varName == name = True
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