Skip to content

Commit ef7f968

Browse files
authored
Merge branch 'ThrowTheSwitch:master' into dev/gen-testrunner-use-begin-end-macro
2 parents 3911b01 + 64939db commit ef7f968

File tree

5 files changed

+115
-4
lines changed

5 files changed

+115
-4
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup Ruby Testing Tools
2424
run: |
2525
sudo gem install rspec
26-
sudo gem install rubocop -v 0.57.2
26+
sudo gem install rubocop -v 1.57.2
2727
2828
# Checks out repository under $GITHUB_WORKSPACE
2929
- name: Checkout Latest Repo

auto/generate_test_runner.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ def create_header(output, mocks, testfile_includes = [])
239239
output.puts('#include "cmock.h"') unless mocks.empty?
240240
output.puts('}') if @options[:externcincludes]
241241
if @options[:defines] && !@options[:defines].empty?
242-
@options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") }
242+
output.puts("/* injected defines for unity settings, etc */")
243+
@options[:defines].each do |d|
244+
def_only = d.match(/(\w+).*/)[1]
245+
output.puts("#ifndef #{def_only}\n#define #{d}\n#endif /* #{def_only} */")
246+
end
243247
end
244248
if @options[:header_file] && !@options[:header_file].empty?
245249
output.puts("#include \"#{File.basename(@options[:header_file])}\"")

docs/UnityHelperScriptsGuide.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ In the `examples` directory, Example 3's Rakefile demonstrates using a Ruby hash
114114
This option specifies an array of file names to be `#include`'d at the top of your runner C file.
115115
You might use it to reference custom types or anything else universally needed in your generated runners.
116116

117+
##### `:defines`
118+
119+
This option specifies an array of definitions to be `#define`'d at the top of your runner C file.
120+
Each definition will be wrapped in an `#ifndef`.
121+
117122
##### `:suite_setup`
118123

119124
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
191196
You should define `UNITY_SUPPORT_TEST_CASES` macro for tests success compiling,
192197
if you enable current option.
193198

194-
You can see list of supported macros list in the next section.
199+
You can see list of supported macros list in the
200+
[Parameterized tests provided macros](#parameterized-tests-provided-macros)
201+
section that follows.
202+
203+
##### `:cmdline_args`
204+
205+
When set to `true`, the generated test runner can accept a number of
206+
options to modify how the test(s) are run.
207+
208+
Ensure Unity is compiled with `UNITY_USE_COMMAND_LINE_ARGS` defined or else
209+
the required functions will not exist.
210+
211+
These are the available options:
212+
213+
| Option | Description |
214+
| --------- | ------------------------------------------------- |
215+
| `-l` | List all tests and exit |
216+
| `-f NAME` | Filter to run only tests whose name includes NAME |
217+
| `-n NAME` | (deprecated) alias of -f |
218+
| `-h` | show the Help menu that lists these options |
219+
| `-q` | Quiet/decrease verbosity |
220+
| `-v` | increase Verbosity |
221+
| `-x NAME` | eXclude tests whose name includes NAME |
222+
223+
##### `:setup_name`
224+
225+
Override the default test `setUp` function name.
226+
227+
##### `:teardown_name`
228+
229+
Override the default test `tearDown` function name.
230+
231+
##### `:test_reset_name`
232+
233+
Override the default test `resetTest` function name.
234+
235+
##### `:test_verify_name`
236+
237+
Override the default test `verifyTest` function name.
238+
239+
##### `:main_name`
240+
241+
Override the test's `main()` function name (from `main` to whatever is specified).
242+
The sentinel value `:auto` will use the test's filename with the `.c` extension removed prefixed
243+
with `main_` as the "main" function.
244+
245+
To clarify, if `:main_name == :auto` and the test filename is "test_my_project.c", then the
246+
generated function name will be `main_test_my_project(int argc, char** argv)`.
247+
248+
##### `main_export_decl`
249+
250+
Provide any `cdecl` for the `main()` test function. Is empty by default.
251+
252+
##### `:omit_begin_end`
253+
254+
If `true`, the `UnityBegin` and `UnityEnd` function will not be called for
255+
Unity test state setup and cleanup.
195256

196257
#### Parameterized tests provided macros
197258

src/unity.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,18 @@ int UnityParseOptions(int argc, char** argv)
23292329
UnityPrint("ERROR: Unknown Option ");
23302330
UNITY_OUTPUT_CHAR(argv[i][1]);
23312331
UNITY_PRINT_EOL();
2332+
/* Now display help */
2333+
/* FALLTHRU */
2334+
case 'h':
2335+
UnityPrint("Options: "); UNITY_PRINT_EOL();
2336+
UnityPrint("-l List all tests and exit"); UNITY_PRINT_EOL();
2337+
UnityPrint("-f NAME Filter to run only tests whose name includes NAME"); UNITY_PRINT_EOL();
2338+
UnityPrint("-n NAME (deprecated) alias of -f"); UNITY_PRINT_EOL();
2339+
UnityPrint("-h show this Help menu"); UNITY_PRINT_EOL();
2340+
UnityPrint("-q Quiet/decrease verbosity"); UNITY_PRINT_EOL();
2341+
UnityPrint("-v increase Verbosity"); UNITY_PRINT_EOL();
2342+
UnityPrint("-x NAME eXclude tests whose name includes NAME"); UNITY_PRINT_EOL();
2343+
UNITY_OUTPUT_FLUSH();
23322344
return 1;
23332345
}
23342346
}

test/tests/test_generate_test_runner.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,41 @@
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 and exit",
1165+
"-f NAME Filter to run only tests whose name includes NAME",
1166+
"-n NAME \\(deprecated\\) alias of -f",
1167+
"-h show this Help menu",
1168+
"-q Quiet/decrease verbosity",
1169+
"-v increase Verbosity",
1170+
"-x NAME eXclude tests whose name includes NAME",
1171+
],
1172+
}
1173+
},
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 and exit",
1189+
"-f NAME Filter to run only tests whose name includes NAME",
1190+
"-n NAME \\(deprecated\\) alias of -f",
1191+
"-h show this Help menu",
1192+
"-q Quiet/decrease verbosity",
1193+
"-v increase Verbosity",
1194+
"-x NAME eXclude tests whose name includes NAME",
1195+
],
11621196
}
11631197
},
11641198
]

0 commit comments

Comments
 (0)