|
| 1 | +# Developing jsonpath-reference-implementation |
| 2 | + |
| 3 | +This guide describes how to set up a development environment and run the tests. |
| 4 | +If you'd like to submit changes, see the [Contributor Guide](./CONTRIBUTING.md). |
| 5 | + |
| 6 | +## Setting up a development environment |
| 7 | + |
| 8 | +The reference implementation is written in [Rust](https://www.rust-lang.org/). |
| 9 | + |
| 10 | +### Installing Rust |
| 11 | + |
| 12 | +Install the latest stable version of Rust by following [these instructions](https://rustup.rs/). |
| 13 | +This will also install [Cargo](https://doc.rust-lang.org/book/ch01-03-hello-cargo.html) which is Rust's |
| 14 | +build system and package manager. |
| 15 | + |
| 16 | +If you are new to Rust, check out the resources at [Learn Rust](https://www.rust-lang.org/learn). |
| 17 | + |
| 18 | +## Running the Compliance Test Suite |
| 19 | + |
| 20 | +Once Rust is installed, run the Compliance Test Suite on the command line by changing directory to |
| 21 | +a clone of this repository and issuing: |
| 22 | +``` |
| 23 | +cargo test |
| 24 | +``` |
| 25 | + |
| 26 | +If all goes well, the output should include this: |
| 27 | +``` |
| 28 | +... |
| 29 | +test tests::compliance_test_suite ... ok |
| 30 | +
|
| 31 | +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out |
| 32 | +... |
| 33 | +``` |
| 34 | + |
| 35 | +## Debugging test failures |
| 36 | + |
| 37 | +To run a test on its own, edit [cts.json](tests/cts.json) and set the `focus` property of the relevant |
| 38 | +test to `true`, for example: |
| 39 | +<pre> |
| 40 | + }, { |
| 41 | + "name": "wildcarded child", |
| 42 | + <b>"focus": true,</b> |
| 43 | + "selector": "$.*", |
| 44 | + "document": {"a" : "A", "b" : "B"}, |
| 45 | + "result": ["A", "B"] |
| 46 | + }, { |
| 47 | +</pre> |
| 48 | + |
| 49 | +When one or more tests are focussed in this way, the test suite will fail with the message |
| 50 | +"testcase(s) still focussed" even if all the tests pass. |
| 51 | +This prevents pull requests being merged in which tests are accidentally left focussed. |
| 52 | + |
| 53 | +To see details of which tests run, use: |
| 54 | +``` |
| 55 | +cargo test -- --show-output |
| 56 | +``` |
| 57 | + |
| 58 | +If you want a bit more detail of what Cargo is doing, use: |
| 59 | +``` |
| 60 | +cargo test -v |
| 61 | +``` |
| 62 | + |
| 63 | +## Editing |
| 64 | + |
| 65 | +First class Rust support is available in various editors. See [Rust Tools](https://www.rust-lang.org/tools) |
| 66 | +for details. |
| 67 | + |
| 68 | +## Code formatting and linting |
| 69 | + |
| 70 | +To format the code, issue: |
| 71 | +``` |
| 72 | +cargo fmt |
| 73 | +``` |
| 74 | + |
| 75 | +To check the code for stylistic and other problems (known as "linting"), issue: |
| 76 | +``` |
| 77 | +cargo clippy |
| 78 | +``` |
| 79 | + |
| 80 | +The following one-liner formats/lints the code and, if that was successful, runs the tests: |
| 81 | +``` |
| 82 | +cargo fmt && cargo clippy && cargo test |
| 83 | +``` |
| 84 | + |
| 85 | +## Generating the docs |
| 86 | + |
| 87 | +To generate and view the docs, issue: |
| 88 | +``` |
| 89 | +cargo doc --document-private-items --open |
| 90 | +``` |
0 commit comments