diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-09-08 14:45:54 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-09-08 14:45:54 +0200 |
| commit | b12e0ba49e10e5a511889acf4b6494d18a324194 (patch) | |
| tree | 375b2704b26499c50d0cbee356e901d5b393a902 /source | |
| parent | bbda83f674a97e80cf89bff3d12737dd5ecc3243 (diff) | |
| download | wanda-b12e0ba49e10e5a511889acf4b6494d18a324194.tar.xz wanda-b12e0ba49e10e5a511889acf4b6494d18a324194.zip | |
wandac: add tests for the CLI
Diffstat (limited to 'source')
| -rw-r--r-- | source/app/wandac/CMakeLists.txt | 21 | ||||
| -rw-r--r-- | source/tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | source/tests/app/wandac/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | source/tests/app/wandac/src/cli.cpp | 80 |
4 files changed, 108 insertions, 5 deletions
diff --git a/source/app/wandac/CMakeLists.txt b/source/app/wandac/CMakeLists.txt index 0a70e5b..71aff36 100644 --- a/source/app/wandac/CMakeLists.txt +++ b/source/app/wandac/CMakeLists.txt @@ -1,19 +1,30 @@ -add_executable("wandac" +add_library("${PROJECT_NAME}c-components" OBJECT "src/cli.cpp" "src/listener.cpp" - "src/main.cpp" ) -target_include_directories("${PROJECT_NAME}c" PRIVATE +target_include_directories("${PROJECT_NAME}c-components" PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" ) -target_link_libraries("${PROJECT_NAME}c" PRIVATE +target_link_libraries("${PROJECT_NAME}c-components" PUBLIC "wanda::control" "wanda::proto" - "wanda::system" "bfg::lyra" + "Boost::headers" +) + +add_executable("wandac" + "src/main.cpp" +) + + +target_link_libraries("${PROJECT_NAME}c" PRIVATE + "${PROJECT_NAME}c-components" + + "wanda::system" + "spdlog::spdlog_header_only" ) diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 769814c..07b922b 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -1,3 +1,4 @@ include("Catch") +add_subdirectory("app/wandac") add_subdirectory("lib/system")
\ No newline at end of file diff --git a/source/tests/app/wandac/CMakeLists.txt b/source/tests/app/wandac/CMakeLists.txt new file mode 100644 index 0000000..ab07030 --- /dev/null +++ b/source/tests/app/wandac/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable("wanda-tests-wandac" + "src/cli.cpp" +) + +target_link_libraries("wanda-tests-wandac" PRIVATE + "${PROJECT_NAME}c-components" + + "Catch2::Catch2WithMain" +) + +catch_discover_tests("wanda-tests-wandac")
\ No newline at end of file diff --git a/source/tests/app/wandac/src/cli.cpp b/source/tests/app/wandac/src/cli.cpp new file mode 100644 index 0000000..ed02b4a --- /dev/null +++ b/source/tests/app/wandac/src/cli.cpp @@ -0,0 +1,80 @@ +#include "wandac/cli.hpp" + +#include <catch2/catch_all.hpp> +#include <catch2/catch_test_macros.hpp> +#include <lyra/args.hpp> + +#include <sstream> +#include <string> + +using namespace std::string_literals; + +namespace wanda::tests::app::wandac +{ + + template<typename ...Ts> + auto make_argument_list(Ts const & ... args) -> lyra::args + { + return {"wanda"s, static_cast<std::string>(args)...}; + } + + SCENARIO("Empty argument list parsing", "[app][client][cli]") + { + GIVEN("A fresh cli instance and error stream") + { + auto cli = ::wandac::cli{}; + auto error_stream = std::ostringstream{}; + + WHEN("invoking parse without any program arguments") + { + auto result = cli.parse(make_argument_list(), error_stream); + + THEN("the return value is false") { REQUIRE_FALSE(result); } + THEN("the error stream is not empty") { REQUIRE_FALSE(error_stream.view().empty()); } + THEN("the help flag is not set") { REQUIRE_FALSE(cli.help); } + THEN("the command is empty") { REQUIRE(cli.command.empty()); } + } + } + } + + SCENARIO("Valid argument list parsing", "[app][client][cli]") + { + GIVEN("A fresh cli instance and error stream") + { + auto cli = ::wandac::cli{}; + auto error_stream = std::ostringstream{}; + + AND_GIVEN("'-h' in the argument list") + { + auto argument_list = make_argument_list("-h"); + + WHEN("invoking parse without additional arguments") + { + auto result = cli.parse(argument_list, error_stream); + + THEN("the return value is true") { REQUIRE(result); } + THEN("the error stream is empty") { REQUIRE(error_stream.view().empty()); } + THEN("the help flag is set") { REQUIRE(cli.help); } + THEN("the command is empty") { REQUIRE(cli.command.empty()); } + } + } + + AND_GIVEN("'change' in the argument list") + { + auto argument_list = make_argument_list("change"); + + WHEN("invoking parse without additional arguments") + { + auto result = cli.parse(argument_list, error_stream); + + THEN("the return valis is true") { REQUIRE(result); } + THEN("the error stream is empty") { REQUIRE(error_stream.view().empty()); } + THEN("the help flag is not set") { REQUIRE_FALSE(cli.help); } + THEN("the command is not empty") { REQUIRE_FALSE(cli.command.empty()); } + THEN("the command is 'change'") { REQUIRE(cli.command == "change"); } + } + } + } + } + +} // namespace wanda::tests::app::wandac |
