Skip to content

Add tests leveraging the existing documentation #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
container_image: ["fedora:latest", "ubuntu:latest"]
compiler: [g++, clang++]
optflag: ["-O0", "-O2"]
memcheck: [off, asan, valgrind]
container:
image: ${{ matrix.container_image }}

steps:
- uses: actions/checkout@v1
- name: install dependencies (Fedora)
if: ${{ matrix.container_image == 'fedora:latest' }}
run: dnf -y install clang gcc-c++ valgrind libasan libubsan jq
- name: install dependencies (Ubuntu)
if: ${{ matrix.container_image == 'ubuntu:latest' }}
run: |
apt-get -y update
apt-get -y install bash clang g++ valgrind libasan5 libubsan1 jq
- name: build and test
shell: bash
run: |
export CXX=${{ matrix.compiler }}
export CXXFLAGS="-std=gnu++14 -g -pthread -lpthread ${{ matrix.optflag }} -Wall -Wextra"
export TESTFLAG=""
if [[ "${{ matrix.memcheck }}" = "asan" ]]; then
export CXXFLAGS="${CXXFLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer"
if [[ "${{ matrix.compiler }}" = "g++" ]]; then
export CXXFLAGS="${CXXFLAGS} -fno-sanitize-recover"
else
export CXXFLAGS="${CXXFLAGS} -fno-sanitize-recover=all"
fi
elif [[ "${{ matrix.memcheck }}" = "valgrind" ]]; then
export TESTFLAG="--valgrind"
fi
${{ matrix.compiler }} -o jtc $CXXFLAGS jtc.cpp
python3 run_tests.py -v $TESTFLAG User\ Guide.md Walk-path\ tutorial.md README.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jtc
file.json
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ Enabling too many debugs might be overwhelming, though one specific case many wo
a failing JSON:
```bash
bash $ <addressbook-sample.json jtc
jtc json exception: expected_json_value
jtc json parsing exception (<stdin>:263): expected_json_value
```
If JSON is big, it's desirable to locate the parsing failure point. Passing just one `-d` let easily spotting the
parsing failure point and its locus:
```bash
bash $ <addressbook-sample.json jtc -d
.display_opts(), option set[0]: -d (internally imposed: )
.init_inputs(), reading json from <stdin>
.exception_locus_(), ... }| ],| "children": [,],| "spouse": null| },| {| ...
.exception_spot_(), -------------------------------------------->| (offset: 967)
jtc json parsing exception (<stdin>:967): expected_json_value
.exception_locus_(), ... "age": 31,| "children": [,],| "phoneNumbers": [| ...
.exception_spot_(), --------------------------------------->| (offset: 263)
jtc json parsing exception (<stdin>:263): expected_json_value
bash $
```

Expand Down Expand Up @@ -442,7 +442,7 @@ bash $ <<<$case3 jtc -w'<Name>l:<N>v[-1]' -rT'[{{$a}},{{$b}}]'
[ "Patrick", "Lynch" ]
[ "Alice", "Price" ]
[ "Rebecca", "Hernandez" ]

#
#jq:
bash $ <<<$case3 jq -c 'if type == "array" then .[] else . end | [.Name, .Surname]'
[null,null]
Expand All @@ -455,7 +455,7 @@ bash $ case2='[{"Surname":"Lynch", "gender":"male", "age":29},{"Name":"Alice", "
bash $
bash $ <<<$case2 jtc -w'<Name>l:<N>v[-1]' -rT'[{{$a}},{{$b}}]'
[ "Alice", "Price" ]

#
#jq:
bash $ <<<$case2 jq -c 'if type == "array" then .[] else . end | [.Name, .Surname]'
[null,"Lynch"]
Expand Down Expand Up @@ -528,7 +528,7 @@ _**`updating JSON recursively by label:`**_ | _**`updating JSON recursively by l


**_Comparison of `jtc` to `jtc` (single-threaded to multi-threaded parsing performance):_**
```bash
```bash SKIP
bash $ unset TIMEFORMAT
bash $
bash $ # concurrent (multi-threaded) parsing:
Expand Down
Loading