Skip to content

Commit

Permalink
Update tests to include jsoncpp trait (#320)
Browse files Browse the repository at this point in the history
* update tests to run jsoncpp

* fix order for type checking

Co-authored-by: cjserio <[email protected]>

* linter should be more specific on on default for trait

* fix linter

* output folder name

* use filepath for linter processing

---------

Co-authored-by: cjserio <[email protected]>
  • Loading branch information
prince-chrismc and cjserio authored Dec 21, 2023
1 parent 65cda08 commit ed98dc1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
12 changes: 11 additions & 1 deletion .github/actions/render/defaults/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: "Set the macro to disable the default traits"
required: false
default: "true"
outputs:
file_path:
description: "Relative path which the 'defaults.h' was written to"
value: ${{ steps.script.outputs.result }}
runs:
using: composite
steps:
Expand All @@ -23,12 +27,14 @@ runs:
- run: npm install mustache
shell: bash
- uses: actions/github-script@v6
id: script
env:
TRAITS_NAME: ${{ inputs.traits_name }}
LIBRARY_NAME: ${{ inputs.library_name }}
LIBRARY_URL: ${{ inputs.library_url }}
DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }}
with:
result-encoding: string
script: |
const mustache = require('mustache')
const path = require('path')
Expand All @@ -54,4 +60,8 @@ runs:
const outputDir = path.join('include', 'jwt-cpp', 'traits', replaceAll(TRAITS_NAME, '_', '-'))
fs.mkdirSync(outputDir, { recursive: true })
fs.writeFileSync(path.join(outputDir, 'defaults.h'), content)
const filePath = path.join(outputDir, 'defaults.h')
fs.writeFileSync(filePath, content)
return filePath
7 changes: 6 additions & 1 deletion .github/actions/render/tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ runs:
const { TRAITS_NAME, SUITE_NAME } = process.env
console.log(`Rendering ${TRAITS_NAME}!`)
// https://dmitripavlutin.com/replace-all-string-occurrences-javascript/
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
const template = fs.readFileSync(path.join('tests', 'traits', 'TraitsTest.cpp.mustache'), 'utf8')
const content = mustache.render(template, {
traits_name: TRAITS_NAME,
traits_dir: TRAITS_NAME.replace('_', '-'),
traits_dir: replaceAll(TRAITS_NAME, '_', '-'),
test_suite_name: SUITE_NAME,
})
const outputDir = path.join('tests', 'traits')
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/jwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- uses: ./.github/actions/install/gtest
- uses: ./.github/actions/install/danielaparker-jsoncons
- uses: ./.github/actions/install/boost-json
- uses: ./.github/actions/install/open-source-parsers-jsoncpp

- name: configure
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/render/defaults
id: render
with:
traits_name: ${{ matrix.traits.name }}
library_name: ${{ matrix.traits.library }}
library_url: ${{ matrix.traits.url }}
disable_default_traits: ${{ matrix.traits.disable_pico }}
- run: clang-format -i include/jwt-cpp/traits/**/*.h
- run: git add include/jwt-cpp/traits/*
- run: clang-format -i ${{ steps.render.outputs.file_path }}
- run: git add ${{ steps.render.outputs.file_path }}
- uses: ./.github/actions/process-linting-results
with:
linter_name: render-defaults
Expand Down
5 changes: 3 additions & 2 deletions include/jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ namespace jwt {
return type::array;
else if (val.isString())
return type::string;
else if (val.isNumeric())
return type::number;
// Order is important https://github.com/Thalhammer/jwt-cpp/pull/320#issuecomment-1865322511
else if (val.isInt())
return type::integer;
else if (val.isNumeric())
return type::number;
else if (val.isBool())
return type::boolean;
else if (val.isObject())
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ else()
if(TARGET boost_json)
target_link_libraries(jwt-cpp-test PRIVATE boost_json)
endif()
if(TARGET jsoncpp_static)
target_link_libraries(jwt-cpp-test PRIVATE jsoncpp_static)
endif()
endif()
target_link_libraries(jwt-cpp-test PRIVATE jwt-cpp nlohmann_json::nlohmann_json
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${CMAKE_DL_LIBS}>)
Expand Down
2 changes: 1 addition & 1 deletion tests/traits/OspJsoncppTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "jwt-cpp/traits/open-source_parsers_jsoncpp/traits.h"
#include "jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h"

#include <gtest/gtest.h>

Expand Down

0 comments on commit ed98dc1

Please sign in to comment.