Skip to content

Commit

Permalink
add strict match option as '-n' again.
Browse files Browse the repository at this point in the history
fix style while I'm at it.
  • Loading branch information
mvandervoord committed Jun 13, 2024
1 parent 5659085 commit 18fb339
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 47 deletions.
2 changes: 1 addition & 1 deletion auto/generate_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def files_to_operate_on(module_name, pattern = nil)
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
}
Expand Down
6 changes: 3 additions & 3 deletions auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def find_tests(source)
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|
Expand Down Expand Up @@ -240,8 +240,8 @@ def create_header(output, mocks, testfile_includes = [])
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 */")
@options[:defines].each do |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
Expand Down
7 changes: 1 addition & 6 deletions auto/stylize_as_junit.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#!/usr/bin/ruby
# =========================================================================
# Unity - A Test Framework for C
# ThrowTheSwitch.org
# Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
# 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
Expand Down
2 changes: 1 addition & 1 deletion docs/UnityHelperScriptsGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
43 changes: 28 additions & 15 deletions src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -2271,13 +2271,15 @@ int UnityEnd(void)
char* UnityOptionIncludeNamed = NULL;
char* UnityOptionExcludeNamed = NULL;
int UnityVerbosity = 1;
int UnityStrictMatch = 0;

/*-----------------------------------------------*/
int UnityParseOptions(int argc, char** argv)
{
int i;
UnityOptionIncludeNamed = NULL;
UnityOptionExcludeNamed = NULL;
UnityStrictMatch = 0;

for (i = 1; i < argc; i++)
{
Expand All @@ -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];
Expand Down Expand Up @@ -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();
Expand All @@ -2359,7 +2362,7 @@ static int IsStringInBiggerString(const char* longstring, const char* shortstrin

if (*sptr == '*')
{
return 1;
return UnityStrictMatch ? 0 : 1;
}

while (*lptr)
Expand All @@ -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 == ':')
return 2;
if (*sptr == 0)
return 1;
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;

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 */
Expand Down
84 changes: 63 additions & 21 deletions test/tests/test_generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n test_",
:cmdline_args => "-f test_",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'test_NotBeConfusedByLongComplicatedStrings',
Expand All @@ -758,7 +758,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n should_",
:cmdline_args => "-f should_",
:expected => {
:to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
:to_fail => [ ],
Expand All @@ -772,7 +772,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n should_,test_",
:cmdline_args => "-f should_,test_",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'test_NotBeConfusedByLongComplicatedStrings',
Expand All @@ -790,7 +790,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n=testRunnerGeneratorSma*",
:cmdline_args => "-f=testRunnerGeneratorSma*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
Expand All @@ -806,7 +806,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:*",
:cmdline_args => "-f testRunnerGeneratorSmall:*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
Expand All @@ -822,7 +822,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:test_*",
:cmdline_args => "-f testRunnerGeneratorSmall:test_*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
Expand All @@ -836,7 +836,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSmall:te*",
:cmdline_args => "-f testRunnerGeneratorSmall:te*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ 'test_ThisTestAlwaysFails' ],
Expand All @@ -850,7 +850,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGeneratorSm*:*",
:cmdline_args => "-f testRunnerGeneratorSm*:*",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
Expand Down Expand Up @@ -885,7 +885,7 @@
: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',
Expand All @@ -903,7 +903,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n ThisTestAlwaysPasses",
:cmdline_args => "-f ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
Expand All @@ -917,7 +917,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator:ThisTestAlwaysPasses",
:cmdline_args => "-f testRunnerGenerator:ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
Expand All @@ -931,7 +931,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator.c:ThisTestAlwaysPasses",
:cmdline_args => "-f testRunnerGenerator.c:ThisTestAlwaysPasses",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
:to_fail => [ ],
Expand All @@ -945,7 +945,7 @@
: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' ],
Expand All @@ -959,21 +959,63 @@
: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' ],
:to_ignore => [ ],
}
},

{ :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 => [ ],
Expand All @@ -987,7 +1029,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n ThisTestDoesNotExist",
:cmdline_args => "-f ThisTestDoesNotExist",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
Expand Down Expand Up @@ -1015,7 +1057,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n testRunnerGenerator",
:cmdline_args => "-f testRunnerGenerator",
:expected => {
:to_pass => [ 'test_ThisTestAlwaysPasses',
'spec_ThisTestPassesWhenNormalSetupRan',
Expand Down Expand Up @@ -1053,7 +1095,7 @@
:cmdline_args => true,
:test_prefix => "paratest"
},
:cmdline_args => "-n ShouldHandleParameterizedTests",
:cmdline_args => "-f ShouldHandleParameterizedTests",
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
Expand Down Expand Up @@ -1124,7 +1166,7 @@
:options => {
:cmdline_args => true,
},
:cmdline_args => "-n",
:cmdline_args => "-f",
:expected => {
:to_pass => [ ],
:to_fail => [ ],
Expand Down Expand Up @@ -1164,7 +1206,7 @@
"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",
Expand All @@ -1188,7 +1230,7 @@
"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",
Expand Down

0 comments on commit 18fb339

Please sign in to comment.