Skip to content

Commit 9f0f94d

Browse files
committed
Generate a Summary-TestFile, that calls all others
1 parent 39c216f commit 9f0f94d

File tree

13 files changed

+89
-103
lines changed

13 files changed

+89
-103
lines changed

app/Main.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Control.Monad.Writer
1010
import Data.Maybe (fromMaybe)
1111
import qualified Data.Text as T
1212
import Debug.Pretty.Simple
13+
import Text.Pretty.Simple
1314
import qualified Language.PureScript as P
1415
import qualified Language.PureScript.Docs as D
1516
import Language.PureScript.Docs.Tags (dumpCtags, dumpEtags)
@@ -73,7 +74,9 @@ docgen p@(PurepurOptions moutput compileOutput inputGlob compileInputGlob) = do
7374
globDir1 ext output >>= mapM_ removeFile
7475
writeTestModules output msCommentTest
7576
writeTestModules output $ (\(doc, name) -> (name, Printer.printPurpurDocument name doc)) <$> testsFromMarkdown
76-
77+
let (summaryDoc, summaryModName) = generateSummaryFile ((fst <$> msCommentTest) ++ (snd <$> testsFromMarkdown))
78+
-- pPrint summaryFile
79+
writeTestModule output (summaryModName, Printer.printPurpurDocument summaryModName summaryDoc)
7780
pure ()
7881
where
7982
runExceptIO :: Except ParseError a -> IO a
@@ -114,8 +117,8 @@ main = do
114117
opts =
115118
Opts.info
116119
command
117-
( Opts.progDesc "Print a greeting for TARGET"
118-
<> Opts.header "hello - a test for optparse-applicative"
120+
( Opts.progDesc "Generate tests from code-examples in purescript docs"
121+
<> Opts.header "purescript-doctest"
119122
)
120123

121124
pscDocsOptions :: Opts.Parser PurepurOptions

example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
```purescript run
55
> f x = x
6+
> f 2
7+
2
68
```

example/test/Main.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import Prelude
44
import Test.Spec (describe, it)
55
import Test.Spec.Assertions (shouldEqual)
66

7-
import Test.Example.Main as Main
8-
import Test.Example.ArrayEx as ArrayEx
7+
-- import Test.Example.Main as Main
8+
import DocTest as DocTest
99
import Effect (Effect)
1010
import Effect.Aff (launchAff_)
1111
import Test.Spec.Reporter.Console (consoleReporter)
1212
import Test.Spec.Runner (runSpec)
1313

1414
-- Specs
1515
main = launchAff_ $ runSpec [consoleReporter] do
16-
Main.main
17-
ArrayEx.main
16+
-- Main.main
17+
-- ArrayEx.main
18+
DocTest.main
1819
pure unit

example/test/docs/ArrayEx.purs

Lines changed: 0 additions & 32 deletions
This file was deleted.

example/test/docs/DocTest.purs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module DocTest where
2+
3+
import Prelude
4+
import Test.Spec (describe, it, Spec)
5+
import Test.Spec.Assertions (shouldEqual)
6+
7+
8+
-- Imports
9+
import Test.DocTest.ArrayEx as Test.DocTest.ArrayEx
10+
import Test.DocTest.Main as Test.DocTest.Main
11+
import Test.DocTest.Sub.Sub1 as Test.DocTest.Sub.Sub1
12+
import Test.MarkdownExamples.READMEmd as Test.MarkdownExamples.READMEmd
13+
14+
15+
-- Declarations
16+
17+
18+
-- Specs
19+
main :: Spec Unit
20+
main = describe "DocTest" $ do
21+
Test.DocTest.ArrayEx.main
22+
Test.DocTest.Main.main
23+
Test.DocTest.Sub.Sub1.main
24+
Test.MarkdownExamples.READMEmd.main
25+
26+
pure unit

example/test/docs/Main.purs

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/test-docs/ArrayEx.purs renamed to example/test/docs/Test.DocTest.ArrayEx.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Test.Example.ArrayEx where
1+
module Test.DocTest.ArrayEx where
22

33
import Prelude
44
import Test.Spec (describe, it, Spec)
@@ -17,16 +17,16 @@ asMaybeInt a = a
1717

1818
-- Specs
1919
main :: Spec Unit
20-
main = describe "ArrayEx" $ do
21-
it "value spec in docs from:main" $ show (fromFoldable (Just 1)) `shouldEqual` "[1]"
22-
it "value spec in docs from:main" $ show (fromFoldable (Nothing :: Maybe Int)) `shouldEqual` "[]"
20+
main = describe "Test.DocTest.ArrayEx" $ do
21+
it "value spec in docs from: main" $ show (fromFoldable (Just 1)) `shouldEqual` "[1]"
22+
it "value spec in docs from: main" $ show (fromFoldable (Nothing :: Maybe Int)) `shouldEqual` "[]"
2323
it "type spec in docs from: main" $ do
2424
let testType = (
2525
[ [ 1
2626
]
2727
]) :: (Array (Array Int))
2828
pure unit
2929

30-
it "value spec in docs from:main" $ show (singleton 2) `shouldEqual` "[2]"
30+
it "value spec in docs from: main" $ show (singleton 2) `shouldEqual` "[2]"
3131

3232
pure unit

example/test-docs/Main.purs renamed to example/test/docs/Test.DocTest.Main.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Test.Example.Main where
1+
module Test.DocTest.Main where
22

33
import Prelude
44
import Test.Spec (describe, it, Spec)
@@ -18,13 +18,13 @@ f x = 28
1818

1919
-- Specs
2020
main :: Spec Unit
21-
main = describe "Main" $ do
22-
it "value spec in docs from:main" $ show (101 + 2 * (\x ->
21+
main = describe "Test.DocTest.Main" $ do
22+
it "value spec in docs from: main" $ show (101 + 2 * (\x ->
2323
x
2424
)
2525
3) `shouldEqual` "107"
26-
it "value spec in docs from:main" $ show (23) `shouldEqual` "23"
27-
it "value spec in docs from:main" $ show (f 1) `shouldEqual` "3"
28-
it "value spec in docs from:main" $ show (f 23) `shouldEqual` "28"
26+
it "value spec in docs from: main" $ show (23) `shouldEqual` "23"
27+
it "value spec in docs from: main" $ show (f 1) `shouldEqual` "3"
28+
it "value spec in docs from: main" $ show (f 23) `shouldEqual` "28"
2929

3030
pure unit

example/test-docs/Sub.Sub1.purs renamed to example/test/docs/Test.DocTest.Sub.Sub1.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Test.Example.Sub.Sub1 where
1+
module Test.DocTest.Sub.Sub1 where
22

33
import Prelude
44
import Test.Spec (describe, it, Spec)
@@ -13,6 +13,6 @@ import Test.Spec.Assertions (shouldEqual)
1313

1414
-- Specs
1515
main :: Spec Unit
16-
main = describe "Sub.Sub1" $ do
16+
main = describe "Test.DocTest.Sub.Sub1" $ do
1717

1818
pure unit

example/test-docs/Test.MdExamples.READMEmd.purs renamed to example/test/docs/Test.MarkdownExamples.READMEmd.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Test.Example.Test.MdExamples.READMEmd where
1+
module Test.MarkdownExamples.READMEmd where
22

33
import Prelude
44
import Test.Spec (describe, it, Spec)
@@ -14,6 +14,7 @@ f x = x
1414

1515
-- Specs
1616
main :: Spec Unit
17-
main = describe "Test.MdExamples.READMEmd" $ do
17+
main = describe "Test.MarkdownExamples.READMEmd" $ do
18+
it "value spec in docs from: ./README.md" $ show (f 2) `shouldEqual` "2"
1819

1920
pure unit

0 commit comments

Comments
 (0)