mirror of
https://github.com/allankoechke/jwt-cpp.git
synced 2026-11-30 10:18:40 +00:00
Update tests to include jsoncpp trait (#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>
This commit is contained in:
12
.github/actions/render/defaults/action.yml
vendored
12
.github/actions/render/defaults/action.yml
vendored
@@ -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:
|
||||
@@ -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')
|
||||
@@ -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
.github/actions/render/tests/action.yml
vendored
7
.github/actions/render/tests/action.yml
vendored
@@ -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')
|
||||
|
||||
1
.github/workflows/jwt.yml
vendored
1
.github/workflows/jwt.yml
vendored
@@ -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: |
|
||||
|
||||
5
.github/workflows/lint.yml
vendored
5
.github/workflows/lint.yml
vendored
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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}>)
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user