Skip to content

Commit

Permalink
Merge pull request #55 from kkarbowiak/exit-tests
Browse files Browse the repository at this point in the history
Add exit tests
  • Loading branch information
kkarbowiak authored Feb 6, 2025
2 parents 9f3cd3d + de7693e commit 9682e53
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions test/exit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Werror -pedantic-errors>
$<$<CXX_COMPILER_ID:MSVC>:
/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)
2 changes: 1 addition & 1 deletion test/manual/main.cpp → test/exit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 0 additions & 14 deletions test/manual/CMakeLists.txt

This file was deleted.

0 comments on commit 9682e53

Please sign in to comment.