Possibility to pass class method reference
[command.git] / tests / option / should_throw_exception_on_missing_value.cpp
1 #include <iostream>
2 #include <vector>
3
4 #include "option.h"
5
6 #define NAME "test"
7 #define BAD_OPTION "test="
8
9 using namespace std;
10 using namespace command;
11
12 void _function(int) { }
13
14 int main() {
15     Option<int> option(NAME, "Option should throw exception on missing value", _function);
16
17     try {
18         if (option.understand(BAD_OPTION)) {
19             std::cout << option.describe() << " but instead it understanded it\n";
20         }
21     }
22     catch(std::invalid_argument e) {
23         std::cout << option.describe() << " and it was thrown correctly\n";
24         return 0;
25     }
26
27     std::cout << option.describe() << " but nothing happened\n";
28     return 1;
29 }