Skip to content

Commit cdb997b

Browse files
committed
Add a script to verify json syntax
This is a useful sanity check to have as we start adding shared test data.
1 parent 867a0be commit cdb997b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: bash
2+
3+
sudo: false
4+
5+
addons:
6+
apt:
7+
packages:
8+
- jq
9+
10+
script:
11+
- bin/jsonlint

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Please see the [contributing guide](https://github.com/exercism/x-api/blob/maste
99

1010
## Test Data Format
1111

12-
Each problem can have a file <problem>.json containing standard test data.
12+
Each problem can have a file <problem>.json containing standard test data.
1313
This data can be incoporated into test programs manually or extracted by a
1414
program. The file contains a single JSON object with a key for documentation
1515
and keys for various tests that may be meaningful for a problem.
@@ -24,7 +24,18 @@ Each test uses a key name representative of the test and an object as the
2424
value. This object has two keys, "Description" and "Cases". Description has
2525
a list of strings as its value. Cases has a list of objects as its value.
2626
Each case object represents a separate test case. A case object should have
27-
a description field and fields for inputs and outputs. A test case description should be a short phrase, suitable to be included in an error message.
27+
a description field and fields for inputs and outputs. A test case description
28+
should be a short phrase, suitable to be included in an error message.
29+
30+
## Automated Tests
31+
32+
The only thing that we're testing at the moment, is whether or not shared test data
33+
is valid json.
34+
35+
If you want to run this before you commit, you will need to install
36+
[jq](https://stedolan.github.io/jq/download/). Then run the script with:
37+
38+
bin/jsonlint
2839

2940
## License
3041

bin/jsonlint

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
STATUS=0
4+
for f in $(ls *.json); do
5+
cat $f | jq . > /dev/null 2>&1
6+
if [ $? != 0 ]; then
7+
echo "Invalid json: $f"
8+
STATUS=1
9+
fi
10+
done
11+
exit $STATUS

0 commit comments

Comments
 (0)