diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4324179b..a1b2fed1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI -on: pull_request +on: [push, pull_request] jobs: @@ -12,6 +12,8 @@ jobs: strategy: + fail-fast: false + matrix: toolchain: @@ -63,25 +65,25 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build - name: Configure - working-directory: test - run: cmake -S . -B build ${{ matrix.cmake_opts }} + working-directory: ${{runner.workspace}}/build + shell: bash + run: cmake -DARGPARSE_BUILD_SAMPLES=ON -DCMAKE_BUILD_TYPE=Debug ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE env: CC: ${{ matrix.c_compiler }} CXX: ${{ matrix.cxx_compiler }} - name: Build for ${{ matrix.os }} with ${{ matrix.compiler }} - working-directory: test - run: cmake --build build + working-directory: ${{runner.workspace}}/build + run: cmake --build . --config Debug --verbose - name: Test - if: ${{ ! startsWith(matrix.os, 'windows') }} - working-directory: test/build - run: ./tests - - - name: Test (Windows) - if: ${{ startsWith(matrix.os, 'windows') }} - working-directory: test/build - run: ./Debug/tests.exe + working-directory: ${{runner.workspace}}/build + run: ctest -C Debug -V + env: + CTEST_OUTPUT_ON_FAILURE: True diff --git a/.gitignore b/.gitignore index cdcb6f62..fded6749 100644 --- a/.gitignore +++ b/.gitignore @@ -264,6 +264,9 @@ __pycache__/ # CMake build directory build +# CMake Testing directory +Testing + # Cppcheck build directory analysis-cppcheck-build-dir diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f9f183f..a92cf775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ project(argparse LANGUAGES CXX ) -option(ARGPARSE_INSTALL "Include an install target" ON) -option(ARGPARSE_BUILD_TESTS "Build tests" ON) +option(ARGPARSE_INSTALL "Include an install target" ${ARGPARSE_IS_TOP_LEVEL}) +option(ARGPARSE_BUILD_TESTS "Build tests" ${ARGPARSE_IS_TOP_LEVEL}) option(ARGPARSE_BUILD_SAMPLES "Build samples" OFF) include(GNUInstallDirs) @@ -28,15 +28,41 @@ target_include_directories(argparse INTERFACE $ $) + +# Pedantic compiler options +# Update if necessary +if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS "/W4") + endif() + list(APPEND ARGPARSE_PEDANTIC_COMPILE_FLAGS "/WX") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) +endif() + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() + if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif() - -if(ARGPARSE_BUILD_TESTS AND ARGPARSE_IS_TOP_LEVEL) + +if(ARGPARSE_BUILD_TESTS) + enable_testing() add_subdirectory(test) endif() - -if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL) + +if(ARGPARSE_INSTALL) install(TARGETS argparse EXPORT argparseConfig) install(EXPORT argparseConfig NAMESPACE argparse:: @@ -95,6 +121,6 @@ if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL) install(FILES "${PKG_CONFIG_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) -endif() -include(CPack) + include(CPack) +endif() diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 0c85127d..3ddeef8b 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -1387,8 +1387,9 @@ class Argument { } if constexpr (details::IsContainer) { return any_cast_container(m_values); + } else { + return std::any_cast(m_values.front()); } - return std::any_cast(m_values.front()); } template diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index dfcc9272..36d7024e 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,32 +1,11 @@ -cmake_minimum_required(VERSION 3.6) -project(argparse_samples) - -if(MSVC) - # Force to always compile with W4 - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() -elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - # Update if necessary - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion") -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() - -# Disable deprecation for windows -if (WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) -endif() function(add_sample NAME) - ADD_EXECUTABLE(ARGPARSE_SAMPLE_${NAME} ${NAME}.cpp) - INCLUDE_DIRECTORIES("../include" ".") - set_target_properties(ARGPARSE_SAMPLE_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) - set_property(TARGET ARGPARSE_SAMPLE_${NAME} PROPERTY CXX_STANDARD 17) + add_executable(argparse_sample_${NAME} ${NAME}.cpp) + target_link_libraries(argparse_sample_${NAME} PRIVATE argparse::argparse) + if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) + target_compile_options(argparse_sample_${NAME} PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) + endif() + set_target_properties(argparse_sample_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) endfunction() add_sample(positional_argument) @@ -43,4 +22,4 @@ add_sample(gathering_remaining_arguments) add_sample(subcommands) add_sample(parse_known_args) add_sample(custom_prefix_characters) -add_sample(custom_assignment_characters) \ No newline at end of file +add_sample(custom_assignment_characters) diff --git a/samples/gathering_remaining_arguments.cpp b/samples/gathering_remaining_arguments.cpp index 099b07f8..46423e37 100644 --- a/samples/gathering_remaining_arguments.cpp +++ b/samples/gathering_remaining_arguments.cpp @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { std::cout << files.size() << " files provided" << std::endl; for (auto &file : files) std::cout << file << std::endl; - } catch (std::logic_error &e) { + } catch (const std::logic_error &) { std::cout << "No files provided" << std::endl; } } \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 587eb824..ecab89db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,28 +1,6 @@ -cmake_minimum_required(VERSION 3.6) -project(argparse_tests) -if(MSVC) - # Force to always compile with W4 - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() -elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - # Update if necessary - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra") -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() -# Disable deprecation for windows -if (WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) -endif() - -# ARGPARSE executable +# ARGPARSE test executable file(GLOB ARGPARSE_TEST_SOURCES main.cpp test_actions.cpp @@ -56,13 +34,10 @@ file(GLOB ARGPARSE_TEST_SOURCES test_equals_form.cpp test_prefix_chars.cpp ) -set_source_files_properties(main.cpp - PROPERTIES - COMPILE_DEFINITIONS DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) -ADD_EXECUTABLE(ARGPARSE_TESTS ${ARGPARSE_TEST_SOURCES}) -INCLUDE_DIRECTORIES("../include" ".") -set_target_properties(ARGPARSE_TESTS PROPERTIES OUTPUT_NAME tests) -set_property(TARGET ARGPARSE_TESTS PROPERTY CXX_STANDARD 17) -# Set ${PROJECT_NAME} as the startup project -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ARGPARSE_TESTS) +add_executable(argparse_tests ${ARGPARSE_TEST_SOURCES}) +if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) + target_compile_options(argparse_tests PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) +endif() +target_link_libraries(argparse_tests PRIVATE argparse::argparse) +add_test(NAME argparse_tests COMMAND argparse_tests) diff --git a/test/README.md b/test/README.md index 491cf1a6..f127ccc2 100644 --- a/test/README.md +++ b/test/README.md @@ -7,7 +7,7 @@ $ mkdir build $ cd build $ cmake ../. $ make -$ ./tests +$ ./argparse_tests ``` ## Windows @@ -21,5 +21,5 @@ $ cmake ../. -G "Visual Studio 15 2017" ``` 2. Open ARGPARSE.sln -3. Build tests in RELEASE | x64 -4. Run tests.exe +3. Build argparse_tests in RELEASE | x64 +4. Run argparse_tests.exe diff --git a/test/main.cpp b/test/main.cpp index 53c0a370..9076ec34 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1 +1,2 @@ -#include +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.hpp" diff --git a/test/test_actions.cpp b/test/test_actions.cpp index aa8cd3de..febbed4c 100644 --- a/test/test_actions.cpp +++ b/test/test_actions.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_append.cpp b/test/test_append.cpp index 8a68c65d..8e419bff 100644 --- a/test/test_append.cpp +++ b/test/test_append.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_as_container.cpp b/test/test_as_container.cpp index 37f725ec..cb2f0cbc 100644 --- a/test/test_as_container.cpp +++ b/test/test_as_container.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_bool_operator.cpp b/test/test_bool_operator.cpp index a34b5d64..5e8d4149 100644 --- a/test/test_bool_operator.cpp +++ b/test/test_bool_operator.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_choices.cpp b/test/test_choices.cpp index 678aba82..b176956e 100644 --- a/test/test_choices.cpp +++ b/test/test_choices.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_compound_arguments.cpp b/test/test_compound_arguments.cpp index 927e5b2e..78bb098f 100644 --- a/test/test_compound_arguments.cpp +++ b/test/test_compound_arguments.cpp @@ -3,8 +3,8 @@ import argparse; #else #include #endif -#include -#include +#include "doctest.hpp" +#include "test_utility.hpp" using doctest::test_suite; diff --git a/test/test_container_arguments.cpp b/test/test_container_arguments.cpp index e6596950..8d52d4ad 100644 --- a/test/test_container_arguments.cpp +++ b/test/test_container_arguments.cpp @@ -3,8 +3,8 @@ import argparse; #else #include #endif -#include -#include +#include "doctest.hpp" +#include "test_utility.hpp" using doctest::test_suite; diff --git a/test/test_default_args.cpp b/test/test_default_args.cpp index 4b813fb4..5fbb7561 100644 --- a/test/test_default_args.cpp +++ b/test/test_default_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_default_value.cpp b/test/test_default_value.cpp index 5287173b..48cf64c9 100644 --- a/test/test_default_value.cpp +++ b/test/test_default_value.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; diff --git a/test/test_equals_form.cpp b/test/test_equals_form.cpp index a4b89a49..5afa2212 100644 --- a/test/test_equals_form.cpp +++ b/test/test_equals_form.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_error_reporting.cpp b/test/test_error_reporting.cpp index 0c911321..6a5f064e 100644 --- a/test/test_error_reporting.cpp +++ b/test/test_error_reporting.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_get.cpp b/test/test_get.cpp index 13db01c4..ea9e1db9 100644 --- a/test/test_get.cpp +++ b/test/test_get.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include diff --git a/test/test_help.cpp b/test/test_help.cpp index 864a8077..17c0b728 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_invalid_arguments.cpp b/test/test_invalid_arguments.cpp index 86e344cc..fedc398c 100644 --- a/test/test_invalid_arguments.cpp +++ b/test/test_invalid_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_is_used.cpp b/test/test_is_used.cpp index cfb6e439..72ba17f3 100644 --- a/test/test_is_used.cpp +++ b/test/test_is_used.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_issue_37.cpp b/test/test_issue_37.cpp index 7e8e2bc1..ac8c7d1a 100644 --- a/test/test_issue_37.cpp +++ b/test/test_issue_37.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_mutually_exclusive_group.cpp b/test/test_mutually_exclusive_group.cpp index f2433647..3d368ebb 100644 --- a/test/test_mutually_exclusive_group.cpp +++ b/test/test_mutually_exclusive_group.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_negative_numbers.cpp b/test/test_negative_numbers.cpp index f9dd463c..e4d85757 100644 --- a/test/test_negative_numbers.cpp +++ b/test/test_negative_numbers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_optional_arguments.cpp b/test/test_optional_arguments.cpp index 74a4c25a..2f8097ed 100644 --- a/test/test_optional_arguments.cpp +++ b/test/test_optional_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_parent_parsers.cpp b/test/test_parent_parsers.cpp index 9f9a7f80..60890a62 100644 --- a/test/test_parent_parsers.cpp +++ b/test/test_parent_parsers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_parse_args.cpp b/test/test_parse_args.cpp index bb3af2a0..b56ea9bc 100644 --- a/test/test_parse_args.cpp +++ b/test/test_parse_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include diff --git a/test/test_parse_known_args.cpp b/test/test_parse_known_args.cpp index 909621f7..9b2976fa 100644 --- a/test/test_parse_known_args.cpp +++ b/test/test_parse_known_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_positional_arguments.cpp b/test/test_positional_arguments.cpp index 16650488..f80c8789 100644 --- a/test/test_positional_arguments.cpp +++ b/test/test_positional_arguments.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif #include -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_prefix_chars.cpp b/test/test_prefix_chars.cpp index a5c3394c..0739d43b 100644 --- a/test/test_prefix_chars.cpp +++ b/test/test_prefix_chars.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif #include -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_repr.cpp b/test/test_repr.cpp index d924a720..c31b576d 100644 --- a/test/test_repr.cpp +++ b/test/test_repr.cpp @@ -4,7 +4,7 @@ import argparse.details; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_required_arguments.cpp b/test/test_required_arguments.cpp index 7d7a077e..6a22415d 100644 --- a/test/test_required_arguments.cpp +++ b/test/test_required_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_scan.cpp b/test/test_scan.cpp index c556cb90..45f65a4e 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; diff --git a/test/test_stringstream.cpp b/test/test_stringstream.cpp index 105bb409..620d06eb 100644 --- a/test/test_stringstream.cpp +++ b/test/test_stringstream.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_subparsers.cpp b/test/test_subparsers.cpp index 532c9a7e..b75e98e5 100644 --- a/test/test_subparsers.cpp +++ b/test/test_subparsers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_version.cpp b/test/test_version.cpp index 3179f566..641a727f 100644 --- a/test/test_version.cpp +++ b/test/test_version.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; diff --git a/xmake.lua b/xmake.lua index c95bda3a..ab45def4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -48,7 +48,6 @@ if get_config("enable_tests") then add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) add_files("test/**.cpp") add_deps("argparse") @@ -64,7 +63,6 @@ if get_config("enable_tests") then add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) add_files("test/**.cpp") add_files("test/argparse_details.cppm")