Skip to content

Commit e4ee687

Browse files
committed
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.
1 parent bf56029 commit e4ee687

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/unity.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,17 @@ int UnityParseOptions(int argc, char** argv)
23292329
UnityPrint("ERROR: Unknown Option ");
23302330
UNITY_OUTPUT_CHAR(argv[i][1]);
23312331
UNITY_PRINT_EOL();
2332+
/* fall-through to display help */
2333+
case 'h':
2334+
UnityPrint("Options: "); UNITY_PRINT_EOL();
2335+
UnityPrint("-l List all tests"); UNITY_PRINT_EOL();
2336+
UnityPrint("-f TEST Only run tests with TEST in the name"); UNITY_PRINT_EOL();
2337+
UnityPrint("-n TEST Only run tests with TEST in the name"); UNITY_PRINT_EOL();
2338+
UnityPrint("-h Show this help menu"); UNITY_PRINT_EOL();
2339+
UnityPrint("-q Quiet/Decrease verbosity"); UNITY_PRINT_EOL();
2340+
UnityPrint("-v Increase verbosity"); UNITY_PRINT_EOL();
2341+
UnityPrint("-x TEST Exclude tests with TEST in the name"); UNITY_PRINT_EOL();
2342+
UNITY_OUTPUT_FLUSH();
23322343
return 1;
23332344
}
23342345
}

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endif
55
ifeq ($(findstring clang, $(CC)), clang)
66
E = -Weverything
77
CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes
8-
CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn
8+
CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn -Wno-covered-switch-default
99
endif
1010
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
1111
#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros

test/tests/test_generate_test_runner.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,43 @@
11581158
:to_pass => [ ],
11591159
:to_fail => [ ],
11601160
:to_ignore => [ ],
1161-
:text => [ "ERROR: Unknown Option z" ],
1161+
:text => [
1162+
"ERROR: Unknown Option z",
1163+
"Options:",
1164+
"-l List all tests",
1165+
"-f TEST Only run tests with TEST in the name",
1166+
"-n TEST Only run tests with TEST in the name",
1167+
"-h Show this help menu",
1168+
"-q Quiet/Decrease verbosity",
1169+
"-v Increase verbosity",
1170+
"-x TEST Exclude tests with TEST in the name",
1171+
],
11621172
}
11631173
},
1174+
1175+
{ :name => 'ArgsHelp',
1176+
:testfile => 'testdata/testRunnerGenerator.c',
1177+
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
1178+
:options => {
1179+
:cmdline_args => true,
1180+
},
1181+
:cmdline_args => "-h",
1182+
:expected => {
1183+
:to_pass => [ ],
1184+
:to_fail => [ ],
1185+
:to_ignore => [ ],
1186+
:text => [
1187+
"Options:",
1188+
"-l List all tests",
1189+
"-f TEST Only run tests with TEST in the name",
1190+
"-n TEST Only run tests with TEST in the name",
1191+
"-h Show this help menu",
1192+
"-q Quiet/Decrease verbosity",
1193+
"-v Increase verbosity",
1194+
"-x TEST Exclude tests with TEST in the name",
1195+
],
1196+
}
1197+
},
11641198
]
11651199

11661200
def runner_test(test, runner, expected, test_defines, cmdline_args, features)

0 commit comments

Comments
 (0)