std::stringstream ss;
ss << argv.substr(pos + 1);
- ss >> value;// memory leak? when is uncommented, and exception is
+ ss >> value;// memory leak? when uncommented and exception is
// thrown, valgrind shows e.g.:
// possibly lost: 380 bytes in 7 blocks
option_handles_negative_float_value.test \
option_handles_boolean_value.test \
option_handles_void_value.test \
- option_should_match_exact_name.test
+ option_should_match_exact_name.test \
+ option_should_throw_exception_on_missing_value.test
noinst_PROGRAMS = $(TESTS)
option_handles_boolean_value_test_SOURCES = option/handles_boolean_value.cpp
option_handles_void_value_test_SOURCES = option/handles_void_value.cpp
option_should_match_exact_name_test_SOURCES = option/should_match_exact_name.cpp
+option_should_throw_exception_on_missing_value_test_SOURCES = option/should_throw_exception_on_missing_value.cpp
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "option.h"
+
+#define NAME "test"
+#define BAD_OPTION "test="
+
+using namespace std;
+using namespace command;
+
+void function(int) { }
+
+int main() {
+ Option<int> option(NAME, "Option should throw exception on missing value", function);
+
+ try {
+ if (option.understand(BAD_OPTION)) {
+ std::cout << option.describe() << " but instead it understanded it\n";
+ }
+ }
+ catch(std::invalid_argument e) {
+ std::cout << option.describe() << " and it was thrown correctly\n";
+ return 0;
+ }
+
+ std::cout << option.describe() << " but nothing happened\n";
+ return 1;
+}