Skip to content

Commit ed98dc1

Browse files
Update tests to include jsoncpp trait (Thalhammer#320)
* update tests to run jsoncpp * fix order for type checking Co-authored-by: cjserio <cjserio@users.noreply.github.com> * linter should be more specific on on default for trait * fix linter * output folder name * use filepath for linter processing --------- Co-authored-by: cjserio <cjserio@users.noreply.github.com>
1 parent 65cda08 commit ed98dc1

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

.github/actions/render/defaults/action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: "Set the macro to disable the default traits"
1515
required: false
1616
default: "true"
17+
outputs:
18+
file_path:
19+
description: "Relative path which the 'defaults.h' was written to"
20+
value: ${{ steps.script.outputs.result }}
1721
runs:
1822
using: composite
1923
steps:
@@ -23,12 +27,14 @@ runs:
2327
- run: npm install mustache
2428
shell: bash
2529
- uses: actions/github-script@v6
30+
id: script
2631
env:
2732
TRAITS_NAME: ${{ inputs.traits_name }}
2833
LIBRARY_NAME: ${{ inputs.library_name }}
2934
LIBRARY_URL: ${{ inputs.library_url }}
3035
DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }}
3136
with:
37+
result-encoding: string
3238
script: |
3339
const mustache = require('mustache')
3440
const path = require('path')
@@ -54,4 +60,8 @@ runs:
5460
5561
const outputDir = path.join('include', 'jwt-cpp', 'traits', replaceAll(TRAITS_NAME, '_', '-'))
5662
fs.mkdirSync(outputDir, { recursive: true })
57-
fs.writeFileSync(path.join(outputDir, 'defaults.h'), content)
63+
64+
const filePath = path.join(outputDir, 'defaults.h')
65+
fs.writeFileSync(filePath, content)
66+
67+
return filePath

.github/actions/render/tests/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ runs:
2828
const { TRAITS_NAME, SUITE_NAME } = process.env
2929
console.log(`Rendering ${TRAITS_NAME}!`)
3030
31+
// https://dmitripavlutin.com/replace-all-string-occurrences-javascript/
32+
function replaceAll(string, search, replace) {
33+
return string.split(search).join(replace);
34+
}
35+
3136
const template = fs.readFileSync(path.join('tests', 'traits', 'TraitsTest.cpp.mustache'), 'utf8')
3237
const content = mustache.render(template, {
3338
traits_name: TRAITS_NAME,
34-
traits_dir: TRAITS_NAME.replace('_', '-'),
39+
traits_dir: replaceAll(TRAITS_NAME, '_', '-'),
3540
test_suite_name: SUITE_NAME,
3641
})
3742
const outputDir = path.join('tests', 'traits')

.github/workflows/jwt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- uses: ./.github/actions/install/gtest
1616
- uses: ./.github/actions/install/danielaparker-jsoncons
1717
- uses: ./.github/actions/install/boost-json
18+
- uses: ./.github/actions/install/open-source-parsers-jsoncpp
1819

1920
- name: configure
2021
run: |

.github/workflows/lint.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ jobs:
8080
steps:
8181
- uses: actions/checkout@v3
8282
- uses: ./.github/actions/render/defaults
83+
id: render
8384
with:
8485
traits_name: ${{ matrix.traits.name }}
8586
library_name: ${{ matrix.traits.library }}
8687
library_url: ${{ matrix.traits.url }}
8788
disable_default_traits: ${{ matrix.traits.disable_pico }}
88-
- run: clang-format -i include/jwt-cpp/traits/**/*.h
89-
- run: git add include/jwt-cpp/traits/*
89+
- run: clang-format -i ${{ steps.render.outputs.file_path }}
90+
- run: git add ${{ steps.render.outputs.file_path }}
9091
- uses: ./.github/actions/process-linting-results
9192
with:
9293
linter_name: render-defaults

include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ namespace jwt {
6666
return type::array;
6767
else if (val.isString())
6868
return type::string;
69-
else if (val.isNumeric())
70-
return type::number;
69+
// Order is important https://github.com/Thalhammer/jwt-cpp/pull/320#issuecomment-1865322511
7170
else if (val.isInt())
7271
return type::integer;
72+
else if (val.isNumeric())
73+
return type::number;
7374
else if (val.isBool())
7475
return type::boolean;
7576
else if (val.isObject())

tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ else()
6767
if(TARGET boost_json)
6868
target_link_libraries(jwt-cpp-test PRIVATE boost_json)
6969
endif()
70+
if(TARGET jsoncpp_static)
71+
target_link_libraries(jwt-cpp-test PRIVATE jsoncpp_static)
72+
endif()
7073
endif()
7174
target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp nlohmann_json::nlohmann_json
7275
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${CMAKE_DL_LIBS}>)

tests/traits/OspJsoncppTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "jwt-cpp/traits/open-source_parsers_jsoncpp/traits.h"
1+
#include "jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h"
22

33
#include <gtest/gtest.h>
44

0 commit comments

Comments
 (0)