24 changed files with 418 additions and 78 deletions
-
2thirdparty/argparse/.clang-tidy
-
42thirdparty/argparse/.github/workflows/tidy-analysis-stage-01.yml
-
86thirdparty/argparse/.github/workflows/tidy-analysis-stage-02.yml
-
20thirdparty/argparse/CMakeLists.txt
-
66thirdparty/argparse/README.md
-
117thirdparty/argparse/include/argparse/argparse.hpp
-
2thirdparty/argparse/samples/compound_arguments.cpp
-
2thirdparty/argparse/samples/custom_assignment_characters.cpp
-
2thirdparty/argparse/samples/custom_prefix_characters.cpp
-
2thirdparty/argparse/samples/gathering_remaining_arguments.cpp
-
2thirdparty/argparse/samples/is_used.cpp
-
2thirdparty/argparse/samples/joining_repeated_optional_arguments.cpp
-
2thirdparty/argparse/samples/list_of_arguments.cpp
-
2thirdparty/argparse/samples/negative_numbers.cpp
-
2thirdparty/argparse/samples/optional_flag_argument.cpp
-
2thirdparty/argparse/samples/positional_argument.cpp
-
2thirdparty/argparse/samples/required_optional_argument.cpp
-
2thirdparty/argparse/samples/subcommands.cpp
-
2thirdparty/argparse/test/CMakeLists.txt
-
52thirdparty/argparse/test/test_as_container.cpp
-
12thirdparty/argparse/test/test_default_args.cpp
-
21thirdparty/argparse/test/test_default_value.cpp
-
7thirdparty/argparse/test/test_get.cpp
-
45thirdparty/argparse/test/test_help.cpp
@ -0,0 +1,42 @@ |
|||
# Insecure workflow with limited permissions that should provide analysis |
|||
# results through an artifact. |
|||
name: Tidy analysis |
|||
|
|||
on: pull_request |
|||
|
|||
jobs: |
|||
|
|||
clang-tidy: |
|||
|
|||
runs-on: ubuntu-20.04 |
|||
|
|||
steps: |
|||
|
|||
- uses: actions/checkout@v3 |
|||
with: |
|||
fetch-depth: 2 |
|||
|
|||
- name: Install clang-tidy |
|||
run: | |
|||
sudo apt-get update |
|||
sudo apt-get install -y clang-tidy-12 |
|||
|
|||
- name: Prepare compile_commands.json |
|||
run: cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
|||
|
|||
- name: Create results directory |
|||
run: mkdir clang-tidy-result |
|||
|
|||
- name: Analyze |
|||
run: git diff -U0 HEAD^ | clang-tidy-diff-12.py -p1 -regex ".+hpp" -extra-arg=-Iinclude -extra-arg=-std=c++17 -export-fixes clang-tidy-result/fixes.yml |
|||
|
|||
- name: Save PR metadata |
|||
run: | |
|||
echo ${{ github.event.number }} > clang-tidy-result/pr-id.txt |
|||
echo ${{ github.event.pull_request.head.repo.full_name }} > clang-tidy-result/pr-head-repo.txt |
|||
echo ${{ github.event.pull_request.head.ref }} > clang-tidy-result/pr-head-ref.txt |
|||
|
|||
- uses: actions/upload-artifact@v2 |
|||
with: |
|||
name: clang-tidy-result |
|||
path: clang-tidy-result/ |
@ -0,0 +1,86 @@ |
|||
# Secure workflow with access to repository secrets and GitHub token |
|||
# for posting analysis results. |
|||
name: Post the Tidy analysis results |
|||
|
|||
on: |
|||
workflow_run: |
|||
workflows: [ "Tidy analysis" ] |
|||
types: [ completed ] |
|||
|
|||
jobs: |
|||
|
|||
clang-tidy-results: |
|||
|
|||
# Trigger the job only if the previous (insecure) workflow completed successfully |
|||
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} |
|||
runs-on: ubuntu-20.04 |
|||
|
|||
steps: |
|||
|
|||
- name: Download analysis results |
|||
uses: actions/github-script@v3.1.0 |
|||
with: |
|||
script: | |
|||
let artifacts = await github.actions.listWorkflowRunArtifacts({ |
|||
owner: context.repo.owner, |
|||
repo: context.repo.repo, |
|||
run_id: ${{github.event.workflow_run.id }}, |
|||
}); |
|||
let matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
|||
return artifact.name == "clang-tidy-result" |
|||
})[0]; |
|||
let download = await github.actions.downloadArtifact({ |
|||
owner: context.repo.owner, |
|||
repo: context.repo.repo, |
|||
artifact_id: matchArtifact.id, |
|||
archive_format: "zip", |
|||
}); |
|||
let fs = require("fs"); |
|||
fs.writeFileSync("${{github.workspace}}/clang-tidy-result.zip", Buffer.from(download.data)); |
|||
|
|||
- name: Set environment variables |
|||
run: | |
|||
mkdir clang-tidy-result |
|||
unzip clang-tidy-result.zip -d clang-tidy-result |
|||
echo "pr_id=$(cat clang-tidy-result/pr-id.txt)" >> $GITHUB_ENV |
|||
echo "pr_head_repo=$(cat clang-tidy-result/pr-head-repo.txt)" >> $GITHUB_ENV |
|||
echo "pr_head_ref=$(cat clang-tidy-result/pr-head-ref.txt)" >> $GITHUB_ENV |
|||
|
|||
- uses: actions/checkout@v3 |
|||
with: |
|||
repository: ${{ env.pr_head_repo }} |
|||
ref: ${{ env.pr_head_ref }} |
|||
persist-credentials: false |
|||
|
|||
- name: Redownload analysis results |
|||
uses: actions/github-script@v3.1.0 |
|||
with: |
|||
script: | |
|||
let artifacts = await github.actions.listWorkflowRunArtifacts({ |
|||
owner: context.repo.owner, |
|||
repo: context.repo.repo, |
|||
run_id: ${{github.event.workflow_run.id }}, |
|||
}); |
|||
let matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
|||
return artifact.name == "clang-tidy-result" |
|||
})[0]; |
|||
let download = await github.actions.downloadArtifact({ |
|||
owner: context.repo.owner, |
|||
repo: context.repo.repo, |
|||
artifact_id: matchArtifact.id, |
|||
archive_format: "zip", |
|||
}); |
|||
let fs = require("fs"); |
|||
fs.writeFileSync("${{github.workspace}}/clang-tidy-result.zip", Buffer.from(download.data)); |
|||
|
|||
- name: Extract analysis results |
|||
run: | |
|||
mkdir clang-tidy-result |
|||
unzip clang-tidy-result.zip -d clang-tidy-result |
|||
|
|||
- name: Run clang-tidy-pr-comments action |
|||
uses: platisd/clang-tidy-pr-comments@master |
|||
with: |
|||
github_token: ${{ secrets.GITHUB_TOKEN }} |
|||
clang_tidy_fixes: clang-tidy-result/fixes.yml |
|||
pull_request_id: ${{ env.pr_id }} |
@ -0,0 +1,52 @@ |
|||
#include <argparse/argparse.hpp>
|
|||
#include <doctest.hpp>
|
|||
|
|||
using doctest::test_suite; |
|||
|
|||
TEST_CASE("Get argument with .at()" * test_suite("as_container")) { |
|||
argparse::ArgumentParser program("test"); |
|||
auto &dir_arg = program.add_argument("--dir"); |
|||
program.at("--dir").default_value(std::string("/home/user")); |
|||
|
|||
SUBCASE("and default value") { |
|||
program.parse_args({"test"}); |
|||
REQUIRE(&(program.at("--dir")) == &dir_arg); |
|||
REQUIRE(program["--dir"] == std::string("/home/user")); |
|||
REQUIRE(program.at("--dir") == std::string("/home/user")); |
|||
} |
|||
|
|||
SUBCASE("and user-supplied value") { |
|||
program.parse_args({"test", "--dir", "/usr/local/database"}); |
|||
REQUIRE(&(program.at("--dir")) == &dir_arg); |
|||
REQUIRE(program["--dir"] == std::string("/usr/local/database")); |
|||
REQUIRE(program.at("--dir") == std::string("/usr/local/database")); |
|||
} |
|||
|
|||
SUBCASE("with unknown argument") { |
|||
program.parse_args({"test"}); |
|||
REQUIRE_THROWS_WITH_AS(program.at("--folder"), |
|||
"No such argument: --folder", std::logic_error); |
|||
} |
|||
} |
|||
|
|||
TEST_CASE("Get subparser with .at()" * test_suite("as_container")) { |
|||
argparse::ArgumentParser program("test"); |
|||
|
|||
argparse::ArgumentParser walk_cmd("walk"); |
|||
auto &speed = walk_cmd.add_argument("speed"); |
|||
|
|||
program.add_subparser(walk_cmd); |
|||
|
|||
SUBCASE("and its argument") { |
|||
program.parse_args({"test", "walk", "4km/h"}); |
|||
REQUIRE(&(program.at<argparse::ArgumentParser>("walk")) == &walk_cmd); |
|||
REQUIRE(&(program.at<argparse::ArgumentParser>("walk").at("speed")) == &speed); |
|||
REQUIRE(program.at<argparse::ArgumentParser>("walk").is_used("speed")); |
|||
} |
|||
|
|||
SUBCASE("with unknown command") { |
|||
program.parse_args({"test"}); |
|||
REQUIRE_THROWS_WITH_AS(program.at<argparse::ArgumentParser>("fly"), |
|||
"No such subparser: fly", std::logic_error); |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
#include <argparse/argparse.hpp>
|
|||
#include <doctest.hpp>
|
|||
#include <string>
|
|||
|
|||
using doctest::test_suite; |
|||
|
|||
TEST_CASE("Use a 'string' default value" * test_suite("default_value")) { |
|||
argparse::ArgumentParser program("test"); |
|||
|
|||
SUBCASE("Use a const char[] default value") { |
|||
program.add_argument("--arg").default_value("array of char"); |
|||
REQUIRE_NOTHROW(program.parse_args({"test"})); |
|||
REQUIRE(program.get("--arg") == std::string("array of char")); |
|||
} |
|||
|
|||
SUBCASE("Use a std::string default value") { |
|||
program.add_argument("--arg").default_value(std::string("string object")); |
|||
REQUIRE_NOTHROW(program.parse_args({"test"})); |
|||
REQUIRE(program.get("--arg") == std::string("string object")); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue