From 9e7b80034efa7412f76739c747aa611ed0caca17 Mon Sep 17 00:00:00 2001 From: Stephan van Veen Date: Sat, 18 May 2019 14:22:10 +0200 Subject: [PATCH] Throw exception in case of unknown argument --- include/argparse.hpp | 5 ++++- test/test_invalid_arguments.hpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index 3fca9fb..69cc370 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -462,10 +462,13 @@ class ArgumentParser { auto tArgument = tIterator->second; it = tArgument->consume(it, end, tCurrentArgument); } + else { + throw std::runtime_error("Unknown argument"); + } } } else { - ++it; + throw std::runtime_error("Unknown argument"); } } } diff --git a/test/test_invalid_arguments.hpp b/test/test_invalid_arguments.hpp index f466be8..1806816 100644 --- a/test/test_invalid_arguments.hpp +++ b/test/test_invalid_arguments.hpp @@ -34,5 +34,5 @@ TEST_CASE("Parse unknown optional argument", "[compound_arguments]") { .action([](const std::string& val) { return std::stoull(val); }) .help("memory in MB to give the VMM when loading"); - bfm.parse_args({ "./test.exe", "-om" }); + REQUIRE_THROWS(bfm.parse_args({ "./test.exe", "-om" })); }