Skip to content

Commit 18fb339

Browse files
committed
add strict match option as '-n' again.
fix style while I'm at it.
1 parent 5659085 commit 18fb339

File tree

6 files changed

+97
-47
lines changed

6 files changed

+97
-47
lines changed

auto/generate_module.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def files_to_operate_on(module_name, pattern = nil)
160160
boilerplate: cfg[:boilerplate],
161161
includes: case (cfg[:inc])
162162
when :src then (@options[:includes][:src] || []) | (pattern_traits[:inc].map { |f| format(f, module_name) })
163-
when :inc then (@options[:includes][:inc] || [])
163+
when :inc then @options[:includes][:inc] || []
164164
when :tst then (@options[:includes][:tst] || []) | (pattern_traits[:inc].map { |f| format("#{@options[:mock_prefix]}#{f}", module_name) })
165165
end
166166
}

auto/generate_test_runner.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def find_tests(source)
171171
arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
172172

173173
args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
174-
("#{arg_values_str},").scan(arg_elements_regex)
174+
"#{arg_values_str},".scan(arg_elements_regex)
175175
end.reduce do |result, arg_range_expanded|
176176
result.product(arg_range_expanded)
177177
end.map do |arg_combinations|
@@ -240,8 +240,8 @@ def create_header(output, mocks, testfile_includes = [])
240240
output.puts('#include "cmock.h"') unless mocks.empty?
241241
output.puts('}') if @options[:externcincludes]
242242
if @options[:defines] && !@options[:defines].empty?
243-
output.puts("/* injected defines for unity settings, etc */")
244-
@options[:defines].each do |d|
243+
output.puts('/* injected defines for unity settings, etc */')
244+
@options[:defines].each do |d|
245245
def_only = d.match(/(\w+).*/)[1]
246246
output.puts("#ifndef #{def_only}\n#define #{d}\n#endif /* #{def_only} */")
247247
end

auto/stylize_as_junit.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1+
#!/usr/bin/ruby
12
# =========================================================================
23
# Unity - A Test Framework for C
34
# ThrowTheSwitch.org
45
# Copyright (c) 2007-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
56
# SPDX-License-Identifier: MIT
67
# =========================================================================
78

8-
#!/usr/bin/ruby
9-
#
10-
# unity_to_junit.rb
11-
#
129
require 'fileutils'
1310
require 'optparse'
1411
require 'ostruct'
1512
require 'set'
1613

17-
require 'pp'
18-
1914
VERSION = 1.0
2015

2116
class ArgvParser

docs/UnityHelperScriptsGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ These are the available options:
225225
| --------- | ------------------------------------------------- |
226226
| `-l` | List all tests and exit |
227227
| `-f NAME` | Filter to run only tests whose name includes NAME |
228-
| `-n NAME` | (deprecated) alias of -f |
228+
| `-n NAME` | Run only the test named NAME |
229229
| `-h` | show the Help menu that lists these options |
230230
| `-q` | Quiet/decrease verbosity |
231231
| `-v` | increase Verbosity |

src/unity.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,13 +2271,15 @@ int UnityEnd(void)
22712271
char* UnityOptionIncludeNamed = NULL;
22722272
char* UnityOptionExcludeNamed = NULL;
22732273
int UnityVerbosity = 1;
2274+
int UnityStrictMatch = 0;
22742275

22752276
/*-----------------------------------------------*/
22762277
int UnityParseOptions(int argc, char** argv)
22772278
{
22782279
int i;
22792280
UnityOptionIncludeNamed = NULL;
22802281
UnityOptionExcludeNamed = NULL;
2282+
UnityStrictMatch = 0;
22812283

22822284
for (i = 1; i < argc; i++)
22832285
{
@@ -2289,6 +2291,7 @@ int UnityParseOptions(int argc, char** argv)
22892291
return -1;
22902292
case 'n': /* include tests with name including this string */
22912293
case 'f': /* an alias for -n */
2294+
UnityStrictMatch = (argv[i][1] == 'n'); /* strictly match this string if -n */
22922295
if (argv[i][2] == '=')
22932296
{
22942297
UnityOptionIncludeNamed = &argv[i][3];
@@ -2336,7 +2339,7 @@ int UnityParseOptions(int argc, char** argv)
23362339
UnityPrint("Options: "); UNITY_PRINT_EOL();
23372340
UnityPrint("-l List all tests and exit"); UNITY_PRINT_EOL();
23382341
UnityPrint("-f NAME Filter to run only tests whose name includes NAME"); UNITY_PRINT_EOL();
2339-
UnityPrint("-n NAME (deprecated) alias of -f"); UNITY_PRINT_EOL();
2342+
UnityPrint("-n NAME Run only the test named NAME"); UNITY_PRINT_EOL();
23402343
UnityPrint("-h show this Help menu"); UNITY_PRINT_EOL();
23412344
UnityPrint("-q Quiet/decrease verbosity"); UNITY_PRINT_EOL();
23422345
UnityPrint("-v increase Verbosity"); UNITY_PRINT_EOL();
@@ -2359,7 +2362,7 @@ static int IsStringInBiggerString(const char* longstring, const char* shortstrin
23592362

23602363
if (*sptr == '*')
23612364
{
2362-
return 1;
2365+
return UnityStrictMatch ? 0 : 1;
23632366
}
23642367

23652368
while (*lptr)
@@ -2372,19 +2375,29 @@ static int IsStringInBiggerString(const char* longstring, const char* shortstrin
23722375
lptr++;
23732376
sptr++;
23742377

2375-
/* We're done if we match the entire string or up to a wildcard */
2376-
if (*sptr == '*')
2377-
return 1;
2378-
if (*sptr == ',')
2379-
return 1;
2380-
if (*sptr == '"')
2381-
return 1;
2382-
if (*sptr == '\'')
2383-
return 1;
2384-
if (*sptr == ':')
2385-
return 2;
2386-
if (*sptr == 0)
2387-
return 1;
2378+
switch (*sptr)
2379+
{
2380+
case '*': /* we encountered a wild-card */
2381+
return UnityStrictMatch ? 0 : 1;
2382+
2383+
case ',': /* we encountered the end of match string */
2384+
case '"':
2385+
case '\'':
2386+
case 0:
2387+
return (!UnityStrictMatch || (*lptr == 0)) ? 1 : 0;
2388+
2389+
case ':': /* we encountered the end of a partial match */
2390+
return 2;
2391+
2392+
default:
2393+
break;
2394+
}
2395+
}
2396+
2397+
// If we didn't match and we're on strict matching, we already know we failed
2398+
if (UnityStrictMatch)
2399+
{
2400+
return 0;
23882401
}
23892402

23902403
/* Otherwise we start in the long pointer 1 character further and try again */

test/tests/test_generate_test_runner.rb

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@
740740
:options => {
741741
:cmdline_args => true,
742742
},
743-
:cmdline_args => "-n test_",
743+
:cmdline_args => "-f test_",
744744
:expected => {
745745
:to_pass => [ 'test_ThisTestAlwaysPasses',
746746
'test_NotBeConfusedByLongComplicatedStrings',
@@ -758,7 +758,7 @@
758758
:options => {
759759
:cmdline_args => true,
760760
},
761-
:cmdline_args => "-n should_",
761+
:cmdline_args => "-f should_",
762762
:expected => {
763763
:to_pass => [ 'should_RunTestsStartingWithShouldByDefault' ],
764764
:to_fail => [ ],
@@ -772,7 +772,7 @@
772772
:options => {
773773
:cmdline_args => true,
774774
},
775-
:cmdline_args => "-n should_,test_",
775+
:cmdline_args => "-f should_,test_",
776776
:expected => {
777777
:to_pass => [ 'test_ThisTestAlwaysPasses',
778778
'test_NotBeConfusedByLongComplicatedStrings',
@@ -790,7 +790,7 @@
790790
:options => {
791791
:cmdline_args => true,
792792
},
793-
:cmdline_args => "-n=testRunnerGeneratorSma*",
793+
:cmdline_args => "-f=testRunnerGeneratorSma*",
794794
:expected => {
795795
:to_pass => [ 'test_ThisTestAlwaysPasses',
796796
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -806,7 +806,7 @@
806806
:options => {
807807
:cmdline_args => true,
808808
},
809-
:cmdline_args => "-n testRunnerGeneratorSmall:*",
809+
:cmdline_args => "-f testRunnerGeneratorSmall:*",
810810
:expected => {
811811
:to_pass => [ 'test_ThisTestAlwaysPasses',
812812
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -822,7 +822,7 @@
822822
:options => {
823823
:cmdline_args => true,
824824
},
825-
:cmdline_args => "-n testRunnerGeneratorSmall:test_*",
825+
:cmdline_args => "-f testRunnerGeneratorSmall:test_*",
826826
:expected => {
827827
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
828828
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -836,7 +836,7 @@
836836
:options => {
837837
:cmdline_args => true,
838838
},
839-
:cmdline_args => "-n testRunnerGeneratorSmall:te*",
839+
:cmdline_args => "-f testRunnerGeneratorSmall:te*",
840840
:expected => {
841841
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
842842
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -850,7 +850,7 @@
850850
:options => {
851851
:cmdline_args => true,
852852
},
853-
:cmdline_args => "-n testRunnerGeneratorSm*:*",
853+
:cmdline_args => "-f testRunnerGeneratorSm*:*",
854854
:expected => {
855855
:to_pass => [ 'test_ThisTestAlwaysPasses',
856856
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -885,7 +885,7 @@
885885
:cmdline_args => true,
886886
:includes => ['Defs.h'],
887887
},
888-
:cmdline_args => "-n test_ -x Ignored",
888+
:cmdline_args => "-f test_ -x Ignored",
889889
:expected => {
890890
:to_pass => [ 'test_ThisTestAlwaysPasses',
891891
'test_NotBeConfusedByLongComplicatedStrings',
@@ -903,7 +903,7 @@
903903
:options => {
904904
:cmdline_args => true,
905905
},
906-
:cmdline_args => "-n ThisTestAlwaysPasses",
906+
:cmdline_args => "-f ThisTestAlwaysPasses",
907907
:expected => {
908908
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
909909
:to_fail => [ ],
@@ -917,7 +917,7 @@
917917
:options => {
918918
:cmdline_args => true,
919919
},
920-
:cmdline_args => "-n testRunnerGenerator:ThisTestAlwaysPasses",
920+
:cmdline_args => "-f testRunnerGenerator:ThisTestAlwaysPasses",
921921
:expected => {
922922
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
923923
:to_fail => [ ],
@@ -931,7 +931,7 @@
931931
:options => {
932932
:cmdline_args => true,
933933
},
934-
:cmdline_args => "-n testRunnerGenerator.c:ThisTestAlwaysPasses",
934+
:cmdline_args => "-f testRunnerGenerator.c:ThisTestAlwaysPasses",
935935
:expected => {
936936
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
937937
:to_fail => [ ],
@@ -945,7 +945,7 @@
945945
:options => {
946946
:cmdline_args => true,
947947
},
948-
:cmdline_args => "-n \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
948+
:cmdline_args => "-f \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
949949
:expected => {
950950
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
951951
:to_fail => [ 'test_ThisTestAlwaysFails' ],
@@ -959,21 +959,63 @@
959959
:options => {
960960
:cmdline_args => true,
961961
},
962-
:cmdline_args => "-n 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
962+
:cmdline_args => "-f 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
963963
:expected => {
964964
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
965965
:to_fail => [ 'test_ThisTestAlwaysFails' ],
966966
:to_ignore => [ ],
967967
}
968968
},
969969

970+
{ :name => 'ArgsHandlePreciseMatch',
971+
:testfile => 'testdata/testRunnerGenerator.c',
972+
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
973+
:options => {
974+
:cmdline_args => true,
975+
},
976+
:cmdline_args => "-n 'test_ThisTestAlwaysPasses'",
977+
:expected => {
978+
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
979+
:to_fail => [ ],
980+
:to_ignore => [ ],
981+
}
982+
},
983+
984+
{ :name => 'ArgsHandlePreciseMatches',
985+
:testfile => 'testdata/testRunnerGenerator.c',
986+
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
987+
:options => {
988+
:cmdline_args => true,
989+
},
990+
:cmdline_args => "-n 'test_ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
991+
:expected => {
992+
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
993+
:to_fail => [ 'test_ThisTestAlwaysFails' ],
994+
:to_ignore => [ ],
995+
}
996+
},
997+
998+
{ :name => 'ArgsRequiresPreciseMatchNotPartial',
999+
:testfile => 'testdata/testRunnerGenerator.c',
1000+
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
1001+
:options => {
1002+
:cmdline_args => true,
1003+
},
1004+
:cmdline_args => "-n ThisTestAlwaysPass",
1005+
:expected => {
1006+
:to_pass => [ ],
1007+
:to_fail => [ ],
1008+
:to_ignore => [ ],
1009+
}
1010+
},
1011+
9701012
{ :name => 'ArgsIncludeAValidTestForADifferentFile',
9711013
:testfile => 'testdata/testRunnerGenerator.c',
9721014
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
9731015
:options => {
9741016
:cmdline_args => true,
9751017
},
976-
:cmdline_args => "-n AnotherFile:ThisTestDoesNotExist",
1018+
:cmdline_args => "-f AnotherFile:ThisTestDoesNotExist",
9771019
:expected => {
9781020
:to_pass => [ ],
9791021
:to_fail => [ ],
@@ -987,7 +1029,7 @@
9871029
:options => {
9881030
:cmdline_args => true,
9891031
},
990-
:cmdline_args => "-n ThisTestDoesNotExist",
1032+
:cmdline_args => "-f ThisTestDoesNotExist",
9911033
:expected => {
9921034
:to_pass => [ ],
9931035
:to_fail => [ ],
@@ -1015,7 +1057,7 @@
10151057
:options => {
10161058
:cmdline_args => true,
10171059
},
1018-
:cmdline_args => "-n testRunnerGenerator",
1060+
:cmdline_args => "-f testRunnerGenerator",
10191061
:expected => {
10201062
:to_pass => [ 'test_ThisTestAlwaysPasses',
10211063
'spec_ThisTestPassesWhenNormalSetupRan',
@@ -1053,7 +1095,7 @@
10531095
:cmdline_args => true,
10541096
:test_prefix => "paratest"
10551097
},
1056-
:cmdline_args => "-n ShouldHandleParameterizedTests",
1098+
:cmdline_args => "-f ShouldHandleParameterizedTests",
10571099
:features => [ :parameterized ],
10581100
:expected => {
10591101
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
@@ -1124,7 +1166,7 @@
11241166
:options => {
11251167
:cmdline_args => true,
11261168
},
1127-
:cmdline_args => "-n",
1169+
:cmdline_args => "-f",
11281170
:expected => {
11291171
:to_pass => [ ],
11301172
:to_fail => [ ],
@@ -1164,7 +1206,7 @@
11641206
"Options:",
11651207
"-l List all tests and exit",
11661208
"-f NAME Filter to run only tests whose name includes NAME",
1167-
"-n NAME \\(deprecated\\) alias of -f",
1209+
"-n NAME Run only the test named NAME",
11681210
"-h show this Help menu",
11691211
"-q Quiet/decrease verbosity",
11701212
"-v increase Verbosity",
@@ -1188,7 +1230,7 @@
11881230
"Options:",
11891231
"-l List all tests and exit",
11901232
"-f NAME Filter to run only tests whose name includes NAME",
1191-
"-n NAME \\(deprecated\\) alias of -f",
1233+
"-n NAME Run only the test named NAME",
11921234
"-h show this Help menu",
11931235
"-q Quiet/decrease verbosity",
11941236
"-v increase Verbosity",

0 commit comments

Comments
 (0)