on master help sign in
Merge pull request #1140 from PhilipRasmussen/idrisdoc

IdrisDoc test improvements, Haddock, and bug fix

commitf9827acf647d59ca717158de87e2fd5596c443c9 authorDavid Christiansen <david@davidchristiansen.dk> dateThu 1 May 2014, 07:28 (12 years ago) parent2693cb1443e899
16 files changed+85−30
idris.cabal+5 src/Idris/IdrisDoc.hs+26−10 src/Idris/REPL.hs+4−2 test/idrisdoc001/TestPrivate.idr+5 test/idrisdoc001/expected+2 test/idrisdoc001/run+1−1 test/idrisdoc001/test_empty.ipkg+1−1 test/idrisdoc006/A.idr → test/idrisdoc006/A/fully/Qualified/NAME.idr+1−1 test/idrisdoc006/expected+6−5 test/idrisdoc006/package_a.ipkg+1−1 test/idrisdoc006/run+9−9 test/idrisdoc008/Abstract.idr+5 test/idrisdoc008/Visible.idr+5 test/idrisdoc008/expected+4 test/idrisdoc008/run+6 test/idrisdoc008/visibility.ipkg+4
idris.cabal+5
@@ -339,12 +339,17 @@ Extra-source-files:
339339 test/idrisdoc005/*.ipkg
340340 test/idrisdoc006/run
341341 test/idrisdoc006/expected
342+ test/idrisdoc006/A/fully/Qualified/NAME.idr
342343 test/idrisdoc006/*.idr
343344 test/idrisdoc006/*.ipkg
344345 test/idrisdoc007/run
345346 test/idrisdoc007/expected
346347 test/idrisdoc007/*.idr
347348 test/idrisdoc007/*.ipkg
349+ test/idrisdoc008/run
350+ test/idrisdoc008/expected
351+ test/idrisdoc008/*.idr
352+ test/idrisdoc008/*.ipkg
348353
349354 test/interactive001/run
350355 test/interactive001/input
src/Idris/IdrisDoc.hs+26−10
@@ -77,10 +77,19 @@ generateDocs ist nss' out =
7777
7878-- ----------------------------------------------------------------- [ Types ]
7979
80+-- | Either an error message or a result
8081type Failable = Either String
82+
83+-- | Internal representation of a fully qualified namespace name
8184type NsName = [T.Text]
85+
86+-- | All information to be documented about a single namespace member
8287type NsItem = (Name, Maybe Docs, Accessibility)
88+
89+-- | All information to be documented about a namespace
8390type NsInfo = [NsItem]
91+
92+-- | A map from namespace names to information about them
8493type NsDict = M.Map NsName NsInfo
8594
8695-- --------------------------------------------------------------- [ Utility ]
@@ -133,10 +142,11 @@ fetchInfo :: IState -- ^ IState to fetch info from
133142fetchInfo ist nss =
134143 do let originNss = S.fromList nss
135144 info <- nsDict ist
136− let info' = M.map (filter (filterName . (\(n, _, _) -> n))) info
145+ let info' = M.map (filter filterInclude) info
137146 info'' = M.map removeOrphans info'
138− reachedNss = traceNss info'' originNss S.empty
139− return $ M.filterWithKey (\k _ -> S.member k reachedNss) info''
147+ info''' = M.filter (not . null) info''
148+ reachedNss = traceNss info''' originNss S.empty
149+ return $ M.filterWithKey (\k _ -> S.member k reachedNss) info'''
140150
141151
142152-- | Removes loose class methods and data constructors,
@@ -160,6 +170,16 @@ filterName (NS n _) = filterName n
160170filterName _ = False
161171
162172
173+-- | Whether a NsItem should be included in the documentation.
174+-- It must not be Hidden and filterName must return True for the name.
175+-- Also it must have Docs -- without Docs, nothing can be done.
176+filterInclude :: NsItem -- ^ Accessibility to check
177+ -> Bool -- ^ Predicate result
178+filterInclude (name, Just _, Public) | filterName name = True
179+filterInclude (name, Just _, Frozen) | filterName name = True
180+filterInclude _ = False
181+
182+
163183-- | Finds all namespaces indirectly referred by a set of namespaces.
164184-- The NsItems of the namespaces are searched for references.
165185traceNss :: NsDict -- ^ Mappings of namespaces and their contents
@@ -215,7 +235,7 @@ getAccess ist n =
215235 let res = lookupDefAcc n False (tt_ctxt ist)
216236 in case res of
217237 [(_, acc)] -> acc
218− _ -> Public
238+ _ -> Hidden
219239
220240-- | Simple predicate for whether an NsItem has Docs
221241hasDoc :: NsItem -- ^ The NsItem to test
@@ -403,19 +423,15 @@ createNsDoc ist ns content out =
403423 do let tpath = out </> "docs" </> (genRelNsPath ns "html")
404424 dir = takeDirectory tpath
405425 file = takeFileName tpath
406− visible (_, _, Hidden) = False
407− visible _ = True
408426 haveDocs (_, Just d, _) = [d]
409427 haveDocs _ = []
410− -- Do not document private members
411− content' = filter visible content
412428 -- We cannot do anything without a Doc
413− content'' = concatMap haveDocs content'
429+ content' = concatMap haveDocs content
414430 createDirectoryIfMissing True dir
415431 (path, h) <- openTempFile dir file
416432 BS2.hPut h $ renderHtml $ wrapper (Just ns) $ do
417433 H.h1 $ toHtml (nsName2Str ns)
418− H.dl ! class_ "decls" $ forM_ content'' (createOtherDoc ist)
434+ H.dl ! class_ "decls" $ forM_ content' (createOtherDoc ist)
419435 hClose h
420436 renameFile path tpath
421437
src/Idris/REPL.hs+4−2
@@ -1565,8 +1565,10 @@ getPkgCheck :: Opt -> Maybe String
15651565getPkgCheck (PkgCheck str) = Just str
15661566getPkgCheck _ = Nothing
15671567
1568−-- IdrisDoc
1569−getPkgMkDoc :: Opt -> Maybe String
1568+-- | Returns None if given an Opt which is not PkgMkDoc
1569+-- Otherwise returns Just x, where x is the contents of PkgMkDoc
1570+getPkgMkDoc :: Opt -- ^ Opt to extract
1571+ -> Maybe String -- ^ Result
15701572getPkgMkDoc (PkgMkDoc str) = Just str
15711573getPkgMkDoc _ = Nothing
15721574
test/idrisdoc001/TestPrivate.idrnew file+5
@@ -0,0 +1,5 @@
1+module TestPrivate
2+
3+private
4+iAmPrivate : ()
5+iAmPrivate = ()
test/idrisdoc001/expected+2
@@ -1,3 +1,5 @@
11Type checking ./TestEmpty.idr
2+Type checking ./TestPrivate.idr
23Warning: Ignoring empty or non-existing namespace 'TestEmpty'
4+Warning: Ignoring empty or non-existing namespace 'TestPrivate'
35No namespaces to generate documentation for
test/idrisdoc001/run+1−1
@@ -1,4 +1,4 @@
11#!/usr/bin/env bash
2−# Tests that no documentation is built for empty namespaces
2+# Tests that no documentation is built for empty and/or private-only namespaces
33idris --mkdoc test_empty.ipkg
44rm -rf *.ibc *_doc
test/idrisdoc001/test_empty.ipkg+1−1
@@ -1,4 +1,4 @@
11package test_empty
22
3−modules = TestEmpty
3+modules = TestEmpty, TestPrivate
44
test/idrisdoc006/A.idr → test/idrisdoc006/A/fully/Qualified/NAME.idrrenamed+1−1
@@ -1,4 +1,4 @@
1−module A
1+module A.fully.Qualified.NAME
22
33||| This is another test
44data Test : Type where
test/idrisdoc006/expected+6−5
@@ -1,6 +1,7 @@
1−Type checking ./A.idr
1+Type checking ./A/fully/Qualified/NAME.idr
2+IdrisDoc file written
23Type checking ./B.idr
3−A: Check
4−B: Check
5−A
6−B
4+A.fully.Qualified.NAME.html
5+B.html
6+A.fully.Qualified.NAME is in the index
7+B is in the index
test/idrisdoc006/package_a.ipkg+1−1
@@ -1,4 +1,4 @@
11package test_merge
22
3−modules = A
3+modules = A.fully.Qualified.NAME
44
test/idrisdoc006/run+9−9
@@ -1,17 +1,17 @@
11#!/usr/bin/env bash
2−# Tests that documentation properly is merged with existing
2+# Tests that documentation properly is merged with existent.
33idris --mkdoc package_a.ipkg
4+[ -f test_merge_doc/IdrisDoc ] && echo "IdrisDoc file written"
45idris --mkdoc package_b.ipkg
5−[ -f test_merge_doc/docs/A.html ] && echo "A: Check"
6−[ -f test_merge_doc/docs/B.html ] && echo "B: Check"
7−if grep -q "href\\=\"docs/A\\.html\"" test_merge_doc/index.html; then
8− echo A
6+ls -1p test_merge_doc/docs
7+if grep -q "href\\=\"docs/A.fully.Qualified.NAME\\.html\"" test_merge_doc/index.html; then
8+ echo A.fully.Qualified.NAME is in the index
99else
10− echo A is not in the index
10+ echo A.fully.Qualified.NAME is NOT in the index
1111fi
1212if grep -q "href\\=\"docs/B\\.html\"" test_merge_doc/index.html; then
13− echo B
13+ echo B is in the index
1414else
15− echo B is not in the index
15+ echo B is NOT in the index
1616fi
17−rm -rf *.ibc *_doc
17+rm -rf *.ibc *_doc A/fully/Qualified/NAME.ibc
test/idrisdoc008/Abstract.idrnew file+5
@@ -0,0 +1,5 @@
1+module Abstract
2+
3+abstract
4+frozen : ()
5+frozen = ()
test/idrisdoc008/Visible.idrnew file+5
@@ -0,0 +1,5 @@
1+module Visible
2+
3+public
4+visible : ()
5+visible = ()
test/idrisdoc008/expectednew file+4
@@ -0,0 +1,4 @@
1+Type checking ./Abstract.idr
2+Type checking ./Visible.idr
3+Abstract members are documented
4+Public members are documented
test/idrisdoc008/runnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env bash
2+# Tests that documentation is generated for both public and abstract members.
3+idris --mkdoc visibility.ipkg
4+[ -f visibility_doc/docs/Abstract.html ] && echo "Abstract members are documented"
5+[ -f visibility_doc/docs/Visible.html ] && echo "Public members are documented"
6+rm -rf *.ibc *_doc
test/idrisdoc008/visibility.ipkgnew file+4
@@ -0,0 +1,4 @@
1+package visibility
2+
3+modules = Abstract, Visible
4+