1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

12 Commits

Author SHA1 Message Date
Mark VanderVoord
860062d51b Fixed issue #715 (typo that disabled two tests) 2024-03-09 19:36:15 -05:00
Mark VanderVoord
e3457a85f4 Fix temperamental test in core test suite. 2024-03-09 19:26:38 -05:00
Mark VanderVoord
b512a1c184 Flesh out documentation for command line options for runner generator. 2024-03-09 18:50:25 -05:00
Mark VanderVoord
2777955d3a Document unity exec time options. 2024-03-09 18:28:42 -05:00
Mark VanderVoord
64939db64e generate test runner: clean injected defines so the ifndef doesn't use the assignment when it exists. 2024-01-19 11:44:48 -05:00
Mark VanderVoord
b4f65573f7 Bump rubocop version 2024-01-04 16:57:45 -05:00
Mark VanderVoord
da5a45ba1c Merge pull request #706 from Skinner927/add-help-to-test-binaries
Add help option to test command line args
2023-12-04 14:10:11 -05:00
Dennis Skinner
3adb5dd7b9 Add FALLTHRU 2023-12-04 14:04:13 -05:00
Dennis Skinner
4a606dc2cd Add missing generate_test_runner.rb options to docs 2023-12-03 23:02:23 -05:00
Dennis Skinner
049ddda615 Fix tests for new help verbiage 2023-12-03 23:02:09 -05:00
Dennis Skinner
fcb4e53c36 Update help menu to use mnemonics 2023-12-03 22:07:15 -05:00
Dennis Skinner
985f6e0194 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.
2023-12-02 03:05:33 -05:00
10 changed files with 170 additions and 8 deletions

View File

@@ -23,7 +23,7 @@ jobs:
- name: Setup Ruby Testing Tools
run: |
sudo gem install rspec
sudo gem install rubocop -v 0.57.2
sudo gem install rubocop -v 1.57.2
# Checks out repository under $GITHUB_WORKSPACE
- name: Checkout Latest Repo

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) <year> 2007-23 Mike Karlesky, Mark VanderVoord, Greg Williams
Copyright (c) <year> 2007-24 Mike Karlesky, Mark VanderVoord, Greg Williams
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -239,7 +239,11 @@ class UnityTestRunnerGenerator
output.puts('#include "cmock.h"') unless mocks.empty?
output.puts('}') if @options[:externcincludes]
if @options[:defines] && !@options[:defines].empty?
@options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") }
output.puts("/* injected defines for unity settings, etc */")
@options[:defines].each do |d|
def_only = d.match(/(\w+).*/)[1]
output.puts("#ifndef #{def_only}\n#define #{d}\n#endif /* #{def_only} */")
end
end
if @options[:header_file] && !@options[:header_file].empty?
output.puts("#include \"#{File.basename(@options[:header_file])}\"")

View File

@@ -482,6 +482,34 @@ _Example:_
#define UNITY_OUTPUT_COLOR
```
#### `UNITY_INCLUDE_EXEC_TIME`
Define this to measure and report execution time for each test in the suite. When enabled, Unity will do
it's best to automatically find a way to determine the time in milliseconds. On most Windows, macos, or
Linux environments, this is automatic. If not, you can give Unity more information.
#### `UNITY_CLOCK_MS`
If you're working on a system (embedded or otherwise) which has an accessible millisecond timer. You can
define `UNITY_CLOCK_MS` to be the name of the function which returns the millisecond timer. It will then
attempt to use that function for timing purposes.
#### `UNITY_EXEC_TIME_START`
Define this hook to start a millisecond timer if necessary.
#### `UNITY_EXEC_TIME_STOP`
Define this hook to stop a millisecond timer if necessary.
#### `UNITY_PRINT_EXEC_TIME`
Define this hook to print the current execution time. Used to report the milliseconds elapsed.
#### `UNITY_TIME_TYPE`
Finally, this can be set to the type which holds the millisecond timer.
#### `UNITY_SHORTHAND_AS_INT`
#### `UNITY_SHORTHAND_AS_MEM`

View File

@@ -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.
@@ -121,6 +126,8 @@ Define this option with C code to be executed _before any_ test cases are run.
Alternatively, if your C compiler supports weak symbols, you can leave this option unset and instead provide a `void suiteSetUp(void)` function in your test suite.
The linker will look for this symbol and fall back to a Unity-provided stub if it is not found.
This option can also be specified at the command prompt as `--suite_setup=""`
##### `:suite_teardown`
Define this option with C code to be executed _after all_ test cases have finished.
@@ -131,6 +138,8 @@ You can normally just return `num_failures`.
Alternatively, if your C compiler supports weak symbols, you can leave this option unset and instead provide a `int suiteTearDown(int num_failures)` function in your test suite.
The linker will look for this symbol and fall back to a Unity-provided stub if it is not found.
This option can also be specified at the command prompt as `--suite_teardown=""`
##### `:enforce_strict_ordering`
This option should be defined if you have the strict order feature enabled in CMock (see CMock documentation).
@@ -141,6 +150,8 @@ If you provide the same YAML to the generator as used in CMock's configuration,
This option should be defined if you are mixing C and CPP and want your test runners to automatically include extern "C" support when they are generated.
This option can also be specified at the command prompt as `--externc`
##### `:mock_prefix` and `:mock_suffix`
Unity automatically generates calls to Init, Verify and Destroy for every file included in the main test file that starts with the given mock prefix and ends with the given mock suffix, file extension not included.
@@ -165,8 +176,11 @@ Or as a yaml file:
If you are using CMock, it is very likely that you are already passing an array of plugins to CMock.
You can just use the same array here.
This script will just ignore the plugins that don't require additional support.
This option can also be specified at the command prompt as `--cexception`
##### `:include_extensions`
This option specifies the pattern for matching acceptable header file extensions.
@@ -191,7 +205,77 @@ 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.
This option can also be specified at the command prompt as `--use_param_tests=1`
##### `: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.
This option can also be specified at the command prompt as `--setup_name=""`
##### `:teardown_name`
Override the default test `tearDown` function name.
This option can also be specified at the command prompt as `--teardown_name=""`
##### `:test_reset_name`
Override the default test `resetTest` function name.
This option can also be specified at the command prompt as `--test_reset_name=""`
##### `:test_verify_name`
Override the default test `verifyTest` function name.
This option can also be specified at the command prompt as `--test_verify_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)`.
This option can also be specified at the command prompt as `--main_name=""`
##### `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.
This option can also be specified at the command prompt as `--omit_begin_end`
#### Parameterized tests provided macros

View File

@@ -2329,6 +2329,18 @@ int UnityParseOptions(int argc, char** argv)
UnityPrint("ERROR: Unknown Option ");
UNITY_OUTPUT_CHAR(argv[i][1]);
UNITY_PRINT_EOL();
/* Now display help */
/* FALLTHRU */
case 'h':
UnityPrint("Options: "); 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;
}
}

View File

@@ -1158,7 +1158,41 @@ RUNNER_TESTS = [
:to_pass => [ ],
:to_fail => [ ],
:to_ignore => [ ],
:text => [ "ERROR: Unknown Option z" ],
:text => [
"ERROR: Unknown Option z",
"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",
],
}
},
{ :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 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",
],
}
},
]

View File

@@ -61,7 +61,7 @@ void testInt64ArrayWithinDeltaAndMessage(void)
#endif
}
void tesUInt64ArrayNotWithinDelta(void)
void testInt64ArrayNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();

View File

@@ -296,9 +296,9 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
Unity.CurrentTestFailed = 1;
startPutcharSpy(); /* Suppress output */
startFlushSpy();
TEST_ASSERT_EQUAL(0, getFlushSpyCalls());
UnityConcludeTest();
endPutcharSpy();
TEST_ASSERT_EQUAL(0, getFlushSpyCalls());
TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures);
#if defined(UNITY_OUTPUT_FLUSH) && defined(UNITY_OUTPUT_FLUSH_HEADER_DECLARATION)
TEST_ASSERT_EQUAL(1, getFlushSpyCalls());

View File

@@ -61,7 +61,7 @@ void testInt64ArrayWithinDeltaAndMessage(void)
#endif
}
void tesUInt64ArrayNotWithinDelta(void)
void testInt64ArrayNotWithinDelta(void)
{
#ifndef UNITY_SUPPORT_64
TEST_IGNORE();