|
1 | 1 | Purepur |
2 | 2 | ======= |
3 | 3 |
|
| 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 | + |
4 | 49 | ```bash |
5 | | -stack run -- -o test/docs --src "src/**/*.purs" (spago sources) |
| 50 | +git clone … |
| 51 | +cd … |
| 52 | +stack install |
6 | 53 | ``` |
7 | 54 |
|
8 | | -Code-Generation |
| 55 | +Testing |
9 | 56 | ----- |
10 | 57 |
|
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