[mlpack-git] master: Test duplicate parameter handling. (eb5b750)
gitdub at mlpack.org
gitdub at mlpack.org
Tue Nov 1 11:52:43 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/981ffa2d67d8fe38df6c699589005835fef710ea...04551164d9950dbdb3738f0c9d87e2d498fd8192
>---------------------------------------------------------------
commit eb5b750ac00f9f608d600cfbdc5b9c9a66cff4d5
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Nov 1 11:52:43 2016 -0400
Test duplicate parameter handling.
>---------------------------------------------------------------
eb5b750ac00f9f608d600cfbdc5b9c9a66cff4d5
src/mlpack/tests/cli_test.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/mlpack/tests/cli_test.cpp b/src/mlpack/tests/cli_test.cpp
index 90f89b6..953791d 100644
--- a/src/mlpack/tests/cli_test.cpp
+++ b/src/mlpack/tests/cli_test.cpp
@@ -125,6 +125,47 @@ BOOST_AUTO_TEST_CASE(TestOption)
}
/**
+ * Test that duplicate flags are filtered out correctly.
+ */
+BOOST_AUTO_TEST_CASE(TestDuplicateFlag)
+{
+ AddRequiredCLIOptions();
+
+ PARAM_FLAG("test", "test", "t");
+
+ int argc = 3;
+ const char* argv[3];
+ argv[0] = "./test";
+ argv[1] = "--test";
+ argv[2] = "--test";
+
+ // This should not throw an exception.
+ CLI::ParseCommandLine(argc, const_cast<char**>(argv));
+}
+
+/**
+ * Test that duplicate options throw an exception.
+ */
+BOOST_AUTO_TEST_CASE(TestDuplicateParam)
+{
+ AddRequiredCLIOptions();
+
+ int argc = 5;
+ const char* argv[5];
+ argv[0] = "./test";
+ argv[1] = "--info";
+ argv[2] = "test1";
+ argv[3] = "--info";
+ argv[4] = "test2";
+
+ // This should throw an exception.
+ Log::Fatal.ignoreInput = true;
+ BOOST_REQUIRE_THROW(CLI::ParseCommandLine(argc, const_cast<char**>(argv)),
+ std::runtime_error);
+ Log::Fatal.ignoreInput = false;
+}
+
+/**
* Ensure that a Boolean option which we define is set correctly.
*/
BOOST_AUTO_TEST_CASE(TestBooleanOption)
More information about the mlpack-git
mailing list