Skip to content

Commit bd32847

Browse files
committed
Merge branch 'master' into platform_matrix
2 parents 88069f0 + 8b0daf1 commit bd32847

27 files changed

+793
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ build/
22
builddir/
33
test/sandbox
44
.DS_Store
5+
examples/example_1/subprojects/unity
56
examples/example_1/test1.exe
67
examples/example_1/test2.exe
78
examples/example_2/all_tests.exe

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_include_directories(${PROJECT_NAME}
7676
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
7777
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
7878
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
79+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
7980
$<BUILD_INTERFACE:$<$<BOOL:${UNITY_EXTENSION_MEMORY_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/memory/src>>
8081
$<BUILD_INTERFACE:$<$<BOOL:${UNITY_EXTENSION_FIXTURE_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/fixture/src>>
8182
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.or
66
Unity Test is a unit testing framework built for C, with a focus on working with embedded toolchains.
77

88
This project is made to test code targetting microcontrollers big and small.
9-
The core project is a single C file and a pair of headers, allowing it to the added to your existing build setup without too much headache.
9+
The core project is a single C file and a pair of headers, allowing it to be added to your existing build setup without too much headache.
1010
You may use any compiler you wish, and may use most existing build systems including Make, CMake, etc.
1111
If you'd like to leave the hard work to us, you might be interested in Ceedling, a build tool also by ThrowTheSwitch.org.
1212

auto/extract_version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
import re
3+
import sys
4+
5+
ver_re = re.compile(r"^#define\s+UNITY_VERSION_(?:MAJOR|MINOR|BUILD)\s+(\d+)$")
6+
version = []
7+
8+
with open(sys.argv[1], "r") as f:
9+
for line in f:
10+
m = ver_re.match(line)
11+
if m:
12+
version.append(m.group(1))
13+
14+
print(".".join(version))
15+

auto/generate_test_runner.rb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def find_tests(source)
132132

133133
lines.each_with_index do |line, _index|
134134
# find tests
135-
next unless line =~ /^((?:\s*(?:TEST_CASE|TEST_RANGE)\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m
136-
next unless line =~ /^((?:\s*(?:TEST_CASE|TEST_RANGE)\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]})\w*)\s*\(\s*(.*)\s*\)/m
135+
next unless line =~ /^((?:\s*(?:TEST_(?:CASE|RANGE|MATRIX))\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m
136+
next unless line =~ /^((?:\s*(?:TEST_(?:CASE|RANGE|MATRIX))\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]})\w*)\s*\(\s*(.*)\s*\)/m
137137

138138
arguments = Regexp.last_match(1)
139139
name = Regexp.last_match(2)
@@ -143,25 +143,38 @@ def find_tests(source)
143143

144144
if @options[:use_param_tests] && !arguments.empty?
145145
args = []
146-
type_and_args = arguments.split(/TEST_(CASE|RANGE)/)
147-
(1...type_and_args.length).step(2).each do |i|
148-
if type_and_args[i] == 'CASE'
146+
type_and_args = arguments.split(/TEST_(CASE|RANGE|MATRIX)/)
147+
for i in (1...type_and_args.length).step(2)
148+
case type_and_args[i]
149+
when "CASE"
149150
args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1')
150-
next
151-
end
152151

153-
# RANGE
154-
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|
155-
exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
156-
arg_values_str[1...-1].map do |arg_value_str|
157-
arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
158-
end.push(exclude_end)
159-
end.map do |arg_values|
160-
Range.new(arg_values[0], arg_values[1], arg_values[3]).step(arg_values[2]).to_a
161-
end.reduce(nil) do |result, arg_range_expanded|
162-
result.nil? ? arg_range_expanded.map { |a| [a] } : result.product(arg_range_expanded)
163-
end.map do |arg_combinations|
164-
arg_combinations.flatten.join(', ')
152+
when "RANGE"
153+
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|
154+
exclude_end = arg_values_str[0] == '<' && arg_values_str[-1] == '>'
155+
arg_values_str[1...-1].map do |arg_value_str|
156+
arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
157+
end.push(exclude_end)
158+
end.map do |arg_values|
159+
Range.new(arg_values[0], arg_values[1], arg_values[3]).step(arg_values[2]).to_a
160+
end.reduce(nil) do |result, arg_range_expanded|
161+
result.nil? ? arg_range_expanded.map { |a| [a] } : result.product(arg_range_expanded)
162+
end.map do |arg_combinations|
163+
arg_combinations.flatten.join(', ')
164+
end
165+
166+
when "MATRIX"
167+
single_arg_regex_string = /(?:(?:"(?:\\"|[^\\])*?")+|(?:'\\?.')+|(?:[^\s\]\["'\,]|\[[\d\S_-]+\])+)/.source
168+
args_regex = /\[((?:\s*#{single_arg_regex_string}\s*,?)*(?:\s*#{single_arg_regex_string})?\s*)\]/m
169+
arg_elements_regex = /\s*(#{single_arg_regex_string})\s*,\s*/m
170+
171+
args += type_and_args[i + 1].scan(args_regex).flatten.map do |arg_values_str|
172+
(arg_values_str + ',').scan(arg_elements_regex)
173+
end.reduce do |result, arg_range_expanded|
174+
result.product(arg_range_expanded)
175+
end.map do |arg_combinations|
176+
arg_combinations.flatten.join(', ')
177+
end
165178
end
166179
end
167180
end
@@ -197,7 +210,7 @@ def find_includes(source)
197210
{
198211
local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten,
199212
system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" },
200-
linkonly: source.scan(/^TEST_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten
213+
linkonly: source.scan(/^TEST_SOURCE_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten
201214
}
202215
end
203216

@@ -388,7 +401,7 @@ def create_main(output, filename, tests, used_mocks)
388401
output.puts(' {')
389402
output.puts(' if (parse_status < 0)')
390403
output.puts(' {')
391-
output.puts(" UnityPrint(\"#{filename.gsub('.c', '')}.\");")
404+
output.puts(" UnityPrint(\"#{filename.gsub('.c', '').gsub(/\\/, '\\\\\\')}.\");")
392405
output.puts(' UNITY_PRINT_EOL();')
393406
tests.each do |test|
394407
if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty?

0 commit comments

Comments
 (0)