Skip to content

Commit ad75824

Browse files
committed
README
1 parent 8477ea1 commit ad75824

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

README.md

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
11
Purepur
22
=======
33

4+
Generate tests from examples in your purescript-docs.
5+
6+
Given:
7+
```purescript
8+
module Data.Array exposing …
9+
10+
-- | Convert a `Foldable` structure into an `Array`.
11+
-- |
12+
-- | ```purescript run
13+
-- | > fromFoldable (Just 1)
14+
-- | [1]
15+
-- | ```
16+
-- |
17+
fromFoldable :: forall f. Foldable f => f ~> Array
18+
fromFoldable = fromFoldableImpl foldr
19+
```
20+
purepur will generate:
21+
```purescript
22+
module Test.Example.Data.Array where
23+
24+
25+
26+
main :: Spec Unit
27+
main = describe "ArrayEx" $ do
28+
it "value spec in docs from:fromFoldable" $ show (fromFoldable (Just 1)) `shouldEqual` "[1]"
29+
```
30+
31+
Usage
32+
------
33+
34+
For purepur to recognize an example as a test, add ` ```purescript run` to a comment in your purescript code, like shown here https://github.com/csicar/purescript-purepur/blob/master/example/src/ArrayEx.purs#L11.
35+
The syntax of the code-fence is identical to that of PSCI. This means that copying the terminal output from PSCI to a docs comment _should_ directly work.
36+
37+
Now generate the test-files:
38+
39+
`purepure -o test/docs --src "src/**/*.purs" (spago sources)`
40+
41+
- `-o` specifies the directory, where the test-files should be written to
42+
- `--src` specified the glob, for which tests should be generated.
43+
44+
Now `test/docs` should look similar to this: https://github.com/csicar/purescript-purepur/blob/master/example/test/docs
45+
46+
Building
47+
--------
48+
449
```bash
5-
stack run -- -o test/docs --src "src/**/*.purs" (spago sources)
50+
git clone …
51+
cd
52+
stack install
653
```
754

8-
Code-Generation
55+
Testing
956
-----
1057

11-
- `imports` go to the top
12-
- `declarations` go right after the imports (in the same order as in the file)
13-
- `expected outputs` refer to the psci command directly before it
58+
run in `example`
59+
60+
```bash
61+
stack run -- -o test/docs --src "src/**/*.purs" (spago sources)
62+
```
63+
64+
65+
The project is forked from https://github.com/andyarvanitis/purescript-native

0 commit comments

Comments
 (0)