Add Option tests.
[command.git] / tests / option / should_throw_exception_on_missing_value.cpp
diff --git a/tests/option/should_throw_exception_on_missing_value.cpp b/tests/option/should_throw_exception_on_missing_value.cpp
new file mode 100644 (file)
index 0000000..f872ed1
--- /dev/null
@@ -0,0 +1,29 @@
+#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;
+}