diff --git a/CMakeLists.txt b/CMakeLists.txt index c119b4e4..1d005d67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) enable_testing() add_subdirectory(test/unittest) - add_subdirectory(test/manual) + add_subdirectory(test/exit) add_subdirectory(thirdparty/doctest) add_subdirectory(tutorial) diff --git a/test/exit/CMakeLists.txt b/test/exit/CMakeLists.txt new file mode 100644 index 00000000..ad3f2ef5 --- /dev/null +++ b/test/exit/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.15) + +add_executable(app) +target_sources(app + PRIVATE + main.cpp) + +target_compile_features(app PRIVATE cxx_std_20) +target_compile_options(app PRIVATE + $<$,$>: + -Wall -Wextra -Werror -pedantic-errors> + $<$: + /W4 /WX /permissive->) +target_link_libraries(app PRIVATE cpp-argparse) + +add_test(NAME help-test COMMAND app --help) +set_property(TEST help-test PROPERTY PASS_REGULAR_EXPRESSION "usage: app \\[-h\\] \\[--optional OPTIONAL\\] \\[-v\\] positional\n\npositional arguments:\n positional\n\noptional arguments:\n -h, --help show this help message and exit\n --optional OPTIONAL\n -v, --version show program's version number and exit\n") + +add_test(NAME version-test COMMAND app --version) +set_property(TEST version-test PROPERTY PASS_REGULAR_EXPRESSION "1\.0\.0") + +add_test(NAME error-test-1 COMMAND app) +set_property(TEST error-test-1 PROPERTY WILL_FAIL true) + +add_test(NAME error-test-2 COMMAND app) +set_property(TEST error-test-2 PROPERTY PASS_REGULAR_EXPRESSION "the following arguments are required: positional\nusage: app \\[-h\\] \\[--optional OPTIONAL\\] \\[-v\\] positional\n\npositional arguments:\n positional\n\noptional arguments:\n -h, --help show this help message and exit\n --optional OPTIONAL\n -v, --version show program's version number and exit\n") + +add_custom_target(run_exit_test ALL + COMMAND ${CMAKE_CTEST_COMMAND} -C debug --output-on-failure + DEPENDS app) diff --git a/test/manual/main.cpp b/test/exit/main.cpp similarity index 89% rename from test/manual/main.cpp rename to test/exit/main.cpp index 968be925..ea4998d2 100644 --- a/test/manual/main.cpp +++ b/test/exit/main.cpp @@ -4,7 +4,7 @@ auto main(int argc, char * argv[]) -> int { - auto parser = argparse::ArgumentParser(); + auto parser = argparse::ArgumentParser().prog("app"); parser.add_argument("positional"); parser.add_argument("--optional"); parser.add_argument("-v", "--version").action(argparse::version).version("1.0.0"); diff --git a/test/manual/CMakeLists.txt b/test/manual/CMakeLists.txt deleted file mode 100644 index db941692..00000000 --- a/test/manual/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -add_executable(app) -target_sources(app - PRIVATE - main.cpp) - -target_compile_features(app PRIVATE cxx_std_20) -target_compile_options(app PRIVATE - $<$,$>: - -Wall -Wextra -Werror -pedantic-errors> - $<$: - /W4 /WX /permissive->) -target_link_libraries(app PRIVATE cpp-argparse)