diff options
author | Andrei Pavel <andrei@isc.org> | 2023-12-15 11:07:30 +0100 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2024-01-26 18:47:41 +0100 |
commit | 697e9fad4002a727ed514aa9020bc67d2e8f2ae0 (patch) | |
tree | ea176c6498a2109cf29a4daabf88bea5ea68faa0 /src/bin | |
parent | [#2788] make all commandLineArgs tests more strict (diff) | |
download | kea-697e9fad4002a727ed514aa9020bc67d2e8f2ae0.tar.xz kea-697e9fad4002a727ed514aa9020bc67d2e8f2ae0.zip |
[#2788] exhaust options before throwing error
Prior to this change, if parseArgs() was called twice during the same
program lifetime and it stumbled on an unsupported option and throwed an
exception on the first call, the previous set of arguments lived on to
be parsed by the second call. This is a situation that likely arises
only in unit tests, but let us fix it properly to at least silence the unit
test failure on alpine, which was happening because of different
implementation of getopt from musl, and which motivated looking into how
getopt behaves. To make the bug evident even in a non-alpine environment, add an
EXPECT_THROW_MSG in DStubControllerTest.commandLineArgs when parsing argv3, and
see that it outputs "unsupported option: [s]" instead of
"extraneous command line information".
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/agent/tests/ca_controller_unittests.cc | 2 | ||||
-rw-r--r-- | src/bin/d2/tests/d2_controller_unittests.cc | 2 | ||||
-rw-r--r-- | src/bin/netconf/tests/netconf_controller_unittests.cc | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/src/bin/agent/tests/ca_controller_unittests.cc b/src/bin/agent/tests/ca_controller_unittests.cc index dc63e01a39..a20ea1a770 100644 --- a/src/bin/agent/tests/ca_controller_unittests.cc +++ b/src/bin/agent/tests/ca_controller_unittests.cc @@ -216,7 +216,7 @@ TEST_F(CtrlAgentControllerTest, commandLineArgs) { char* argv2[] = { const_cast<char*>("progName"), const_cast<char*>("-x") }; argc = 2; - EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: [x] "); + EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: -x"); } // Tests application process creation and initialization. diff --git a/src/bin/d2/tests/d2_controller_unittests.cc b/src/bin/d2/tests/d2_controller_unittests.cc index 8bac486ba6..52e4cc0565 100644 --- a/src/bin/d2/tests/d2_controller_unittests.cc +++ b/src/bin/d2/tests/d2_controller_unittests.cc @@ -132,7 +132,7 @@ TEST_F(D2ControllerTest, commandLineArgs) { char* argv2[] = { const_cast<char*>("progName"), const_cast<char*>("-x") }; argc = 2; - EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: [x] "); + EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: -x"); } /// @brief Tests application process creation and initialization. diff --git a/src/bin/netconf/tests/netconf_controller_unittests.cc b/src/bin/netconf/tests/netconf_controller_unittests.cc index 03002f7c4c..3bbd708f3d 100644 --- a/src/bin/netconf/tests/netconf_controller_unittests.cc +++ b/src/bin/netconf/tests/netconf_controller_unittests.cc @@ -131,7 +131,7 @@ TEST_F(NetconfControllerTest, commandLineArgs) { char* argv2[] = { const_cast<char*>("progName"), const_cast<char*>("-x") }; argc = 2; - EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: [x] "); + EXPECT_THROW_MSG(parseArgs(argc, argv2), InvalidUsage, "unsupported option: -x"); } // Tests application process creation and initialization. |