From 985f6e019472a2165cbae2320eac04f90eb8d226 Mon Sep 17 00:00:00 2001 From: Dennis Skinner Date: Sat, 2 Dec 2023 03:05:32 -0500 Subject: [PATCH] Add help option to test command line args When test binaries are run with unknown options or with the standard -h option, a help menu will print all available options. This is much more convenient than having to dig through unity.c to find every option. --- src/unity.c | 11 ++++++++ test/tests/test_generate_test_runner.rb | 36 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index cc2e5ce..284f0dc 100644 --- a/src/unity.c +++ b/src/unity.c @@ -2329,6 +2329,17 @@ int UnityParseOptions(int argc, char** argv) UnityPrint("ERROR: Unknown Option "); UNITY_OUTPUT_CHAR(argv[i][1]); UNITY_PRINT_EOL(); + /* fall-through to display help */ + case 'h': + UnityPrint("Options: "); UNITY_PRINT_EOL(); + UnityPrint("-l List all tests"); UNITY_PRINT_EOL(); + UnityPrint("-f TEST Only run tests with TEST in the name"); UNITY_PRINT_EOL(); + UnityPrint("-n TEST Only run tests with TEST in the name"); UNITY_PRINT_EOL(); + UnityPrint("-h Show this help menu"); UNITY_PRINT_EOL(); + UnityPrint("-q Quiet/Decrease verbosity"); UNITY_PRINT_EOL(); + UnityPrint("-v Increase verbosity"); UNITY_PRINT_EOL(); + UnityPrint("-x TEST Exclude tests with TEST in the name"); UNITY_PRINT_EOL(); + UNITY_OUTPUT_FLUSH(); return 1; } } diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 658b6e2..1d73bf8 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -1158,9 +1158,43 @@ RUNNER_TESTS = [ :to_pass => [ ], :to_fail => [ ], :to_ignore => [ ], - :text => [ "ERROR: Unknown Option z" ], + :text => [ + "ERROR: Unknown Option z", + "Options:", + "-l List all tests", + "-f TEST Only run tests with TEST in the name", + "-n TEST Only run tests with TEST in the name", + "-h Show this help menu", + "-q Quiet/Decrease verbosity", + "-v Increase verbosity", + "-x TEST Exclude tests with TEST in the name", + ], } }, + + { :name => 'ArgsHelp', + :testfile => 'testdata/testRunnerGenerator.c', + :testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'], + :options => { + :cmdline_args => true, + }, + :cmdline_args => "-h", + :expected => { + :to_pass => [ ], + :to_fail => [ ], + :to_ignore => [ ], + :text => [ + "Options:", + "-l List all tests", + "-f TEST Only run tests with TEST in the name", + "-n TEST Only run tests with TEST in the name", + "-h Show this help menu", + "-q Quiet/Decrease verbosity", + "-v Increase verbosity", + "-x TEST Exclude tests with TEST in the name", + ], + } + }, ] def runner_test(test, runner, expected, test_defines, cmdline_args, features)