From 985f6e019472a2165cbae2320eac04f90eb8d226 Mon Sep 17 00:00:00 2001 From: Dennis Skinner Date: Sat, 2 Dec 2023 03:05:32 -0500 Subject: [PATCH 1/5] 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) From fcb4e53c367b8df1053810ed8ed6192ee322e27d Mon Sep 17 00:00:00 2001 From: Dennis Skinner <1518323+Skinner927@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:07:15 -0500 Subject: [PATCH 2/5] Update help menu to use mnemonics --- src/unity.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/unity.c b/src/unity.c index 284f0dc..8b858c9 100644 --- a/src/unity.c +++ b/src/unity.c @@ -2332,13 +2332,13 @@ int UnityParseOptions(int argc, char** argv) /* 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(); + UnityPrint("-l List all tests and exit"); UNITY_PRINT_EOL(); + UnityPrint("-f NAME Filter to run only tests whose name includes NAME"); UNITY_PRINT_EOL(); + UnityPrint("-n NAME (deprecated) alias of -f"); 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 NAME eXclude tests whose name includes NAME"); UNITY_PRINT_EOL(); UNITY_OUTPUT_FLUSH(); return 1; } From 049ddda6156ec4889748805e85328876e322cac4 Mon Sep 17 00:00:00 2001 From: Dennis Skinner <1518323+Skinner927@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:02:09 -0500 Subject: [PATCH 3/5] Fix tests for new help verbiage --- test/tests/test_generate_test_runner.rb | 56 ++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 1d73bf8..0f92a3a 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -1161,40 +1161,40 @@ RUNNER_TESTS = [ :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", + "-l List all tests and exit", + "-f NAME Filter to run only tests whose name includes NAME", + "-n NAME (deprecated) alias of -f", + "-h show this Help menu", + "-q Quiet/decrease verbosity", + "-v increase Verbosity", + "-x NAME eXclude tests whose name includes 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", - ], - } + :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 and exit", + "-f NAME Filter to run only tests whose name includes NAME", + "-n NAME (deprecated) alias of -f", + "-h show this Help menu", + "-q Quiet/decrease verbosity", + "-v increase Verbosity", + "-x NAME eXclude tests whose name includes NAME", + ], + } + }, ] def runner_test(test, runner, expected, test_defines, cmdline_args, features) From 4a606dc2cd47e1fcd8391c45ae6be7fc648346e9 Mon Sep 17 00:00:00 2001 From: Dennis Skinner <1518323+Skinner927@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:58:39 -0500 Subject: [PATCH 4/5] Add missing `generate_test_runner.rb` options to docs --- docs/UnityHelperScriptsGuide.md | 63 ++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/UnityHelperScriptsGuide.md b/docs/UnityHelperScriptsGuide.md index 3c32133..6838280 100644 --- a/docs/UnityHelperScriptsGuide.md +++ b/docs/UnityHelperScriptsGuide.md @@ -114,6 +114,11 @@ In the `examples` directory, Example 3's Rakefile demonstrates using a Ruby hash This option specifies an array of file names to be `#include`'d at the top of your runner C file. You might use it to reference custom types or anything else universally needed in your generated runners. +##### `:defines` + +This option specifies an array of definitions to be `#define`'d at the top of your runner C file. +Each definition will be wrapped in an `#ifndef`. + ##### `:suite_setup` Define this option with C code to be executed _before any_ test cases are run. @@ -191,7 +196,63 @@ Few usage examples can be found in `/test/tests/test_unity_parameterized.c` file You should define `UNITY_SUPPORT_TEST_CASES` macro for tests success compiling, if you enable current option. -You can see list of supported macros list in the next section. +You can see list of supported macros list in the +[Parameterized tests provided macros](#parameterized-tests-provided-macros) +section that follows. + +##### `:cmdline_args` + +When set to `true`, the generated test runner can accept a number of +options to modify how the test(s) are run. + +Ensure Unity is compiled with `UNITY_USE_COMMAND_LINE_ARGS` defined or else +the required functions will not exist. + +These are the available options: + +| Option | Description | +| --------- | ------------------------------------------------- | +| `-l` | List all tests and exit | +| `-f NAME` | Filter to run only tests whose name includes NAME | +| `-n NAME` | (deprecated) alias of -f | +| `-h` | show the Help menu that lists these options | +| `-q` | Quiet/decrease verbosity | +| `-v` | increase Verbosity | +| `-x NAME` | eXclude tests whose name includes NAME | + +##### `:setup_name` + +Override the default test `setUp` function name. + +##### `:teardown_name` + +Override the default test `tearDown` function name. + +##### `:test_reset_name` + +Override the default test `resetTest` function name. + +##### `:test_verify_name` + +Override the default test `verifyTest` function name. + +##### `:main_name` + +Override the test's `main()` function name (from `main` to whatever is specified). +The sentinel value `:auto` will use the test's filename with the `.c` extension removed prefixed +with `main_` as the "main" function. + +To clarify, if `:main_name == :auto` and the test filename is "test_my_project.c", then the +generated function name will be `main_test_my_project(int argc, char** argv)`. + +##### `main_export_decl` + +Provide any `cdecl` for the `main()` test function. Is empty by default. + +##### `:omit_begin_end` + +If `true`, the `UnityBegin` and `UnityEnd` function will not be called for +Unity test state setup and cleanup. #### Parameterized tests provided macros From 3adb5dd7b92bab98ed079f2a4729a6b281b3dbde Mon Sep 17 00:00:00 2001 From: Dennis Skinner <1518323+Skinner927@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:38:50 -0500 Subject: [PATCH 5/5] Add FALLTHRU --- src/unity.c | 3 ++- test/tests/test_generate_test_runner.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/unity.c b/src/unity.c index 8b858c9..b105fa2 100644 --- a/src/unity.c +++ b/src/unity.c @@ -2329,7 +2329,8 @@ int UnityParseOptions(int argc, char** argv) UnityPrint("ERROR: Unknown Option "); UNITY_OUTPUT_CHAR(argv[i][1]); UNITY_PRINT_EOL(); - /* fall-through to display help */ + /* Now display help */ + /* FALLTHRU */ case 'h': UnityPrint("Options: "); UNITY_PRINT_EOL(); UnityPrint("-l List all tests and exit"); UNITY_PRINT_EOL(); diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 0f92a3a..229b6ab 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -1163,7 +1163,7 @@ RUNNER_TESTS = [ "Options:", "-l List all tests and exit", "-f NAME Filter to run only tests whose name includes NAME", - "-n NAME (deprecated) alias of -f", + "-n NAME \\(deprecated\\) alias of -f", "-h show this Help menu", "-q Quiet/decrease verbosity", "-v increase Verbosity", @@ -1187,7 +1187,7 @@ RUNNER_TESTS = [ "Options:", "-l List all tests and exit", "-f NAME Filter to run only tests whose name includes NAME", - "-n NAME (deprecated) alias of -f", + "-n NAME \\(deprecated\\) alias of -f", "-h show this Help menu", "-q Quiet/decrease verbosity", "-v increase Verbosity",