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 (`runAssertionIO` mdl)
44takeJust :: String -> Maybe a -> a
45takeJust msg = fromMaybe (error msg)
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
59 -- | Assert that a particular value declaration exists, and its type
60 -- satisfies the given predicate.
61 | ValueShouldHaveTypeSignature P.ModuleName String (ShowFn (P.Type -> Bool))
64newtype ShowFn a = ShowFn a
66instance Show (ShowFn a) where
70 -- | A declaration was not documented, but should have been
71 = NotDocumented P.ModuleName String
72 -- | A child declaration was not documented, but should have been
73 | ChildrenNotDocumented P.ModuleName String [String]
74 -- | A declaration was documented, but should not have been
75 | Documented P.ModuleName String
76 -- | A child declaration was documented, but should not have been
77 | ChildDocumented P.ModuleName String String
78 -- | A constraint was missing.
79 | ConstraintMissing P.ModuleName String String
80 -- | A declaration had the wrong "type" (ie, value, type, type class)
81 -- Fields: declaration title, expected "type", actual "type".
82 | WrongDeclarationType P.ModuleName String String String
83 -- | A value declaration had the wrong type (in the sense of "type
84 -- checking"), eg, because the inferred type was used when the explicit type
86 -- Fields: module name, declaration name, actual type.
87 | ValueDeclarationWrongType P.ModuleName String P.Type
92 | Fail AssertionFailure
95runAssertion :: Assertion -> Docs.Module -> AssertionResult
96runAssertion assertion Docs.Module{..} =
98 ShouldBeDocumented mn decl children ->
99 case findChildren decl (declarationsFor mn) of
101 Fail (NotDocumented mn decl)
102 Just actualChildren ->
103 case children \\ actualChildren of
105 cs -> Fail (ChildrenNotDocumented mn decl cs)
107 ShouldNotBeDocumented mn decl ->
108 case findChildren decl (declarationsFor mn) of
110 Fail (Documented mn decl)
114 ChildShouldNotBeDocumented mn decl child ->
115 case findChildren decl (declarationsFor mn) of
117 if child `elem` children
118 then Fail (ChildDocumented mn decl child)
121 Fail (NotDocumented mn decl)
123 ShouldBeConstrained mn decl tyClass ->
124 case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
126 Fail (NotDocumented mn decl)
127 Just Docs.Declaration{..} ->
129 Docs.ValueDeclaration ty ->
130 if checkConstrained ty tyClass
132 else Fail (ConstraintMissing mn decl tyClass)
134 Fail (WrongDeclarationType mn decl "value"
135 (Docs.declInfoToString declInfo))
137 ValueShouldHaveTypeSignature mn decl (ShowFn tyPredicate) ->
138 case find ((==) decl . Docs.declTitle) (declarationsFor mn) of
140 Fail (NotDocumented mn decl)
141 Just Docs.Declaration{..} ->
143 Docs.ValueDeclaration ty ->
147 (ValueDeclarationWrongType mn decl ty)
149 Fail (WrongDeclarationType mn decl "value"
150 (Docs.declInfoToString declInfo))
156 else fromMaybe [] (lookup mn modReExports)
159 fmap childrenTitles . find ((==) title . Docs.declTitle)
161 childrenTitles = map Docs.cdeclTitle . Docs.declChildren
163checkConstrained :: P.Type -> String -> Bool
164checkConstrained ty tyClass =
165 -- Note that we don't recurse on ConstrainedType if none of the constraints
166 -- match; this is by design, as constraints should be moved to the front
169 P.ConstrainedType cs _ | any (matches tyClass) cs ->
172 checkConstrained ty' tyClass
177 (==) className . P.runProperName . P.disqualify . fst
179runAssertionIO :: Assertion -> Docs.Module -> IO ()
180runAssertionIO assertion mdl = do
181 putStrLn ("In " ++ P.runModuleName (Docs.modName mdl) ++ ": " ++ show assertion)
182 case runAssertion assertion mdl of
185 putStrLn ("Failed: " <> show reason)
188testCases :: [(String, [Assertion])]
191 [ -- From dependencies
192 ShouldBeDocumented (n "Prelude") "Unit" []
193 , ShouldNotBeDocumented (n "Prelude") "unit"
196 , ShouldBeDocumented (n "Example2") "one" []
197 , ShouldNotBeDocumented (n "Example2") "two"
200 [ ShouldBeDocumented (n "Example2") "one" []
201 , ShouldBeDocumented (n "Example2") "two" []
205 [ ShouldBeDocumented (n "UTF8") "thing" []
209 [ ShouldBeDocumented (n "Transitive2") "transitive3" []
213 [ ShouldBeDocumented (n "Prelude") "Boolean2" ["True"]
214 , ChildShouldNotBeDocumented (n "Prelude") "Boolean2" "False"
218 [ ShouldBeDocumented (n "Prelude") "Unit" []
219 , ShouldBeDocumented (n "DuplicateNames") "unit" []
220 , ShouldNotBeDocumented (n "Prelude") "unit"
224 [ ShouldBeDocumented (n "MultiVirtual1") "foo" []
225 , ShouldBeDocumented (n "MultiVirtual2") "bar" []
226 , ShouldBeDocumented (n "MultiVirtual2") "baz" []
230 [ ShouldBeDocumented (n "Clash1") "value" []
231 , ShouldBeDocumented (n "Clash1") "Type" []
232 , ShouldBeDocumented (n "Clash1") "TypeClass" ["typeClassMember"]
235 , ("SolitaryTypeClassMember",
236 [ ShouldBeDocumented (n "SomeTypeClass") "member" []
237 , ShouldNotBeDocumented (n "SomeTypeClass") "SomeClass"
238 , ShouldBeConstrained (n "SomeTypeClass") "member" "SomeClass"
241 , ("ReExportedTypeClass",
242 [ ShouldBeDocumented (n "SomeTypeClass") "SomeClass" ["member"]
245 , ("TypeClassWithoutMembers",
246 [ ShouldBeDocumented (n "Intermediate") "SomeClass" []
247 , ChildShouldNotBeDocumented (n "Intermediate") "SomeClass" "member"
250 -- Remove this after 0.9.
252 [ ShouldBeDocumented (n "OldOperators2") "(>>)" []
256 [ ShouldBeDocumented (n "NewOperators2") "(>>>)" []
259 , ("ExplicitTypeSignatures",
260 [ ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "explicit" (ShowFn (hasTypeVar "something"))
261 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
262 , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
267 n = P.moduleNameFromString
270 getAny . P.everythingOnTypes (<>) (Any . isVar varName)
272 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