Skip to content

Commit

Permalink
Add help option to test command line args
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Skinner927 committed Dec 2, 2023
1 parent bf56029 commit 97d2f6e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("Help: "); 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;
}
}
Expand Down
36 changes: 35 additions & 1 deletion test/tests/test_generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,43 @@
:to_pass => [ ],
:to_fail => [ ],
:to_ignore => [ ],
:text => [ "ERROR: Unknown Option z" ],
:text => [
"ERROR: Unknown Option z",
"Help:",
"-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 => [
"Help:",
"-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)
Expand Down

0 comments on commit 97d2f6e

Please sign in to comment.