Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
csicar committed May 5, 2020
1 parent 8477ea1 commit ad75824
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,65 @@
Purepur
=======

Generate tests from examples in your purescript-docs.

Given:
```purescript
module Data.Array exposing …
-- | Convert a `Foldable` structure into an `Array`.
-- |
-- | ```purescript run
-- | > fromFoldable (Just 1)
-- | [1]
-- | ```
-- |
fromFoldable :: forall f. Foldable f => f ~> Array
fromFoldable = fromFoldableImpl foldr
```
purepur will generate:
```purescript
module Test.Example.Data.Array where
main :: Spec Unit
main = describe "ArrayEx" $ do
it "value spec in docs from:fromFoldable" $ show (fromFoldable (Just 1)) `shouldEqual` "[1]"
```

Usage
------

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.
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.

Now generate the test-files:

`purepure -o test/docs --src "src/**/*.purs" (spago sources)`

- `-o` specifies the directory, where the test-files should be written to
- `--src` specified the glob, for which tests should be generated.

Now `test/docs` should look similar to this: https://github.com/csicar/purescript-purepur/blob/master/example/test/docs

Building
--------

```bash
stack run -- -o test/docs --src "src/**/*.purs" (spago sources)
git clone …
cd
stack install
```

Code-Generation
Testing
-----

- `imports` go to the top
- `declarations` go right after the imports (in the same order as in the file)
- `expected outputs` refer to the psci command directly before it
run in `example`

```bash
stack run -- -o test/docs --src "src/**/*.purs" (spago sources)
```


The project is forked from https://github.com/andyarvanitis/purescript-native

0 comments on commit ad75824

Please sign in to comment.