Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit d27e6fd

Browse files
author
Marko Mikulicic
authored
Merge pull request #6 from glyn/dev-guide
Add developer guide
2 parents ebc5f21 + fcfc9f4 commit d27e6fd

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ git commit -a
2323
git push origin my-new-feature
2424
```
2525

26+
See the [Developer Guide](./DEVELOPING.md) for how to set up a development environment and run the tests.
27+
If you want to make a small change, e.g. to fix a typo, you don't have to set up a development environment
28+
as the tests will run automatically against any pull request.
29+
2630
### Staying In Sync With Upstream
2731

2832
When your branch gets out of sync with the jsonpath-standard/jsonpath-reference-implementation/main branch, use the following to update:

DEVELOPING.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
```

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
**WORK IN PROGRESS**
44

5-
See [cts.json](tests/cts.json) for the Compliance Test Suite and [grammar.pest](src/grammar.pest) for the Parsing Expression Grammar of the Reference Implementation.
5+
This Reference Implementation follows, and usually lags behind, the [internet draft](https://jsonpath-standard.github.io/internet-draft/).
6+
7+
See [cts.json](tests/cts.json) for the Compliance Test Suite and [grammar.pest](src/grammar.pest) for the Parsing Expression Grammar of the Reference Implementation.
8+
9+
See the [Developer Guide](./DEVELOPING.md) if you want to run the code against the test suite. See the [Contributor Guide](./CONTRIBUTING.md) if you'd like to submit changes.

tests/cts.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ mod tests {
1111
use std::fs;
1212
use std::panic;
1313

14-
const VERBOSE: bool = false;
15-
1614
#[derive(Debug, PartialEq, Serialize, Deserialize)]
1715
struct TestSuite {
1816
tests: Vec<Testcase>,
@@ -51,9 +49,14 @@ mod tests {
5149
continue;
5250
}
5351
let result = panic::catch_unwind(|| {
54-
if VERBOSE {
52+
if t.invalid_selector {
53+
println!(
54+
"testcase name = `{}`, selector = `{}`, expected invalid selector.",
55+
t.name, t.selector
56+
);
57+
} else {
5558
println!(
56-
"name = {}, selector = {}, document = {:?}, result = {:?}",
59+
"testcase name = `{}`, selector = `{}`, document:\n{:#}\nexpected result = `{}`.",
5760
t.name, t.selector, t.document, t.result
5861
);
5962
}

0 commit comments

Comments
 (0)