aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.cli/test_command_map.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.cli/test_command_map.cc')
-rw-r--r--nihil.cli/test_command_map.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/nihil.cli/test_command_map.cc b/nihil.cli/test_command_map.cc
new file mode 100644
index 0000000..1b87a49
--- /dev/null
+++ b/nihil.cli/test_command_map.cc
@@ -0,0 +1,32 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+#include <vector>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil.cli;
+
+namespace {
+
+auto cmd_sub1_called = false;
+auto cmd_sub1 = nihil::command("cmd sub1", "", [](int, char **) -> int
+{
+ cmd_sub1_called = true;
+ return 0;
+});
+
+} // anonymous namespace
+
+TEST_CASE("command_map: basic", "[command_map]")
+{
+ auto args = std::vector<char const *>{
+ "cmd", "sub1", nullptr
+ };
+ auto argv = const_cast<char **>(args.data());
+
+ int ret = nihil::dispatch_command(args.size() - 1, argv);
+ REQUIRE(ret == 0);
+ REQUIRE(cmd_sub1_called == true);
+}