Move tests to their directories. Add unsigned int Option test.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 20 May 2015 16:50:33 +0000 (18:50 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 20 May 2015 16:50:33 +0000 (18:50 +0200)
tests/Makefile.am
tests/command/src/option_test_command.cpp
tests/command/understand_int_option.test [new file with mode: 0755]
tests/command/understand_unsigned_int_option.test [new file with mode: 0755]

index f489244dbb64842ade7103a7c945919faa11a087..4df147ebef0950d67f77c59f3d228c9da83a8b89 100644 (file)
@@ -1,33 +1,35 @@
 AUTOMAKE_OPTIONS = subdir-objects
 
 TEST_PROGS = \
-       descriptive_holds_data.test \
-       callable_invokes_provided_function.test \
-       callable_invokes_void_function.test \
-       parameter_is_descriptive.test \
-       parameter_should_be_non_required.test \
-       argument_handles_string_value.test \
-       argument_handles_int_value.test \
-       argument_handles_negative_int_value.test \
-       argument_handles_float_value.test \
-       argument_handles_negative_float_value.test \
-       argument_handles_boolean_value.test \
-       option_handles_string_value.test \
-       option_handles_int_value.test \
-       option_handles_negative_int_value.test \
-       option_handles_float_value.test \
-       option_handles_negative_float_value.test \
-       option_handles_boolean_value.test \
-       option_handles_void_value.test \
-       option_should_match_exact_name.test \
-       option_should_throw_exception_on_missing_value.test \
-       required_should_be_required.test \
-       multivalue_should_extract_arguments_by_separator.test \
-       multivalue_should_extract_options_by_separator.test
+       descriptive/holds_data.test \
+       callable/invokes_provided_function.test \
+       callable/invokes_void_function.test \
+       parameter/is_descriptive.test \
+       parameter/should_be_non_required.test \
+       argument/handles_string_value.test \
+       argument/handles_int_value.test \
+       argument/handles_negative_int_value.test \
+       argument/handles_float_value.test \
+       argument/handles_negative_float_value.test \
+       argument/handles_boolean_value.test \
+       option/handles_string_value.test \
+       option/handles_int_value.test \
+       option/handles_negative_int_value.test \
+       option/handles_float_value.test \
+       option/handles_negative_float_value.test \
+       option/handles_boolean_value.test \
+       option/handles_void_value.test \
+       option/should_match_exact_name.test \
+       option/should_throw_exception_on_missing_value.test \
+       required/should_be_required.test \
+       multivalue/should_extract_arguments_by_separator.test \
+       multivalue/should_extract_options_by_separator.test
 
 TEST_SCRPTS = \
        command/understand_void_option.test \
-       command/understand_bool_option.test
+       command/understand_bool_option.test \
+       command/understand_int_option.test \
+       command/understand_unsigned_int_option.test
 
 TESTS = \
        $(TEST_PROGS) \
index 312d4aadfcbb214bccb3f1a55e1d6bb886252c94..b4c92f00b612da5a3ae2ca897079c02449f54c98 100644 (file)
@@ -26,6 +26,9 @@ int main(int argc, char *argv[]) {
             new Option<int>("int", "int Test", [](int i) {
                 std::cout << "int: " << i << std::endl;
             }),
+            new Option<unsigned int>("unsigned-int", "unsigned int Test", [](unsigned int i) {
+                std::cout << "unsigned int: " << i << std::endl;
+            }),
             new Option<float>("float", "float Test", [](float f) {
                 std::cout << "float: " << f << std::endl;
             }),
diff --git a/tests/command/understand_int_option.test b/tests/command/understand_int_option.test
new file mode 100755 (executable)
index 0000000..2703221
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+for t in -5 -4 -3 -2 -1 0 1 2 3 4 5 10 100 200 300 21231; do
+    TEST=$($srcdir/command/option_test_command int=$t)
+    if [ ! "$TEST" = "int: $t" ]; then
+        echo "Command should understand Option<int>. Expecting output: 'int: $t', got: '$TEST'. Program exited with $? code."
+        return 1;
+    fi
+done
+
+for t in a b c d e example_string f3f12; do
+    TEST=$($srcdir/command/option_test_command int=$t)
+    if [ ! "$?" = "1" ]; then
+        echo "Command should not understand Option<int> if value is not integer only. Got: '$TEST', from: '$t;. Program exited with $? code."
+        return 1;
+    fi
+done
+
+echo "Command understand Option<int> correctly."
+
+return 0;
diff --git a/tests/command/understand_unsigned_int_option.test b/tests/command/understand_unsigned_int_option.test
new file mode 100755 (executable)
index 0000000..5a92735
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+for t in 0 1 2 3 4 5 10 100 200 300 21231; do
+    TEST=$($srcdir/command/option_test_command unsigned-int=$t)
+    if [ ! "$TEST" = "unsigned int: $t" ]; then
+        echo "Command should understand Option<unsigned int>. Expecting output: 'unsigned int: $t', got: '$TEST', from: '$t'. Program exited with $? code."
+        return 1;
+    fi
+done
+
+for t in a b c d e example_string f3f12; do
+    TEST=$($srcdir/command/option_test_command unsigned-int=$t)
+    if [ ! "$?" = "1" ]; then
+        echo "Command should not understand Option<unsigned int> if value is not unsigned integer only. Got: '$TEST', from: '$t'. Program exited with $? code."
+        return 1;
+    fi
+done
+
+echo "Command understand Option<int> correctly."
+
+return 0;