From: Rafał Długołęcki Date: Wed, 20 May 2015 16:50:33 +0000 (+0200) Subject: Move tests to their directories. Add unsigned int Option test. X-Git-Tag: v0.2.1~7 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=ef9c54cfdb5b669287dbc5e2d07a62715f1bf202;p=command.git Move tests to their directories. Add unsigned int Option test. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index f489244..4df147e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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) \ diff --git a/tests/command/src/option_test_command.cpp b/tests/command/src/option_test_command.cpp index 312d4aa..b4c92f0 100644 --- a/tests/command/src/option_test_command.cpp +++ b/tests/command/src/option_test_command.cpp @@ -26,6 +26,9 @@ int main(int argc, char *argv[]) { new Option("int", "int Test", [](int i) { std::cout << "int: " << i << std::endl; }), + new Option("unsigned-int", "unsigned int Test", [](unsigned int i) { + std::cout << "unsigned int: " << i << std::endl; + }), new Option("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 index 0000000..2703221 --- /dev/null +++ b/tests/command/understand_int_option.test @@ -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. 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 if value is not integer only. Got: '$TEST', from: '$t;. Program exited with $? code." + return 1; + fi +done + +echo "Command understand Option 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 index 0000000..5a92735 --- /dev/null +++ b/tests/command/understand_unsigned_int_option.test @@ -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. 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 if value is not unsigned integer only. Got: '$TEST', from: '$t'. Program exited with $? code." + return 1; + fi +done + +echo "Command understand Option correctly." + +return 0;