Skip to content

Commit bf56029

Browse files
authored
Merge pull request #656 from ThrowTheSwitch/platform_matrix
unity 2.6 release candidate
2 parents 8b0daf1 + a1b1600 commit bf56029

21 files changed

+262
-121
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
unit-tests:
1616
name: "Unit Tests"
1717
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
ruby: ['2.7', '3.0', '3.1', '3.2']
1821
steps:
1922
# Install Ruby Testing Tools
2023
- name: Setup Ruby Testing Tools

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) <year> 2007-21 Mike Karlesky, Mark VanderVoord, Greg Williams
3+
Copyright (c) <year> 2007-23 Mike Karlesky, Mark VanderVoord, Greg Williams
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unity Test ![CI][]
22

3-
__Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
3+
__Copyright (c) 2007 - 2023 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
44

55
Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.org.
66
Unity Test is a unit testing framework built for C, with a focus on working with embedded toolchains.
@@ -12,6 +12,8 @@ If you'd like to leave the hard work to us, you might be interested in Ceedling,
1212

1313
If you're new to Unity, we encourage you to tour the [getting started guide][].
1414

15+
You can also find the [change log][] and [known issues][] in our documentation.
16+
1517
## Getting Started
1618

1719
The [docs][] folder contains a [getting started guide][] and much more tips about using Unity.
@@ -54,7 +56,7 @@ The message is output stating why.
5456

5557
Compare two integers for equality and display errors as signed integers.
5658
A cast will be performed to your natural integer size so often this can just be used.
57-
When you need to specify the exact size, like when comparing arrays, you can use a specific version:
59+
When you need to specify the exact size, you can use a specific version.
5860

5961
TEST_ASSERT_EQUAL_UINT(expected, actual)
6062
TEST_ASSERT_EQUAL_UINT8(expected, actual)
@@ -72,7 +74,8 @@ Like INT, there are variants for different sizes also.
7274
TEST_ASSERT_EQUAL_HEX64(expected, actual)
7375

7476
Compares two integers for equality and display errors as hexadecimal.
75-
Like the other integer comparisons, you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16` will show 4 nibbles).
77+
Like the other integer comparisons, you can specify the size...
78+
here the size will also effect how many nibbles are shown (for example, `HEX16` will show 4 nibbles).
7679

7780
TEST_ASSERT_EQUAL(expected, actual)
7881

@@ -214,7 +217,8 @@ Fails if the pointer is equal to NULL
214217
TEST_ASSERT_EQUAL_MEMORY(expected, actual, len)
215218

216219
Compare two blocks of memory.
217-
This is a good generic assertion for types that can't be coerced into acting like standard types... but since it's a memory compare, you have to be careful that your data types are packed.
220+
This is a good generic assertion for types that can't be coerced into acting like standard types...
221+
but since it's a memory compare, you have to be careful that your data types are packed.
218222

219223
### \_MESSAGE
220224

@@ -224,5 +228,7 @@ This is useful for specifying more information about the problem.
224228

225229
[CI]: https://github.com/ThrowTheSwitch/Unity/workflows/CI/badge.svg
226230
[getting started guide]: docs/UnityGettingStartedGuide.md
231+
[change log]: docs/UnityChangeLog.md
232+
[known issues]: docs/UnityKnownIssues.md
227233
[docs]: docs/
228234
[UnityAssertionsReference.md]: docs/UnityAssertionsReference.md

auto/colour_reporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def report(message)
1212
if !$colour_output
1313
$stdout.puts(message)
1414
else
15-
message = message.join('\n') if message.class == Array
15+
message = message.join('\n') if message.instance_of?(Array)
1616
message.each_line do |line|
1717
line.chomp!
1818
colour = case line

auto/generate_module.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
require 'pathname'
1414

1515
# TEMPLATE_TST
16-
TEMPLATE_TST ||= '#ifdef TEST
16+
TEMPLATE_TST ||= '#ifdef %5$s
1717
1818
#include "unity.h"
1919
@@ -32,7 +32,7 @@
3232
TEST_IGNORE_MESSAGE("Need to Implement %1$s");
3333
}
3434
35-
#endif // TEST
35+
#endif // %5$s
3636
'.freeze
3737

3838
# TEMPLATE_SRC
@@ -108,7 +108,8 @@ def self.default_options
108108
update_svn: false,
109109
boilerplates: {},
110110
test_prefix: 'Test',
111-
mock_prefix: 'Mock'
111+
mock_prefix: 'Mock',
112+
test_define: 'TEST'
112113
}
113114
end
114115

@@ -132,9 +133,9 @@ def files_to_operate_on(module_name, pattern = nil)
132133

133134
# create triad definition
134135
prefix = @options[:test_prefix] || 'Test'
135-
triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] },
136+
triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] },
136137
{ ext: '.h', path: @options[:path_inc], prefix: '', template: TEMPLATE_INC, inc: :inc, boilerplate: @options[:boilerplates][:inc] },
137-
{ ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst] }]
138+
{ ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst], test_define: @options[:test_define] }]
138139

139140
# prepare the pattern for use
140141
pattern = (pattern || @options[:pattern] || 'src').downcase
@@ -154,6 +155,7 @@ def files_to_operate_on(module_name, pattern = nil)
154155
path: (Pathname.new("#{cfg[:path]}#{subfolder}") + filename).cleanpath,
155156
name: submodule_name,
156157
template: cfg[:template],
158+
test_define: cfg[:test_define],
157159
boilerplate: cfg[:boilerplate],
158160
includes: case (cfg[:inc])
159161
when :src then (@options[:includes][:src] || []) | (pattern_traits[:inc].map { |f| format(f, module_name) })
@@ -168,18 +170,19 @@ def files_to_operate_on(module_name, pattern = nil)
168170
end
169171

170172
############################
171-
def neutralize_filename(name, start_cap = true)
173+
def neutralize_filename(name, start_cap: true)
172174
return name if name.empty?
175+
173176
name = name.split(/(?:\s+|_|(?=[A-Z][a-z]))|(?<=[a-z])(?=[A-Z])/).map(&:capitalize).join('_')
174-
name = name[0].downcase + name[1..-1] unless start_cap
177+
name = name[0].downcase + name[1..] unless start_cap
175178
name
176179
end
177180

178181
############################
179182
def create_filename(part1, part2 = '')
180-
name = part2.empty? ? part1 : part1 + '_' + part2
183+
name = part2.empty? ? part1 : "#{part1}_#{part2}"
181184
case (@options[:naming])
182-
when 'bumpy' then neutralize_filename(name, false).delete('_')
185+
when 'bumpy' then neutralize_filename(name, start_cap: false).delete('_')
183186
when 'camel' then neutralize_filename(name).delete('_')
184187
when 'snake' then neutralize_filename(name).downcase
185188
when 'caps' then neutralize_filename(name).upcase
@@ -212,7 +215,8 @@ def generate(module_name, pattern = nil)
212215
f.write(file[:template] % [file[:name],
213216
file[:includes].map { |ff| "#include \"#{ff}\"\n" }.join,
214217
file[:name].upcase.tr('-', '_'),
215-
file[:name].tr('-', '_')])
218+
file[:name].tr('-', '_'),
219+
file[:test_define]])
216220
end
217221
if @options[:update_svn]
218222
`svn add \"#{file[:path]}\"`
@@ -260,12 +264,12 @@ def destroy(module_name, pattern = nil)
260264
case arg
261265
when /^-d/ then destroy = true
262266
when /^-u/ then options[:update_svn] = true
263-
when /^-p\"?(\w+)\"?/ then options[:pattern] = Regexp.last_match(1)
264-
when /^-s\"?(.+)\"?/ then options[:path_src] = Regexp.last_match(1)
265-
when /^-i\"?(.+)\"?/ then options[:path_inc] = Regexp.last_match(1)
266-
when /^-t\"?(.+)\"?/ then options[:path_tst] = Regexp.last_match(1)
267-
when /^-n\"?(.+)\"?/ then options[:naming] = Regexp.last_match(1)
268-
when /^-y\"?(.+)\"?/ then options = UnityModuleGenerator.grab_config(Regexp.last_match(1))
267+
when /^-p"?(\w+)"?/ then options[:pattern] = Regexp.last_match(1)
268+
when /^-s"?(.+)"?/ then options[:path_src] = Regexp.last_match(1)
269+
when /^-i"?(.+)"?/ then options[:path_inc] = Regexp.last_match(1)
270+
when /^-t"?(.+)"?/ then options[:path_tst] = Regexp.last_match(1)
271+
when /^-n"?(.+)"?/ then options[:naming] = Regexp.last_match(1)
272+
when /^-y"?(.+)"?/ then options = UnityModuleGenerator.grab_config(Regexp.last_match(1))
269273
when /^(\w+)/
270274
raise "ERROR: You can't have more than one Module name specified!" unless module_name.nil?
271275

auto/generate_test_runner.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def self.default_options
4545
cmdline_args: false,
4646
omit_begin_end: false,
4747
use_param_tests: false,
48+
use_system_files: true,
4849
include_extensions: '(?:hpp|hh|H|h)',
4950
source_extensions: '(?:cpp|cc|ino|C|c)'
5051
}
@@ -69,7 +70,7 @@ def run(input_file, output_file, options = nil)
6970
source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
7071
tests = find_tests(source)
7172
headers = find_includes(source)
72-
testfile_includes = (headers[:local] + headers[:system])
73+
testfile_includes = @options[:use_system_files] ? (headers[:local] + headers[:system]) : (headers[:local])
7374
used_mocks = find_mocks(testfile_includes)
7475
testfile_includes = (testfile_includes - used_mocks)
7576
testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ }
@@ -80,7 +81,7 @@ def run(input_file, output_file, options = nil)
8081

8182
# determine which files were used to return them
8283
all_files_used = [input_file, output_file]
83-
all_files_used += testfile_includes.map { |filename| filename + '.c' } unless testfile_includes.empty?
84+
all_files_used += testfile_includes.map { |filename| "#{filename}.c" } unless testfile_includes.empty?
8485
all_files_used += @options[:includes] unless @options[:includes].empty?
8586
all_files_used += headers[:linkonly] unless headers[:linkonly].empty?
8687
all_files_used.uniq
@@ -144,12 +145,12 @@ def find_tests(source)
144145
if @options[:use_param_tests] && !arguments.empty?
145146
args = []
146147
type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/)
147-
for i in (1...type_and_args.length).step(2)
148+
(1...type_and_args.length).step(2).each do |i|
148149
case type_and_args[i]
149-
when "CASE"
150+
when 'CASE'
150151
args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1')
151152

152-
when "RANGE"
153+
when 'RANGE'
153154
args += type_and_args[i + 1].scan(/(\[|<)\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*(\]|>)/m).map do |arg_values_str|
154155
exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
155156
arg_values_str[1...-1].map do |arg_value_str|
@@ -163,13 +164,13 @@ def find_tests(source)
163164
arg_combinations.flatten.join(', ')
164165
end
165166

166-
when "MATRIX"
167-
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["'\,]|\[[\d\S_-]+\])+)/.source
167+
when 'MATRIX'
168+
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["',]|\[[\d\S_-]+\])+)/.source
168169
args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m
169170
arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
170171

171172
args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
172-
(arg_values_str + ',').scan(arg_elements_regex)
173+
("#{arg_values_str},").scan(arg_elements_regex)
173174
end.reduce do |result, arg_range_expanded|
174175
result.product(arg_range_expanded)
175176
end.map do |arg_combinations|
@@ -188,7 +189,7 @@ def find_tests(source)
188189
source_lines = source.split("\n")
189190
source_index = 0
190191
tests_and_line_numbers.size.times do |i|
191-
source_lines[source_index..-1].each_with_index do |line, index|
192+
source_lines[source_index..].each_with_index do |line, index|
192193
next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
193194

194195
source_index += index
@@ -207,12 +208,11 @@ def find_includes(source)
207208
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
208209

209210
# parse out includes
210-
includes = {
211-
local: source.scan(/^\s*#include\s+\"\s*(.+\.#{@options[:include_extensions]})\s*\"/).flatten,
211+
{
212+
local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
212213
system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" },
213-
linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten
214+
linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
214215
}
215-
includes
216216
end
217217

218218
def find_mocks(includes)
@@ -369,7 +369,7 @@ def create_run_test(output)
369369
require 'erb'
370370
file = File.read(File.join(__dir__, 'run_test.erb'))
371371
template = ERB.new(file, trim_mode: '<>')
372-
output.puts("\n" + template.result(binding))
372+
output.puts("\n#{template.result(binding)}")
373373
end
374374

375375
def create_args_wrappers(output, tests)
@@ -459,7 +459,7 @@ def create_main(output, filename, tests, used_mocks)
459459
end
460460

461461
def create_h_file(output, filename, tests, testfile_includes, used_mocks)
462-
filename = File.basename(filename).gsub(/[-\/\\\.\,\s]/, '_').upcase
462+
filename = File.basename(filename).gsub(/[-\/\\.,\s]/, '_').upcase
463463
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
464464
output.puts("#ifndef _#{filename}")
465465
output.puts("#define _#{filename}\n\n")
@@ -498,7 +498,7 @@ def create_h_file(output, filename, tests, testfile_includes, used_mocks)
498498
when /\.*\.ya?ml$/
499499
options = UnityTestRunnerGenerator.grab_config(arg)
500500
true
501-
when /--(\w+)=\"?(.*)\"?/
501+
when /--(\w+)="?(.*)"?/
502502
options[Regexp.last_match(1).to_sym] = Regexp.last_match(2)
503503
true
504504
when /\.*\.(?:hpp|hh|H|h)$/

0 commit comments

Comments
 (0)