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

add strict match option as '-n' again.

fix style while I'm at it.
This commit is contained in:
Mark VanderVoord
2024-06-12 22:59:08 -04:00
parent 5659085418
commit 18fb33921f
6 changed files with 97 additions and 47 deletions

View File

@@ -160,7 +160,7 @@ class UnityModuleGenerator
boilerplate: cfg[:boilerplate],
includes: case (cfg[:inc])
when :src then (@options[:includes][:src] || []) | (pattern_traits[:inc].map { |f| format(f, module_name) })
when :inc then (@options[:includes][:inc] || [])
when :inc then @options[:includes][:inc] || []
when :tst then (@options[:includes][:tst] || []) | (pattern_traits[:inc].map { |f| format("#{@options[:mock_prefix]}#{f}", module_name) })
end
}

View File

@@ -171,7 +171,7 @@ class UnityTestRunnerGenerator
arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
("#{arg_values_str},").scan(arg_elements_regex)
"#{arg_values_str},".scan(arg_elements_regex)
end.reduce do |result, arg_range_expanded|
result.product(arg_range_expanded)
end.map do |arg_combinations|
@@ -240,7 +240,7 @@ class UnityTestRunnerGenerator
output.puts('#include "cmock.h"') unless mocks.empty?
output.puts('}') if @options[:externcincludes]
if @options[:defines] && !@options[:defines].empty?
output.puts("/* injected defines for unity settings, etc */")
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} */")

View File

@@ -1,3 +1,4 @@
#!/usr/bin/ruby
# =========================================================================
# Unity - A Test Framework for C
# ThrowTheSwitch.org
@@ -5,17 +6,11 @@
# SPDX-License-Identifier: MIT
# =========================================================================
#!/usr/bin/ruby
#
# unity_to_junit.rb
#
require 'fileutils'
require 'optparse'
require 'ostruct'
require 'set'
require 'pp'
VERSION = 1.0
class ArgvParser

View File

@@ -225,7 +225,7 @@ These are the available 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` | Run only the test named NAME |
| `-h` | show the Help menu that lists these options |
| `-q` | Quiet/decrease verbosity |
| `-v` | increase Verbosity |

View File

@@ -2271,6 +2271,7 @@ int UnityEnd(void)
char* UnityOptionIncludeNamed = NULL;
char* UnityOptionExcludeNamed = NULL;
int UnityVerbosity = 1;
int UnityStrictMatch = 0;
/*-----------------------------------------------*/
int UnityParseOptions(int argc, char** argv)
@@ -2278,6 +2279,7 @@ int UnityParseOptions(int argc, char** argv)
int i;
UnityOptionIncludeNamed = NULL;
UnityOptionExcludeNamed = NULL;
UnityStrictMatch = 0;
for (i = 1; i < argc; i++)
{
@@ -2289,6 +2291,7 @@ int UnityParseOptions(int argc, char** argv)
return -1;
case 'n': /* include tests with name including this string */
case 'f': /* an alias for -n */
UnityStrictMatch = (argv[i][1] == 'n'); /* strictly match this string if -n */
if (argv[i][2] == '=')
{
UnityOptionIncludeNamed = &argv[i][3];
@@ -2336,7 +2339,7 @@ int UnityParseOptions(int argc, char** argv)
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("-n NAME Run only the test named 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();
@@ -2359,7 +2362,7 @@ static int IsStringInBiggerString(const char* longstring, const char* shortstrin
if (*sptr == '*')
{
return 1;
return UnityStrictMatch ? 0 : 1;
}
while (*lptr)
@@ -2372,19 +2375,29 @@ static int IsStringInBiggerString(const char* longstring, const char* shortstrin
lptr++;
sptr++;
/* We're done if we match the entire string or up to a wildcard */
if (*sptr == '*')
return 1;
if (*sptr == ',')
return 1;
if (*sptr == '"')
return 1;
if (*sptr == '\'')
return 1;
if (*sptr == ':')
switch (*sptr)
{
case '*': /* we encountered a wild-card */
return UnityStrictMatch ? 0 : 1;
case ',': /* we encountered the end of match string */
case '"':
case '\'':
case 0:
return (!UnityStrictMatch || (*lptr == 0)) ? 1 : 0;
case ':': /* we encountered the end of a partial match */
return 2;
if (*sptr == 0)
return 1;
default:
break;
}
}
// If we didn't match and we're on strict matching, we already know we failed
if (UnityStrictMatch)
{
return 0;
}
/* Otherwise we start in the long pointer 1 character further and try again */

View File

@@ -740,7 +740,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n test_",
:cmdline_args => "-f test_",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'test_NotBeConfusedByLongComplicatedStrings',
@@ -758,7 +758,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n should_",
:cmdline_args => "-f should_",
:expected => {
:to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
:to_fail => [ ],
@@ -772,7 +772,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n should_,test_",
:cmdline_args => "-f should_,test_",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'test_NotBeConfusedByLongComplicatedStrings',
@@ -790,7 +790,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n=testRunnerGeneratorSma*",
:cmdline_args => "-f=testRunnerGeneratorSma*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -806,7 +806,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:*",
:cmdline_args => "-f testRunnerGeneratorSmall:*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -822,7 +822,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:test_*",
:cmdline_args => "-f testRunnerGeneratorSmall:test_*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -836,7 +836,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:te*",
:cmdline_args => "-f testRunnerGeneratorSmall:te*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -850,7 +850,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSm*:*",
:cmdline_args => "-f testRunnerGeneratorSm*:*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -885,7 +885,7 @@ RUNNER_TESTS = [
:cmdline_args => true,
:includes => ['Defs.h'],
},
:cmdline_args => "-n test_ -x Ignored",
:cmdline_args => "-f test_ -x Ignored",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'test_NotBeConfusedByLongComplicatedStrings',
@@ -903,7 +903,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n ThisTestAlwaysPasses",
:cmdline_args => "-f ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
@@ -917,7 +917,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator:ThisTestAlwaysPasses",
:cmdline_args => "-f testRunnerGenerator:ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
@@ -931,7 +931,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator.c:ThisTestAlwaysPasses",
:cmdline_args => "-f testRunnerGenerator.c:ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
@@ -945,7 +945,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
:cmdline_args => "-f \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -959,7 +959,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
:cmdline_args => "-f 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -967,13 +967,55 @@ RUNNER_TESTS = [
}
},
{ :name => 'ArgsHandlePreciseMatch',
:testfile => 'testdata/testRunnerGenerator.c',
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n 'test_ThisTestAlwaysPasses'",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
:to_ignore => [ ],
}
},
{ :name => 'ArgsHandlePreciseMatches',
:testfile => 'testdata/testRunnerGenerator.c',
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n 'test_ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
:to_ignore => [ ],
}
},
{ :name => 'ArgsRequiresPreciseMatchNotPartial',
:testfile => 'testdata/testRunnerGenerator.c',
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n ThisTestAlwaysPass",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
:to_ignore => [ ],
}
},
{ :name => 'ArgsIncludeAValidTestForADifferentFile',
:testfile => 'testdata/testRunnerGenerator.c',
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n AnotherFile:ThisTestDoesNotExist",
:cmdline_args => "-f AnotherFile:ThisTestDoesNotExist",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
@@ -987,7 +1029,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n ThisTestDoesNotExist",
:cmdline_args => "-f ThisTestDoesNotExist",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
@@ -1015,7 +1057,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator",
:cmdline_args => "-f testRunnerGenerator",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -1053,7 +1095,7 @@ RUNNER_TESTS = [
:cmdline_args => true,
:test_prefix => "paratest"
},
:cmdline_args => "-n ShouldHandleParameterizedTests",
:cmdline_args => "-f ShouldHandleParameterizedTests",
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
@@ -1124,7 +1166,7 @@ RUNNER_TESTS = [
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n",
:cmdline_args => "-f",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
@@ -1164,7 +1206,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 Run only the test named NAME",
"-h show this Help menu",
"-q Quiet/decrease verbosity",
"-v increase Verbosity",
@@ -1188,7 +1230,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 Run only the test named NAME",
"-h show this Help menu",
"-q Quiet/decrease verbosity",
"-v increase Verbosity",