mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-22 23:45:50 +08:00
Merge branch 'master' into feature-printf
# Conflicts: # src/unity.c
This commit is contained in:
@ -24,7 +24,7 @@ class ColourCommandLine
|
|||||||
return unless RUBY_PLATFORM =~ /(win|w)32$/
|
return unless RUBY_PLATFORM =~ /(win|w)32$/
|
||||||
get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
|
get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L')
|
||||||
@set_console_txt_attrb =
|
@set_console_txt_attrb =
|
||||||
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w(L N), 'I')
|
Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I')
|
||||||
@hout = get_std_handle.call(-11)
|
@hout = get_std_handle.call(-11)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ class ColourCommandLine
|
|||||||
$stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print
|
$stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end # ColourCommandLine
|
end
|
||||||
|
|
||||||
def colour_puts(role, str)
|
def colour_puts(role, str)
|
||||||
ColourCommandLine.new.out_c(:puts, role, str)
|
ColourCommandLine.new.out_c(:puts, role, str)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt"
|
require_relative 'colour_prompt'
|
||||||
|
|
||||||
$colour_output = true
|
$colour_output = true
|
||||||
|
|
||||||
|
@ -45,8 +45,6 @@ TEMPLATE_INC ||= '#ifndef _%3$s_H
|
|||||||
class UnityModuleGenerator
|
class UnityModuleGenerator
|
||||||
############################
|
############################
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
here = File.expand_path(File.dirname(__FILE__)) + '/'
|
|
||||||
|
|
||||||
@options = UnityModuleGenerator.default_options
|
@options = UnityModuleGenerator.default_options
|
||||||
case options
|
case options
|
||||||
when NilClass then @options
|
when NilClass then @options
|
||||||
@ -56,9 +54,9 @@ class UnityModuleGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Create default file paths if none were provided
|
# Create default file paths if none were provided
|
||||||
@options[:path_src] = here + '../src/' if @options[:path_src].nil?
|
@options[:path_src] = "#{__dir__}/../src/" if @options[:path_src].nil?
|
||||||
@options[:path_inc] = @options[:path_src] if @options[:path_inc].nil?
|
@options[:path_inc] = @options[:path_src] if @options[:path_inc].nil?
|
||||||
@options[:path_tst] = here + '../test/' if @options[:path_tst].nil?
|
@options[:path_tst] = "#{__dir__}/../test/" if @options[:path_tst].nil?
|
||||||
@options[:path_src] += '/' unless @options[:path_src][-1] == 47
|
@options[:path_src] += '/' unless @options[:path_src][-1] == 47
|
||||||
@options[:path_inc] += '/' unless @options[:path_inc][-1] == 47
|
@options[:path_inc] += '/' unless @options[:path_inc][-1] == 47
|
||||||
@options[:path_tst] += '/' unless @options[:path_tst][-1] == 47
|
@options[:path_tst] += '/' unless @options[:path_tst][-1] == 47
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
File.expand_path(File.join(File.dirname(__FILE__), 'colour_prompt'))
|
|
||||||
|
|
||||||
class UnityTestRunnerGenerator
|
class UnityTestRunnerGenerator
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
@options = UnityTestRunnerGenerator.default_options
|
@options = UnityTestRunnerGenerator.default_options
|
||||||
@ -15,7 +13,7 @@ class UnityTestRunnerGenerator
|
|||||||
when Hash then @options.merge!(options)
|
when Hash then @options.merge!(options)
|
||||||
else raise 'If you specify arguments, it should be a filename or a hash of options'
|
else raise 'If you specify arguments, it should be a filename or a hash of options'
|
||||||
end
|
end
|
||||||
require "#{File.expand_path(File.dirname(__FILE__))}/type_sanitizer"
|
require_relative 'type_sanitizer'
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.default_options
|
def self.default_options
|
||||||
@ -92,12 +90,25 @@ class UnityTestRunnerGenerator
|
|||||||
def find_tests(source)
|
def find_tests(source)
|
||||||
tests_and_line_numbers = []
|
tests_and_line_numbers = []
|
||||||
|
|
||||||
|
# contains characters which will be substituted from within strings, doing
|
||||||
|
# this prevents these characters from interferring with scrubbers
|
||||||
|
# @ is not a valid C character, so there should be no clashes with files genuinely containing these markers
|
||||||
|
substring_subs = { '{' => '@co@', '}' => '@cc@', ';' => '@ss@', '/' => '@fs@' }
|
||||||
|
substring_re = Regexp.union(substring_subs.keys)
|
||||||
|
substring_unsubs = substring_subs.invert # the inverse map will be used to fix the strings afterwords
|
||||||
|
substring_unsubs['@quote@'] = '\\"'
|
||||||
|
substring_unsubs['@apos@'] = '\\\''
|
||||||
|
substring_unre = Regexp.union(substring_unsubs.keys)
|
||||||
source_scrubbed = source.clone
|
source_scrubbed = source.clone
|
||||||
source_scrubbed = source_scrubbed.gsub(/"[^"\n]*"/, '') # remove things in strings
|
source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char
|
||||||
|
source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char
|
||||||
|
source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic
|
||||||
|
# characters within strings
|
||||||
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments
|
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments
|
||||||
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||||
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||||
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
||||||
|
.map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed
|
||||||
|
|
||||||
lines.each_with_index do |line, _index|
|
lines.each_with_index do |line, _index|
|
||||||
# find tests
|
# find tests
|
||||||
@ -165,10 +176,10 @@ class UnityTestRunnerGenerator
|
|||||||
output.puts('#include "cmock.h"') unless mocks.empty?
|
output.puts('#include "cmock.h"') unless mocks.empty?
|
||||||
output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H')
|
output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H')
|
||||||
output.puts('#include <setjmp.h>')
|
output.puts('#include <setjmp.h>')
|
||||||
output.puts("#endif")
|
output.puts('#endif')
|
||||||
output.puts('#include <stdio.h>')
|
output.puts('#include <stdio.h>')
|
||||||
if @options[:defines] && !@options[:defines].empty?
|
if @options[:defines] && !@options[:defines].empty?
|
||||||
@options[:defines].each { |d| output.puts("#define #{d}") }
|
@options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") }
|
||||||
end
|
end
|
||||||
if @options[:header_file] && !@options[:header_file].empty?
|
if @options[:header_file] && !@options[:header_file].empty?
|
||||||
output.puts("#include \"#{File.basename(@options[:header_file])}\"")
|
output.puts("#include \"#{File.basename(@options[:header_file])}\"")
|
||||||
@ -379,7 +390,7 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
output.puts
|
output.puts
|
||||||
output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
|
output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
|
||||||
output.puts(" return suite_teardown(UnityEnd());")
|
output.puts(' return suite_teardown(UnityEnd());')
|
||||||
output.puts('}')
|
output.puts('}')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ class ParseOutput
|
|||||||
|
|
||||||
# Adjusts the os specific members according to the current path style
|
# Adjusts the os specific members according to the current path style
|
||||||
# (Windows or Unix based)
|
# (Windows or Unix based)
|
||||||
def set_os_specifics(line)
|
def detect_os_specifics(line)
|
||||||
if line.include? '\\'
|
if line.include? '\\'
|
||||||
# Windows X:\Y\Z
|
# Windows X:\Y\Z
|
||||||
@class_name_idx = 1
|
@class_name_idx = 1
|
||||||
@ -254,43 +254,42 @@ class ParseOutput
|
|||||||
# TEST(<test_group, <test_file>) PASS
|
# TEST(<test_group, <test_file>) PASS
|
||||||
#
|
#
|
||||||
# Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)!
|
# Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)!
|
||||||
set_os_specifics(line)
|
detect_os_specifics(line)
|
||||||
line_array = line.split(':')
|
line_array = line.split(':')
|
||||||
|
|
||||||
# If we were able to split the line then we can look to see if any of our target words
|
# If we were able to split the line then we can look to see if any of our target words
|
||||||
# were found. Case is important.
|
# were found. Case is important.
|
||||||
if (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
|
next unless (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
|
||||||
|
|
||||||
# check if the output is fixture output (with verbose flag "-v")
|
# check if the output is fixture output (with verbose flag "-v")
|
||||||
if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
|
if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
|
||||||
line_array = prepare_fixture_line(line)
|
line_array = prepare_fixture_line(line)
|
||||||
if line.include? ' PASS'
|
if line.include? ' PASS'
|
||||||
test_passed_unity_fixture(line_array)
|
test_passed_unity_fixture(line_array)
|
||||||
@test_passed += 1
|
|
||||||
elsif line.include? 'FAIL'
|
|
||||||
test_failed_unity_fixture(line_array)
|
|
||||||
@test_failed += 1
|
|
||||||
elsif line.include? 'IGNORE'
|
|
||||||
test_ignored_unity_fixture(line_array)
|
|
||||||
@test_ignored += 1
|
|
||||||
end
|
|
||||||
# normal output / fixture output (without verbose "-v")
|
|
||||||
elsif line.include? ':PASS'
|
|
||||||
test_passed(line_array)
|
|
||||||
@test_passed += 1
|
@test_passed += 1
|
||||||
elsif line.include? ':FAIL'
|
elsif line.include? 'FAIL'
|
||||||
test_failed(line_array)
|
test_failed_unity_fixture(line_array)
|
||||||
@test_failed += 1
|
@test_failed += 1
|
||||||
elsif line.include? ':IGNORE:'
|
elsif line.include? 'IGNORE'
|
||||||
test_ignored(line_array)
|
test_ignored_unity_fixture(line_array)
|
||||||
@test_ignored += 1
|
|
||||||
elsif line.include? ':IGNORE'
|
|
||||||
line_array.push('No reason given')
|
|
||||||
test_ignored(line_array)
|
|
||||||
@test_ignored += 1
|
@test_ignored += 1
|
||||||
end
|
end
|
||||||
@total_tests = @test_passed + @test_failed + @test_ignored
|
# normal output / fixture output (without verbose "-v")
|
||||||
|
elsif line.include? ':PASS'
|
||||||
|
test_passed(line_array)
|
||||||
|
@test_passed += 1
|
||||||
|
elsif line.include? ':FAIL'
|
||||||
|
test_failed(line_array)
|
||||||
|
@test_failed += 1
|
||||||
|
elsif line.include? ':IGNORE:'
|
||||||
|
test_ignored(line_array)
|
||||||
|
@test_ignored += 1
|
||||||
|
elsif line.include? ':IGNORE'
|
||||||
|
line_array.push('No reason given')
|
||||||
|
test_ignored(line_array)
|
||||||
|
@test_ignored += 1
|
||||||
end
|
end
|
||||||
|
@total_tests = @test_passed + @test_failed + @test_ignored
|
||||||
end
|
end
|
||||||
puts ''
|
puts ''
|
||||||
puts '=================== SUMMARY ====================='
|
puts '=================== SUMMARY ====================='
|
||||||
|
@ -61,8 +61,8 @@ class ArgvParser
|
|||||||
|
|
||||||
opts.parse!(args)
|
opts.parse!(args)
|
||||||
options
|
options
|
||||||
end # parse()
|
end
|
||||||
end # class OptparseExample
|
end
|
||||||
|
|
||||||
class UnityToJUnit
|
class UnityToJUnit
|
||||||
include FileUtils::Verbose
|
include FileUtils::Verbose
|
||||||
@ -155,10 +155,6 @@ class UnityToJUnit
|
|||||||
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
||||||
end
|
end
|
||||||
|
|
||||||
def here
|
|
||||||
File.expand_path(File.dirname(__FILE__))
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def results_structure
|
def results_structure
|
||||||
@ -221,9 +217,9 @@ class UnityToJUnit
|
|||||||
def write_suites_footer(stream)
|
def write_suites_footer(stream)
|
||||||
stream.puts '</testsuites>'
|
stream.puts '</testsuites>'
|
||||||
end
|
end
|
||||||
end # UnityToJUnit
|
end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if $0 == __FILE__
|
||||||
# parse out the command options
|
# parse out the command options
|
||||||
options = ArgvParser.parse(ARGV)
|
options = ArgvParser.parse(ARGV)
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ module RakefileHelpers
|
|||||||
def initialize(all_files = false)
|
def initialize(all_files = false)
|
||||||
@all_files = all_files
|
@all_files = all_files
|
||||||
|
|
||||||
return false unless @all_files
|
return unless @all_files
|
||||||
return false unless File.exist?('test_file_filter.yml')
|
return unless File.exist?('test_file_filter.yml')
|
||||||
|
|
||||||
filters = YAML.load_file('test_file_filter.yml')
|
filters = YAML.load_file('test_file_filter.yml')
|
||||||
@all_files = filters[:all_files]
|
@all_files = filters[:all_files]
|
||||||
|
@ -101,10 +101,6 @@ class UnityTestSummary
|
|||||||
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
||||||
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
||||||
end
|
end
|
||||||
|
|
||||||
def here
|
|
||||||
File.expand_path(File.dirname(__FILE__))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if $0 == __FILE__
|
if $0 == __FILE__
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
int Counter = 0;
|
int Counter = 0;
|
||||||
int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */
|
int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */
|
||||||
|
|
||||||
/* This function is supposed to search through NumbersToFind and find a particular number.
|
/* This function is supposed to search through NumbersToFind and find a particular number.
|
||||||
* If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since
|
* If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since
|
||||||
* NumbersToFind is indexed from 1. Unfortunately it's broken
|
* NumbersToFind is indexed from 1. Unfortunately it's broken
|
||||||
* (and should therefore be caught by our tests) */
|
* (and should therefore be caught by our tests) */
|
||||||
int FindFunction_WhichIsBroken(int NumberToFind)
|
int FindFunction_WhichIsBroken(int NumberToFind)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i <= 8) /* Notice I should have been in braces */
|
while (i < 8) /* Notice I should have been in braces */
|
||||||
i++;
|
i++;
|
||||||
if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */
|
if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */
|
||||||
return i;
|
return i;
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
|
|
||||||
UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/../..'
|
|
||||||
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
require HERE + 'rakefile_helper'
|
require_relative 'rakefile_helper'
|
||||||
|
|
||||||
TEMP_DIRS = [
|
TEMP_DIRS = [
|
||||||
File.join(HERE, 'build')
|
File.join(__dir__, 'build')
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
TEMP_DIRS.each do |dir|
|
TEMP_DIRS.each do |dir|
|
||||||
@ -32,8 +29,8 @@ task :summary do
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build and test Unity'
|
desc 'Build and test Unity'
|
||||||
task all: %i(clean unit summary)
|
task all: %i[clean unit summary]
|
||||||
task default: %i(clobber all)
|
task default: %i[clobber all]
|
||||||
task ci: [:default]
|
task ci: [:default]
|
||||||
task cruise: [:default]
|
task cruise: [:default]
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require UNITY_ROOT + '/auto/unity_test_summary'
|
require_relative '../../auto/unity_test_summary'
|
||||||
require UNITY_ROOT + '/auto/generate_test_runner'
|
require_relative '../../auto/generate_test_runner'
|
||||||
require UNITY_ROOT + '/auto/colour_reporter'
|
require_relative '../../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
C_EXTENSION = '.c'.freeze
|
C_EXTENSION = '.c'.freeze
|
||||||
@ -149,7 +149,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def report_summary
|
def report_summary
|
||||||
summary = UnityTestSummary.new
|
summary = UnityTestSummary.new
|
||||||
summary.root = HERE
|
summary.root = __dir__
|
||||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||||
results_glob.tr!('\\', '/')
|
results_glob.tr!('\\', '/')
|
||||||
results = Dir[results_glob]
|
results = Dir[results_glob]
|
||||||
|
@ -4,15 +4,13 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
|
|
||||||
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
require 'rake/testtask'
|
require 'rake/testtask'
|
||||||
require HERE + 'rakefile_helper'
|
require_relative 'rakefile_helper'
|
||||||
|
|
||||||
TEMP_DIRS = [
|
TEMP_DIRS = [
|
||||||
File.join(HERE, 'build')
|
File.join(__dir__, 'build')
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
TEMP_DIRS.each do |dir|
|
TEMP_DIRS.each do |dir|
|
||||||
@ -33,10 +31,10 @@ task unit: [:prepare_for_tests] do
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build and test Unity Framework'
|
desc 'Build and test Unity Framework'
|
||||||
task all: %i(clean unit)
|
task all: %i[clean unit]
|
||||||
task default: %i(clobber all)
|
task default: %i[clobber all]
|
||||||
task ci: %i(no_color default)
|
task ci: %i[no_color default]
|
||||||
task cruise: %i(no_color default)
|
task cruise: %i[no_color default]
|
||||||
|
|
||||||
desc 'Load configuration'
|
desc 'Load configuration'
|
||||||
task :config, :config_file do |_t, args|
|
task :config, :config_file do |_t, args|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require HERE + '../../auto/unity_test_summary'
|
require_relative '../../auto/unity_test_summary'
|
||||||
require HERE + '../../auto/generate_test_runner'
|
require_relative '../../auto/generate_test_runner'
|
||||||
require HERE + '../../auto/colour_reporter'
|
require_relative '../../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
C_EXTENSION = '.c'.freeze
|
C_EXTENSION = '.c'.freeze
|
||||||
@ -16,7 +16,7 @@ module RakefileHelpers
|
|||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
return if $configured
|
return if $configured
|
||||||
|
|
||||||
$cfg_file = HERE + "../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/
|
$cfg_file = "#{__dir__}/../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/
|
||||||
$cfg = YAML.load(File.read($cfg_file))
|
$cfg = YAML.load(File.read($cfg_file))
|
||||||
$colour_output = false unless $cfg['colour']
|
$colour_output = false unless $cfg['colour']
|
||||||
$configured = true if config_file != DEFAULT_CONFIG_FILE
|
$configured = true if config_file != DEFAULT_CONFIG_FILE
|
||||||
@ -128,7 +128,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def report_summary
|
def report_summary
|
||||||
summary = UnityTestSummary.new
|
summary = UnityTestSummary.new
|
||||||
summary.root = HERE
|
summary.root = __dir__
|
||||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||||
results_glob.tr!('\\', '/')
|
results_glob.tr!('\\', '/')
|
||||||
results = Dir[results_glob]
|
results = Dir[results_glob]
|
||||||
@ -145,9 +145,9 @@ module RakefileHelpers
|
|||||||
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
$cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil?
|
||||||
|
|
||||||
# Get a list of all source files needed
|
# Get a list of all source files needed
|
||||||
src_files = Dir[HERE + 'src/*.c']
|
src_files = Dir["#{__dir__}/src/*.c"]
|
||||||
src_files += Dir[HERE + 'test/*.c']
|
src_files += Dir["#{__dir__}/test/*.c"]
|
||||||
src_files += Dir[HERE + 'test/main/*.c']
|
src_files += Dir["#{__dir__}/test/main/*.c"]
|
||||||
src_files << '../../src/unity.c'
|
src_files << '../../src/unity.c'
|
||||||
|
|
||||||
# Build object files
|
# Build object files
|
||||||
|
203
src/unity.c
203
src/unity.c
@ -319,7 +319,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print)
|
|||||||
{
|
{
|
||||||
/* A negative number, including MIN negative */
|
/* A negative number, including MIN negative */
|
||||||
UNITY_OUTPUT_CHAR('-');
|
UNITY_OUTPUT_CHAR('-');
|
||||||
number = (UNITY_UINT)(-number_to_print);
|
number = -number;
|
||||||
}
|
}
|
||||||
UnityPrintNumberUnsigned(number);
|
UnityPrintNumberUnsigned(number);
|
||||||
}
|
}
|
||||||
@ -350,7 +350,9 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print)
|
|||||||
int nibble;
|
int nibble;
|
||||||
char nibbles = nibbles_to_print;
|
char nibbles = nibbles_to_print;
|
||||||
if ((unsigned)nibbles > (2 * sizeof(number)))
|
if ((unsigned)nibbles > (2 * sizeof(number)))
|
||||||
|
{
|
||||||
nibbles = 2 * sizeof(number);
|
nibbles = 2 * sizeof(number);
|
||||||
|
}
|
||||||
|
|
||||||
while (nibbles > 0)
|
while (nibbles > 0)
|
||||||
{
|
{
|
||||||
@ -396,13 +398,25 @@ void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number)
|
|||||||
|
|
||||||
/*-----------------------------------------------*/
|
/*-----------------------------------------------*/
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
/* This function prints a floating-point value in a format similar to
|
/*
|
||||||
* printf("%.6g"). It can work with either single- or double-precision,
|
* This function prints a floating-point value in a format similar to
|
||||||
* but for simplicity, it prints only 6 significant digits in either case.
|
* printf("%.7g") on a single-precision machine or printf("%.9g") on a
|
||||||
* Printing more than 6 digits accurately is hard (at least in the single-
|
* double-precision machine. The 7th digit won't always be totally correct
|
||||||
* precision case) and isn't attempted here. */
|
* in single-precision operation (for that level of accuracy, a more
|
||||||
|
* complicated algorithm would be needed).
|
||||||
|
*/
|
||||||
void UnityPrintFloat(const UNITY_DOUBLE input_number)
|
void UnityPrintFloat(const UNITY_DOUBLE input_number)
|
||||||
{
|
{
|
||||||
|
#ifdef UNITY_INCLUDE_DOUBLE
|
||||||
|
static const int sig_digits = 9;
|
||||||
|
static const UNITY_INT32 min_scaled = 100000000;
|
||||||
|
static const UNITY_INT32 max_scaled = 1000000000;
|
||||||
|
#else
|
||||||
|
static const int sig_digits = 7;
|
||||||
|
static const UNITY_INT32 min_scaled = 1000000;
|
||||||
|
static const UNITY_INT32 max_scaled = 10000000;
|
||||||
|
#endif
|
||||||
|
|
||||||
UNITY_DOUBLE number = input_number;
|
UNITY_DOUBLE number = input_number;
|
||||||
|
|
||||||
/* print minus sign (including for negative zero) */
|
/* print minus sign (including for negative zero) */
|
||||||
@ -413,32 +427,85 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* handle zero, NaN, and +/- infinity */
|
/* handle zero, NaN, and +/- infinity */
|
||||||
if (number == 0.0f) UnityPrint("0");
|
if (number == 0.0f)
|
||||||
else if (isnan(number)) UnityPrint("nan");
|
{
|
||||||
else if (isinf(number)) UnityPrint("inf");
|
UnityPrint("0");
|
||||||
|
}
|
||||||
|
else if (isnan(number))
|
||||||
|
{
|
||||||
|
UnityPrint("nan");
|
||||||
|
}
|
||||||
|
else if (isinf(number))
|
||||||
|
{
|
||||||
|
UnityPrint("inf");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
UNITY_INT32 n_int = 0, n;
|
||||||
int exponent = 0;
|
int exponent = 0;
|
||||||
int decimals, digits;
|
int decimals, digits;
|
||||||
UNITY_INT32 n;
|
char buf[16] = {0};
|
||||||
char buf[16];
|
|
||||||
|
|
||||||
/* scale up or down by powers of 10 */
|
/*
|
||||||
while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; }
|
* Scale up or down by powers of 10. To minimize rounding error,
|
||||||
while (number < 100000.0f) { number *= 10.0f; exponent--; }
|
* start with a factor/divisor of 10^10, which is the largest
|
||||||
while (number > 1000000.0f * 1e6f) { number /= 1e6f; exponent += 6; }
|
* power of 10 that can be represented exactly. Finally, compute
|
||||||
while (number > 1000000.0f) { number /= 10.0f; exponent++; }
|
* (exactly) the remaining power of 10 and perform one more
|
||||||
|
* multiplication or division.
|
||||||
|
*/
|
||||||
|
if (number < 1.0f)
|
||||||
|
{
|
||||||
|
UNITY_DOUBLE factor = 1.0f;
|
||||||
|
|
||||||
|
while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; }
|
||||||
|
while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; }
|
||||||
|
|
||||||
|
number *= factor;
|
||||||
|
}
|
||||||
|
else if (number > (UNITY_DOUBLE)max_scaled)
|
||||||
|
{
|
||||||
|
UNITY_DOUBLE divisor = 1.0f;
|
||||||
|
|
||||||
|
while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; }
|
||||||
|
while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; }
|
||||||
|
|
||||||
|
number /= divisor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* In this range, we can split off the integer part before
|
||||||
|
* doing any multiplications. This reduces rounding error by
|
||||||
|
* freeing up significant bits in the fractional part.
|
||||||
|
*/
|
||||||
|
UNITY_DOUBLE factor = 1.0f;
|
||||||
|
n_int = (UNITY_INT32)number;
|
||||||
|
number -= (UNITY_DOUBLE)n_int;
|
||||||
|
|
||||||
|
while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; }
|
||||||
|
|
||||||
|
number *= factor;
|
||||||
|
}
|
||||||
|
|
||||||
/* round to nearest integer */
|
/* round to nearest integer */
|
||||||
n = ((UNITY_INT32)(number + number) + 1) / 2;
|
n = ((UNITY_INT32)(number + number) + 1) / 2;
|
||||||
if (n > 999999)
|
|
||||||
|
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
|
/* round to even if exactly between two integers */
|
||||||
|
if ((n & 1) && ((UNITY_DOUBLE)n - number == 0.5f))
|
||||||
|
n--;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
n += n_int;
|
||||||
|
|
||||||
|
if (n >= max_scaled)
|
||||||
{
|
{
|
||||||
n = 100000;
|
n = min_scaled;
|
||||||
exponent++;
|
exponent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* determine where to place decimal point */
|
/* determine where to place decimal point */
|
||||||
decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5;
|
decimals = (exponent <= 0 && exponent >= -(sig_digits + 3)) ? -exponent : (sig_digits - 1);
|
||||||
exponent += decimals;
|
exponent += decimals;
|
||||||
|
|
||||||
/* truncate trailing zeroes after decimal point */
|
/* truncate trailing zeroes after decimal point */
|
||||||
@ -617,6 +684,7 @@ static void UnityPrintExpectedAndActualStringsLen(const char* expected,
|
|||||||
* Assertion & Control Helpers
|
* Assertion & Control Helpers
|
||||||
*-----------------------------------------------*/
|
*-----------------------------------------------*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
|
static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
|
||||||
UNITY_INTERNAL_PTR actual,
|
UNITY_INTERNAL_PTR actual,
|
||||||
const UNITY_LINE_TYPE lineNumber,
|
const UNITY_LINE_TYPE lineNumber,
|
||||||
@ -649,6 +717,7 @@ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
|
|||||||
* Assertion Functions
|
* Assertion Functions
|
||||||
*-----------------------------------------------*/
|
*-----------------------------------------------*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
void UnityAssertBits(const UNITY_INT mask,
|
void UnityAssertBits(const UNITY_INT mask,
|
||||||
const UNITY_INT expected,
|
const UNITY_INT expected,
|
||||||
const UNITY_INT actual,
|
const UNITY_INT actual,
|
||||||
@ -755,9 +824,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
UnityPrintPointlessAndBail();
|
UnityPrintPointlessAndBail();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expected == actual) return; /* Both are NULL or same pointer */
|
if (expected == actual)
|
||||||
|
{
|
||||||
|
return; /* Both are NULL or same pointer */
|
||||||
|
}
|
||||||
|
|
||||||
if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
|
if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
|
||||||
|
{
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
|
}
|
||||||
|
|
||||||
while ((elements > 0) && elements--)
|
while ((elements > 0) && elements--)
|
||||||
{
|
{
|
||||||
@ -842,12 +917,14 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
|||||||
UnityPrint(UnityStrDelta)
|
UnityPrint(UnityStrDelta)
|
||||||
#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
|
#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual)
|
static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual)
|
||||||
{
|
{
|
||||||
UNITY_FLOAT diff;
|
UNITY_FLOAT diff;
|
||||||
UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
|
UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected,
|
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected,
|
||||||
UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual,
|
UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual,
|
||||||
const UNITY_UINT32 num_elements,
|
const UNITY_UINT32 num_elements,
|
||||||
@ -866,9 +943,15 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected,
|
|||||||
UnityPrintPointlessAndBail();
|
UnityPrintPointlessAndBail();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expected == actual) return; /* Both are NULL or same pointer */
|
if (expected == actual)
|
||||||
|
{
|
||||||
|
return; /* Both are NULL or same pointer */
|
||||||
|
}
|
||||||
|
|
||||||
if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
|
if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
|
||||||
|
{
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
|
}
|
||||||
|
|
||||||
while (elements--)
|
while (elements--)
|
||||||
{
|
{
|
||||||
@ -953,14 +1036,18 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
|
|||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrint(UnityStrExpected);
|
||||||
if (!should_be_trait)
|
if (!should_be_trait)
|
||||||
|
{
|
||||||
UnityPrint(UnityStrNot);
|
UnityPrint(UnityStrNot);
|
||||||
|
}
|
||||||
UnityPrint(trait_names[trait_index]);
|
UnityPrint(trait_names[trait_index]);
|
||||||
UnityPrint(UnityStrWas);
|
UnityPrint(UnityStrWas);
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
UnityPrintFloat((UNITY_DOUBLE)actual);
|
UnityPrintFloat((UNITY_DOUBLE)actual);
|
||||||
#else
|
#else
|
||||||
if (should_be_trait)
|
if (should_be_trait)
|
||||||
|
{
|
||||||
UnityPrint(UnityStrNot);
|
UnityPrint(UnityStrNot);
|
||||||
|
}
|
||||||
UnityPrint(trait_names[trait_index]);
|
UnityPrint(trait_names[trait_index]);
|
||||||
#endif
|
#endif
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
@ -978,6 +1065,7 @@ static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_D
|
|||||||
UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
|
UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected,
|
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected,
|
||||||
UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual,
|
UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual,
|
||||||
const UNITY_UINT32 num_elements,
|
const UNITY_UINT32 num_elements,
|
||||||
@ -996,9 +1084,15 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expecte
|
|||||||
UnityPrintPointlessAndBail();
|
UnityPrintPointlessAndBail();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expected == actual) return; /* Both are NULL or same pointer */
|
if (expected == actual)
|
||||||
|
{
|
||||||
|
return; /* Both are NULL or same pointer */
|
||||||
|
}
|
||||||
|
|
||||||
if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
|
if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
|
||||||
|
{
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
|
}
|
||||||
|
|
||||||
while (elements--)
|
while (elements--)
|
||||||
{
|
{
|
||||||
@ -1038,7 +1132,6 @@ void UnityAssertDoublesWithin(const UNITY_DOUBLE delta,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------*/
|
/*-----------------------------------------------*/
|
||||||
|
|
||||||
void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
|
void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber,
|
const UNITY_LINE_TYPE lineNumber,
|
||||||
@ -1083,14 +1176,18 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
|
|||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrint(UnityStrExpected);
|
||||||
if (!should_be_trait)
|
if (!should_be_trait)
|
||||||
|
{
|
||||||
UnityPrint(UnityStrNot);
|
UnityPrint(UnityStrNot);
|
||||||
|
}
|
||||||
UnityPrint(trait_names[trait_index]);
|
UnityPrint(trait_names[trait_index]);
|
||||||
UnityPrint(UnityStrWas);
|
UnityPrint(UnityStrWas);
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
#ifndef UNITY_EXCLUDE_FLOAT_PRINT
|
||||||
UnityPrintFloat(actual);
|
UnityPrintFloat(actual);
|
||||||
#else
|
#else
|
||||||
if (should_be_trait)
|
if (should_be_trait)
|
||||||
|
{
|
||||||
UnityPrint(UnityStrNot);
|
UnityPrint(UnityStrNot);
|
||||||
|
}
|
||||||
UnityPrint(trait_names[trait_index]);
|
UnityPrint(trait_names[trait_index]);
|
||||||
#endif
|
#endif
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
@ -1113,16 +1210,24 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
|
|||||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||||
{
|
{
|
||||||
if (actual > expected)
|
if (actual > expected)
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
|
{
|
||||||
|
Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
|
{
|
||||||
|
Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((UNITY_UINT)actual > (UNITY_UINT)expected)
|
if ((UNITY_UINT)actual > (UNITY_UINT)expected)
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta);
|
{
|
||||||
|
Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta);
|
{
|
||||||
|
Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Unity.CurrentTestFailed)
|
if (Unity.CurrentTestFailed)
|
||||||
@ -1318,9 +1423,15 @@ void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected,
|
|||||||
UnityPrintPointlessAndBail();
|
UnityPrintPointlessAndBail();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expected == actual) return; /* Both are NULL or same pointer */
|
if (expected == actual)
|
||||||
|
{
|
||||||
|
return; /* Both are NULL or same pointer */
|
||||||
|
}
|
||||||
|
|
||||||
if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
|
if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
|
||||||
|
{
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
|
}
|
||||||
|
|
||||||
while (elements--)
|
while (elements--)
|
||||||
{
|
{
|
||||||
@ -1397,6 +1508,7 @@ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
|
/*-----------------------------------------------*/
|
||||||
UNITY_INTERNAL_PTR UnityFloatToPtr(const float num)
|
UNITY_INTERNAL_PTR UnityFloatToPtr(const float num)
|
||||||
{
|
{
|
||||||
UnityQuickCompare.f = num;
|
UnityQuickCompare.f = num;
|
||||||
@ -1405,6 +1517,7 @@ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_DOUBLE
|
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||||
|
/*-----------------------------------------------*/
|
||||||
UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num)
|
UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num)
|
||||||
{
|
{
|
||||||
UnityQuickCompare.d = num;
|
UnityQuickCompare.d = num;
|
||||||
@ -1416,6 +1529,7 @@ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num)
|
|||||||
* Control Functions
|
* Control Functions
|
||||||
*-----------------------------------------------*/
|
*-----------------------------------------------*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
|
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
|
||||||
{
|
{
|
||||||
RETURN_IF_FAIL_OR_IGNORE;
|
RETURN_IF_FAIL_OR_IGNORE;
|
||||||
@ -1540,6 +1654,7 @@ char* UnityOptionIncludeNamed = NULL;
|
|||||||
char* UnityOptionExcludeNamed = NULL;
|
char* UnityOptionExcludeNamed = NULL;
|
||||||
int UnityVerbosity = 1;
|
int UnityVerbosity = 1;
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
int UnityParseOptions(int argc, char** argv)
|
int UnityParseOptions(int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnityOptionIncludeNamed = NULL;
|
UnityOptionIncludeNamed = NULL;
|
||||||
@ -1556,9 +1671,13 @@ int UnityParseOptions(int argc, char** argv)
|
|||||||
case 'n': /* include tests with name including this string */
|
case 'n': /* include tests with name including this string */
|
||||||
case 'f': /* an alias for -n */
|
case 'f': /* an alias for -n */
|
||||||
if (argv[i][2] == '=')
|
if (argv[i][2] == '=')
|
||||||
|
{
|
||||||
UnityOptionIncludeNamed = &argv[i][3];
|
UnityOptionIncludeNamed = &argv[i][3];
|
||||||
|
}
|
||||||
else if (++i < argc)
|
else if (++i < argc)
|
||||||
|
{
|
||||||
UnityOptionIncludeNamed = argv[i];
|
UnityOptionIncludeNamed = argv[i];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UnityPrint("ERROR: No Test String to Include Matches For");
|
UnityPrint("ERROR: No Test String to Include Matches For");
|
||||||
@ -1574,9 +1693,13 @@ int UnityParseOptions(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
case 'x': /* exclude tests with name including this string */
|
case 'x': /* exclude tests with name including this string */
|
||||||
if (argv[i][2] == '=')
|
if (argv[i][2] == '=')
|
||||||
|
{
|
||||||
UnityOptionExcludeNamed = &argv[i][3];
|
UnityOptionExcludeNamed = &argv[i][3];
|
||||||
|
}
|
||||||
else if (++i < argc)
|
else if (++i < argc)
|
||||||
|
{
|
||||||
UnityOptionExcludeNamed = argv[i];
|
UnityOptionExcludeNamed = argv[i];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UnityPrint("ERROR: No Test String to Exclude Matches For");
|
UnityPrint("ERROR: No Test String to Exclude Matches For");
|
||||||
@ -1596,6 +1719,7 @@ int UnityParseOptions(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
||||||
{
|
{
|
||||||
const char* lptr = longstring;
|
const char* lptr = longstring;
|
||||||
@ -1603,7 +1727,9 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
|||||||
const char* lnext = lptr;
|
const char* lnext = lptr;
|
||||||
|
|
||||||
if (*sptr == '*')
|
if (*sptr == '*')
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
while (*lptr)
|
while (*lptr)
|
||||||
{
|
{
|
||||||
@ -1634,9 +1760,11 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
|||||||
lptr = lnext;
|
lptr = lnext;
|
||||||
sptr = shortstring;
|
sptr = shortstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
int UnityStringArgumentMatches(const char* str)
|
int UnityStringArgumentMatches(const char* str)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
@ -1649,7 +1777,9 @@ int UnityStringArgumentMatches(const char* str)
|
|||||||
while (ptr1[0] != 0)
|
while (ptr1[0] != 0)
|
||||||
{
|
{
|
||||||
if ((ptr1[0] == '"') || (ptr1[0] == '\''))
|
if ((ptr1[0] == '"') || (ptr1[0] == '\''))
|
||||||
|
{
|
||||||
ptr1++;
|
ptr1++;
|
||||||
|
}
|
||||||
|
|
||||||
/* look for the start of the next partial */
|
/* look for the start of the next partial */
|
||||||
ptr2 = ptr1;
|
ptr2 = ptr1;
|
||||||
@ -1658,26 +1788,37 @@ int UnityStringArgumentMatches(const char* str)
|
|||||||
{
|
{
|
||||||
ptr2++;
|
ptr2++;
|
||||||
if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','))
|
if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','))
|
||||||
|
{
|
||||||
ptrf = &ptr2[1];
|
ptrf = &ptr2[1];
|
||||||
|
}
|
||||||
} while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','));
|
} while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','));
|
||||||
|
|
||||||
while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ',')))
|
while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ',')))
|
||||||
|
{
|
||||||
ptr2++;
|
ptr2++;
|
||||||
|
}
|
||||||
|
|
||||||
/* done if complete filename match */
|
/* done if complete filename match */
|
||||||
retval = IsStringInBiggerString(Unity.TestFile, ptr1);
|
retval = IsStringInBiggerString(Unity.TestFile, ptr1);
|
||||||
if (retval == 1)
|
if (retval == 1)
|
||||||
|
{
|
||||||
return retval;
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/* done if testname match after filename partial match */
|
/* done if testname match after filename partial match */
|
||||||
if ((retval == 2) && (ptrf != 0))
|
if ((retval == 2) && (ptrf != 0))
|
||||||
{
|
{
|
||||||
if (IsStringInBiggerString(Unity.CurrentTestName, ptrf))
|
if (IsStringInBiggerString(Unity.CurrentTestName, ptrf))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* done if complete testname match */
|
/* done if complete testname match */
|
||||||
if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1)
|
if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
ptr1 = ptr2;
|
ptr1 = ptr2;
|
||||||
}
|
}
|
||||||
@ -1686,6 +1827,7 @@ int UnityStringArgumentMatches(const char* str)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------*/
|
||||||
int UnityTestMatches(void)
|
int UnityTestMatches(void)
|
||||||
{
|
{
|
||||||
/* Check if this test name matches the included test pattern */
|
/* Check if this test name matches the included test pattern */
|
||||||
@ -1695,14 +1837,19 @@ int UnityTestMatches(void)
|
|||||||
retval = UnityStringArgumentMatches(UnityOptionIncludeNamed);
|
retval = UnityStringArgumentMatches(UnityOptionIncludeNamed);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if this test name matches the excluded test pattern */
|
/* Check if this test name matches the excluded test pattern */
|
||||||
if (UnityOptionExcludeNamed)
|
if (UnityOptionExcludeNamed)
|
||||||
{
|
{
|
||||||
if (UnityStringArgumentMatches(UnityOptionExcludeNamed))
|
if (UnityStringArgumentMatches(UnityOptionExcludeNamed))
|
||||||
|
{
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,6 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
|
|||||||
# undef UNITY_WEAK_PRAGMA
|
# undef UNITY_WEAK_PRAGMA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------
|
/*-------------------------------------------------------
|
||||||
* Internal Structs Needed
|
* Internal Structs Needed
|
||||||
*-------------------------------------------------------*/
|
*-------------------------------------------------------*/
|
||||||
@ -404,11 +403,13 @@ UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT,
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
UNITY_WITHIN = 0,
|
||||||
UNITY_EQUAL_TO = 1,
|
UNITY_EQUAL_TO = 1,
|
||||||
UNITY_GREATER_THAN = 2,
|
UNITY_GREATER_THAN = 2,
|
||||||
UNITY_GREATER_OR_EQUAL = 2 + UNITY_EQUAL_TO,
|
UNITY_GREATER_OR_EQUAL = 2 + UNITY_EQUAL_TO,
|
||||||
UNITY_SMALLER_THAN = 4,
|
UNITY_SMALLER_THAN = 4,
|
||||||
UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO
|
UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO,
|
||||||
|
UNITY_UNKNOWN
|
||||||
} UNITY_COMPARISON_T;
|
} UNITY_COMPARISON_T;
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
@ -429,7 +430,8 @@ typedef enum UNITY_FLOAT_TRAIT
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
UNITY_ARRAY_TO_VAL = 0,
|
UNITY_ARRAY_TO_VAL = 0,
|
||||||
UNITY_ARRAY_TO_ARRAY
|
UNITY_ARRAY_TO_ARRAY,
|
||||||
|
UNITY_ARRAY_UNKNOWN
|
||||||
} UNITY_FLAGS_T;
|
} UNITY_FLAGS_T;
|
||||||
|
|
||||||
struct UNITY_STORAGE_T
|
struct UNITY_STORAGE_T
|
||||||
@ -577,9 +579,9 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
|
|||||||
const UNITY_LINE_TYPE lineNumber,
|
const UNITY_LINE_TYPE lineNumber,
|
||||||
const UNITY_DISPLAY_STYLE_T style);
|
const UNITY_DISPLAY_STYLE_T style);
|
||||||
|
|
||||||
void UnityFail(const char* msg, const UNITY_LINE_TYPE line);
|
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
||||||
|
|
||||||
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line);
|
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_FLOAT
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
void UnityAssertFloatsWithin(const UNITY_FLOAT delta,
|
void UnityAssertFloatsWithin(const UNITY_FLOAT delta,
|
||||||
@ -835,9 +837,9 @@ int UnityTestMatches(void);
|
|||||||
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY)
|
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY)
|
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY)
|
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY)
|
||||||
#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL)
|
#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL)
|
||||||
#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL)
|
#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL)
|
||||||
#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL)
|
#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL)
|
||||||
#define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64)
|
#define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64)
|
||||||
#define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64)
|
#define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64)
|
||||||
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64)
|
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64)
|
||||||
@ -919,10 +921,10 @@ int UnityTestMatches(void);
|
|||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble)
|
||||||
#else
|
#else
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line))
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual, (UNITY_LINE_TYPE)(line), message)
|
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (UNITY_LINE_TYPE)(line), (message))
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_ARRAY)
|
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY)
|
||||||
#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_VAL)
|
#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN)
|
||||||
|
@ -18,7 +18,7 @@ Style/HashSyntax:
|
|||||||
EnforcedStyle: no_mixed_keys
|
EnforcedStyle: no_mixed_keys
|
||||||
|
|
||||||
# This is disabled because it seems to get confused over nested hashes
|
# This is disabled because it seems to get confused over nested hashes
|
||||||
Style/AlignHash:
|
Layout/AlignHash:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
EnforcedHashRocketStyle: table
|
EnforcedHashRocketStyle: table
|
||||||
EnforcedColonStyle: table
|
EnforcedColonStyle: table
|
||||||
|
@ -4,17 +4,16 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/'
|
|
||||||
$verbose = false
|
$verbose = false
|
||||||
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
require UNITY_ROOT + 'rakefile_helper'
|
require_relative 'rakefile_helper'
|
||||||
require 'rspec/core/rake_task'
|
require 'rspec/core/rake_task'
|
||||||
|
|
||||||
TEMP_DIRS = [
|
TEMP_DIRS = [
|
||||||
File.join(UNITY_ROOT, 'build'),
|
File.join(__dir__, 'build'),
|
||||||
File.join(UNITY_ROOT, 'sandbox')
|
File.join(__dir__, 'sandbox')
|
||||||
]
|
]
|
||||||
|
|
||||||
TEMP_DIRS.each do |dir|
|
TEMP_DIRS.each do |dir|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require UNITY_ROOT + '../auto/unity_test_summary'
|
require_relative '../auto/unity_test_summary'
|
||||||
require UNITY_ROOT + '../auto/generate_test_runner'
|
require_relative '../auto/generate_test_runner'
|
||||||
require UNITY_ROOT + '../auto/colour_reporter'
|
require_relative '../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
C_EXTENSION = '.c'.freeze
|
C_EXTENSION = '.c'.freeze
|
||||||
@ -179,7 +179,7 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def report_summary
|
def report_summary
|
||||||
summary = UnityTestSummary.new
|
summary = UnityTestSummary.new
|
||||||
summary.root = UNITY_ROOT
|
summary.root = __dir__
|
||||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||||
results_glob.tr!('\\', '/')
|
results_glob.tr!('\\', '/')
|
||||||
results = Dir[results_glob]
|
results = Dir[results_glob]
|
||||||
|
@ -46,6 +46,14 @@ void flushSpy(void) {}
|
|||||||
|
|
||||||
int SetToOneToFailInTearDown;
|
int SetToOneToFailInTearDown;
|
||||||
int SetToOneMeanWeAlreadyCheckedThisGuy;
|
int SetToOneMeanWeAlreadyCheckedThisGuy;
|
||||||
|
static unsigned NextExpectedStringIndex;
|
||||||
|
static unsigned NextExpectedCharIndex;
|
||||||
|
|
||||||
|
void suiteSetUp(void)
|
||||||
|
{
|
||||||
|
NextExpectedStringIndex = 0;
|
||||||
|
NextExpectedCharIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
@ -111,3 +119,56 @@ void test_NormalFailsStillWork(void)
|
|||||||
TEST_ASSERT_TRUE(0);
|
TEST_ASSERT_TRUE(0);
|
||||||
VERIFY_FAILS_END
|
VERIFY_FAILS_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(0, "abc")
|
||||||
|
TEST_CASE(1, "{")
|
||||||
|
TEST_CASE(2, "}")
|
||||||
|
TEST_CASE(3, ";")
|
||||||
|
TEST_CASE(4, "\"quoted\"")
|
||||||
|
void test_StringsArePreserved(unsigned index, const char * str)
|
||||||
|
{
|
||||||
|
static const char * const expected[] =
|
||||||
|
{
|
||||||
|
"abc",
|
||||||
|
"{",
|
||||||
|
"}",
|
||||||
|
";",
|
||||||
|
"\"quoted\""
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Ensure that no test cases are skipped by tracking the next expected index */
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(NextExpectedStringIndex, index);
|
||||||
|
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(expected[index], str);
|
||||||
|
|
||||||
|
NextExpectedStringIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(0, 'x')
|
||||||
|
TEST_CASE(1, '{')
|
||||||
|
TEST_CASE(2, '}')
|
||||||
|
TEST_CASE(3, ';')
|
||||||
|
TEST_CASE(4, '\'')
|
||||||
|
TEST_CASE(5, '"')
|
||||||
|
void test_CharsArePreserved(unsigned index, char c)
|
||||||
|
{
|
||||||
|
static const char expected[] =
|
||||||
|
{
|
||||||
|
'x',
|
||||||
|
'{',
|
||||||
|
'}',
|
||||||
|
';',
|
||||||
|
'\'',
|
||||||
|
'"'
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Ensure that no test cases are skipped by tracking the next expected index */
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(NextExpectedCharIndex, index);
|
||||||
|
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
|
||||||
|
TEST_ASSERT_EQUAL(expected[index], c);
|
||||||
|
|
||||||
|
NextExpectedCharIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -4497,49 +4497,69 @@ void testNotEqualFloatEachEqualLengthZero(void)
|
|||||||
|
|
||||||
void testFloatPrinting(void)
|
void testFloatPrinting(void)
|
||||||
{
|
{
|
||||||
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e-07", 0.00000050000005f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.100469499f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.100469499f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("2", 1.9999995f); /*Rounding to int place*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 0.9999995f); /*Rounding to int place*/
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.999999", 7.999999f); /*Not rounding*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.99999", 7.99999f); /*Not rounding*/
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00002", 16.00002f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0002", 16.0002f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00004", 16.00004f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0004", 16.0004f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.00006", 16.00006f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0006", 16.0006f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9999999", 9999999.0f); /*Last full print integer*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("999999", 999999.0f); /*Last full print integer*/
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-5e-07", -0.00000050000005f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.100469499f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.100469499f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-2", -1.9999995f); /*Rounding to int place*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -0.9999995f); /*Rounding to int place*/
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.999999", -7.999999f); /*Not rounding*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.99999", -7.99999f); /*Not rounding*/
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00002", -16.00002f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0002", -16.0002f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00004", -16.00004f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0004", -16.0004f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.00006", -16.00006f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0006", -16.0006f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-9999999", -9999999.0f); /*Last full print integer*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999", -999999.0f); /*Last full print integer*/
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0f);
|
/* Fails, prints "4.294968e+09" due to FP math imprecision
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e+09", 5000000000.0f);
|
* TEST_ASSERT_EQUAL_PRINT_FLOATING("4.294967e+09", 4294967296.0f); */
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("8e+09", 8.0e+09f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e+09", 5000000000.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("8.31e+09", 8309999104.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("8e+09", 8.0e+09f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 1.0e+10f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("8.309999e+09", 8309999104.0f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000000.0f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 1.0e+10f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000000.0f);
|
||||||
/* Some compilers have trouble with inexact float constants, a float cast works generally */
|
/* Some compilers have trouble with inexact float constants, a float cast works generally */
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005e+10", (float)1.000054e+10f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.000055e+10", (float)1.000055e+10f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.1e+38", (float)1.10000005e+38f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.6353e+10", 1.63529943e+10f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.635299e+10", 1.63529943e+10f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282e+38", 3.40282346638e38f);
|
/* Fails, prints "3.402824e+38" due to FP math imprecision
|
||||||
|
* TEST_ASSERT_EQUAL_PRINT_FLOATING("3.402823e+38", 3.40282346638e38f); */
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1e+10", -1.0e+10f);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.40282e+38", -3.40282346638e38f);
|
/* Fails, prints "-3.402824e+38" due to FP math imprecision
|
||||||
|
* TEST_ASSERT_EQUAL_PRINT_FLOATING("-3.402823e+38", -3.40282346638e38f); */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFloatPrintingRoundTiesToEven(void)
|
||||||
|
{
|
||||||
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0004882813", 0.00048828125f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("488281.3", 488281.25f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("5.000001e-07", 0.00000050000005f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.000001e-07", -0.00000050000005f);
|
||||||
|
#else /* Default to Round ties to even */
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.0004882812", 0.00048828125f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("488281.2", 488281.25f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("5e-07", 0.00000050000005f);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-5e-07", -0.00000050000005f);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4556,36 +4576,83 @@ void testFloatPrintingInfinityAndNaN(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_TEST_ALL_FLOATS_PRINT_OK) && defined(USING_OUTPUT_SPY)
|
||||||
|
#ifdef UNITY_INCLUDE_DOUBLE
|
||||||
static void printFloatValue(float f)
|
static void printFloatValue(float f)
|
||||||
{
|
{
|
||||||
char expected[18];
|
char expected[18];
|
||||||
char expected_lower[18];
|
|
||||||
char expected_higher[18];
|
|
||||||
|
|
||||||
startPutcharSpy();
|
startPutcharSpy();
|
||||||
|
|
||||||
UnityPrintFloat(f);
|
UnityPrintFloat(f);
|
||||||
|
|
||||||
sprintf(expected, "%.6g", f);
|
sprintf(expected, "%.9g", f);
|
||||||
|
|
||||||
/* We print all NaN's as "nan", not "-nan" */
|
/* We print all NaN's as "nan", not "-nan" */
|
||||||
if(strcmp(expected, "-nan") == 0) strcpy(expected, "nan");
|
if (strcmp(expected, "-nan") == 0) strcpy(expected, "nan");
|
||||||
|
|
||||||
/* Allow for rounding differences in last digit */
|
if (strcmp(expected, getBufferPutcharSpy()))
|
||||||
double lower = (double)f * 0.9999995;
|
|
||||||
double higher = (double)f * 1.0000005;
|
|
||||||
|
|
||||||
if (isfinite(lower)) sprintf(expected_lower, "%.6g", lower); else strcpy(expected_lower, expected);
|
|
||||||
if (isfinite(higher)) sprintf(expected_higher, "%.6g", higher); else strcpy(expected_higher, expected);
|
|
||||||
|
|
||||||
if (strcmp(expected, getBufferPutcharSpy()) != 0 &&
|
|
||||||
strcmp(expected_lower, getBufferPutcharSpy()) != 0 &&
|
|
||||||
strcmp(expected_higher, getBufferPutcharSpy()) != 0)
|
|
||||||
{
|
{
|
||||||
/* Fail with diagnostic printing */
|
/* Fail with diagnostic printing */
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void printFloatValue(float f)
|
||||||
|
{
|
||||||
|
char expected[18];
|
||||||
|
char expected_lower[18];
|
||||||
|
char expected_lower2[18];
|
||||||
|
char expected_lower3[18];
|
||||||
|
char expected_higher[18];
|
||||||
|
char expected_higher2[18];
|
||||||
|
char expected_higher3[18];
|
||||||
|
|
||||||
|
startPutcharSpy();
|
||||||
|
UnityPrintFloat(f);
|
||||||
|
|
||||||
|
sprintf(expected, "%.7g", f);
|
||||||
|
/* We print all NaN's as "nan", not "-nan" */
|
||||||
|
if (strcmp(expected, "-nan") == 0) strcpy(expected, "nan");
|
||||||
|
|
||||||
|
strcpy(expected_lower, expected);
|
||||||
|
strcpy(expected_lower2, expected);
|
||||||
|
strcpy(expected_lower3, expected);
|
||||||
|
strcpy(expected_higher, expected);
|
||||||
|
strcpy(expected_higher2, expected);
|
||||||
|
strcpy(expected_higher3, expected);
|
||||||
|
|
||||||
|
/* Allow for rounding differences in the last digit */
|
||||||
|
double lower = (double)f * 0.99999995;
|
||||||
|
double higher = (double)f * 1.00000005;
|
||||||
|
|
||||||
|
if(isfinite(lower)) sprintf(expected_lower, "%.7g", lower);
|
||||||
|
if(isfinite(higher)) sprintf(expected_higher, "%.7g", higher);
|
||||||
|
|
||||||
|
/* Outside [1,10000000] allow for relative error of +/-2.5e-7 */
|
||||||
|
if (f < 1.0 || f > 10000000)
|
||||||
|
{
|
||||||
|
double lower2 = (double)f * 0.99999985;
|
||||||
|
double lower3 = (double)f * 0.99999975;
|
||||||
|
double higher2 = (double)f * 1.00000015;
|
||||||
|
double higher3 = (double)f * 1.00000025;
|
||||||
|
|
||||||
|
if (isfinite(lower2)) sprintf(expected_lower2, "%.7g", lower2);
|
||||||
|
if (isfinite(lower3)) sprintf(expected_lower3, "%.7g", lower3);
|
||||||
|
if (isfinite(higher2)) sprintf(expected_higher2, "%.7g", higher2);
|
||||||
|
if (isfinite(higher3)) sprintf(expected_higher3, "%.7g", higher3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(expected, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_lower, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_lower2, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_lower3, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_higher, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_higher2, getBufferPutcharSpy()) != 0 &&
|
||||||
|
strcmp(expected_higher3, getBufferPutcharSpy()) != 0)
|
||||||
|
{
|
||||||
|
/* Fail with diagnostic printing */
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void testFloatPrintingRandomSamples(void)
|
void testFloatPrintingRandomSamples(void)
|
||||||
@ -5286,20 +5353,60 @@ void testDoublePrinting(void)
|
|||||||
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469", 0.10046949999999999);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0", 0.0);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967295.999999);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.99e-07", 0.000000499);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967295.9999995);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("5.0000005e-07", 0.00000050000005);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.29497e+09", 4294967296.0);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.100469499", 0.100469499);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 0.9999999995); /*Rounding to int place*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.0072e+15", 9007199254740990.0);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1", 1.0);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.25", 1.25);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("7.99999999", 7.99999999); /*Not rounding*/
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23457e+300", 9.23456789e+300);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000002", 16.0000002);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000004", 16.0000004);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000006", 16.0000006);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("999999999", 999999999.0); /*Last full print integer*/
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469", -0.10046949999999999);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.999999);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.29497e+09", -4294967295.9999995);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.0000005e-07", -0.00000050000005);
|
||||||
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100);
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469499", -0.100469499);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -0.9999999995); /*Rounding to int place*/
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1", -1.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-1.25", -1.25);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7.99999999", -7.99999999); /*Not rounding*/
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000002", -16.0000002);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000004", -16.0000004);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-16.0000006", -16.0000006);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-999999999", -999999999.0); /*Last full print integer*/
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("0.1004695", 0.10046949999999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967295.9);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("4.2949673e+09", 4294967296.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 9999999995.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199254740990.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("7e+100", 7.0e+100);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("3e+200", 3.0e+200);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.23456789e+300", 9.23456789e+300);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.1004695", -0.10046949999999999);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967295.9);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.2949673e+09", -4294967296.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("-7e+100", -7.0e+100);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDoublePrintingRoundTiesToEven(void)
|
||||||
|
{
|
||||||
|
#if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_EXCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY)
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
#ifdef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00000001e+10", 10000000050.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719925e+15", 9007199245000000.0);
|
||||||
|
#else /* Default to Round ties to even */
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("1e+10", 10000000050.0);
|
||||||
|
TEST_ASSERT_EQUAL_PRINT_FLOATING("9.00719924e+15", 9007199245000000.0);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user