mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-18 12:51:44 +08:00
- centralized pretty printing so people can use it more easily
- updated unity helper examples to get them working again - got examples running again git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@65 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
33
auto/colour_reporter.rb
Normal file
33
auto/colour_reporter.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt"
|
||||||
|
|
||||||
|
$colour_output = true
|
||||||
|
|
||||||
|
def report(message)
|
||||||
|
if not $colour_output
|
||||||
|
$stdout.puts(message)
|
||||||
|
else
|
||||||
|
message.each_line do |line|
|
||||||
|
line.chomp!
|
||||||
|
colour = case(line)
|
||||||
|
when /Tests\s+(\d+)\s+Failures\s+\d+\s+Ignored/
|
||||||
|
($1.to_i == 0) ? :green : :red
|
||||||
|
when /PASS/
|
||||||
|
:green
|
||||||
|
when /^OK$/
|
||||||
|
:green
|
||||||
|
when /FAIL/
|
||||||
|
:red
|
||||||
|
when /IGNORE/
|
||||||
|
:yellow
|
||||||
|
when /^(Creating|Compiling|Linking)/
|
||||||
|
:white
|
||||||
|
else
|
||||||
|
:blue
|
||||||
|
end
|
||||||
|
colour_puts(colour, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
$stdout.flush
|
||||||
|
$stderr.flush
|
||||||
|
end
|
@ -22,8 +22,8 @@ class UnityTestSummary
|
|||||||
results = @targets.map {|target| target.gsub(/\\/,'/')}
|
results = @targets.map {|target| target.gsub(/\\/,'/')}
|
||||||
|
|
||||||
# Dig through each result file, looking for details on pass/fail:
|
# Dig through each result file, looking for details on pass/fail:
|
||||||
failure_output = ""
|
failure_output = []
|
||||||
ignore_output = ""
|
ignore_output = []
|
||||||
|
|
||||||
results.each do |result_file|
|
results.each do |result_file|
|
||||||
lines = File.readlines(result_file).map { |line| line.chomp }
|
lines = File.readlines(result_file).map { |line| line.chomp }
|
||||||
@ -32,8 +32,8 @@ class UnityTestSummary
|
|||||||
else
|
else
|
||||||
summary_line = -2
|
summary_line = -2
|
||||||
output = get_details(result_file, lines)
|
output = get_details(result_file, lines)
|
||||||
failure_output += output[:failures] if !output[:failures].empty?
|
failure_output << output[:failures] unless output[:failures].empty?
|
||||||
ignore_output += output[:ignores] if !output[:ignores].empty?
|
ignore_output << output[:ignores] unless output[:ignores].empty?
|
||||||
tests,failures,ignored = parse_test_summary(lines[summary_line])
|
tests,failures,ignored = parse_test_summary(lines[summary_line])
|
||||||
@total_tests += tests
|
@total_tests += tests
|
||||||
@failures += failures
|
@failures += failures
|
||||||
@ -46,7 +46,7 @@ class UnityTestSummary
|
|||||||
@report += "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
@report += "UNITY IGNORED TEST SUMMARY\n"
|
@report += "UNITY IGNORED TEST SUMMARY\n"
|
||||||
@report += "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
@report += ignore_output
|
@report += ignore_output.flatten.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
if @failures > 0
|
if @failures > 0
|
||||||
@ -54,7 +54,7 @@ class UnityTestSummary
|
|||||||
@report += "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
@report += "UNITY FAILED TEST SUMMARY\n"
|
@report += "UNITY FAILED TEST SUMMARY\n"
|
||||||
@report += "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
@report += failure_output
|
@report += failure_output.flatten.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
@report += "\n"
|
@report += "\n"
|
||||||
@ -86,53 +86,17 @@ class UnityTestSummary
|
|||||||
@@root=nil
|
@@root=nil
|
||||||
|
|
||||||
def get_details(result_file, lines)
|
def get_details(result_file, lines)
|
||||||
fail_lines = [] # indices of lines with failures
|
results = { :failures => [], :ignores => [], :successes => [] }
|
||||||
ignore_lines = [] # indices of lines with ignores
|
lines.each do |line|
|
||||||
lines.each_with_index do |line,i|
|
line_out = line.gsub(/\//, "\\")
|
||||||
if (i < (lines.length - 2) && !(line =~ /PASS$/))
|
src_file,src_line,test_name,status,msg = line.split(/:/)
|
||||||
if line =~ /(^.*\.c):(\d+)/
|
case(status)
|
||||||
if line =~ /IGNORED$/
|
when 'IGNORE' then results[:ignores] << line_out
|
||||||
ignore_lines << i
|
when 'FAIL' then results[:failures] << line_out
|
||||||
else
|
when 'PASS' then results[:successes] << line_out
|
||||||
fail_lines << i
|
|
||||||
end
|
|
||||||
elsif line =~ /IGNORED$/
|
|
||||||
ignore_lines << i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return results
|
||||||
failures = []
|
|
||||||
fail_lines.each do |fail_line|
|
|
||||||
if lines[fail_line] =~ /\w:/
|
|
||||||
src_file,src_line,test_name,msg = lines[fail_line].split(/:/)
|
|
||||||
src_file = "#{@root}#{src_file}" unless @root == nil || @root.length == 0
|
|
||||||
detail = "#{src_file}:#{src_line}:#{test_name}:: #{msg}"
|
|
||||||
failures << detail.gsub(/\//, "\\")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if failures.length == 0
|
|
||||||
failure_results = ""
|
|
||||||
else
|
|
||||||
failure_results = failures.join("\n") + "\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
ignores = []
|
|
||||||
ignore_lines.each do |ignore_line|
|
|
||||||
if lines[ignore_line] =~ /\w:/
|
|
||||||
src_file,src_line,test_name,msg = lines[ignore_line].split(/:/)
|
|
||||||
src_file = "#{@root}#{src_file}" unless @root == nil || @root.length == 0
|
|
||||||
detail = "#{src_file}:#{src_line}:#{test_name}:: #{msg}"
|
|
||||||
ignores << detail.gsub(/\//, "\\")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if ignores.length == 0
|
|
||||||
ignore_results = ""
|
|
||||||
else
|
|
||||||
ignore_results = ignores.join("\n") + "\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
results = {:failures => failure_results, :ignores => ignore_results}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_test_summary(summary)
|
def parse_test_summary(summary)
|
||||||
|
@ -5,41 +5,19 @@
|
|||||||
|
|
||||||
static char message[1024];
|
static char message[1024];
|
||||||
|
|
||||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length)
|
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length, const unsigned short line)
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for (i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
sprintf(message, "Array comparison failed at index %u.", i);
|
|
||||||
TEST_ASSERT_EQUAL_UINT_MESSAGE(expected[i], actual[i], message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for (i = 0; i < length; i++)
|
|
||||||
{
|
|
||||||
sprintf(message, "Array comparison failed at index %u.", i);
|
|
||||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected[i], actual[i], message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length)
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
sprintf(message, "Array mismatch at index %u, Expected %f, Actual %f, Tolerance %f, Delta %f", i, expected[i], actual[i], tolerance, (expected[i]-actual[i]));
|
sprintf(message, "Array mismatch at index %u, Expected %f, Actual %f, Tolerance %f, Delta %f", i, expected[i], actual[i], tolerance, (expected[i]-actual[i]));
|
||||||
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
|
UNITY_TEST_ASSERT_WITHIN_FLOAT(tolerance, expected[i], actual[i], line, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual)
|
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line)
|
||||||
{
|
{
|
||||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, "Example Struct Failed For Field x");
|
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
|
||||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
|
UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y");
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,13 @@
|
|||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
|
|
||||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
|
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length, const unsigned short line);
|
||||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
|
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line);
|
||||||
void AssertEqualCharArray(const char expected[], const char actual[], const int length);
|
|
||||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length);
|
|
||||||
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual);
|
|
||||||
|
|
||||||
#define TEST_ASSERT_EQUAL_uint32_ARRAY(expected, actual, length) {AssertEqualUintArray(expected, actual, length);}
|
#define UNITY_TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length, line, message) AssertFloatArrayWithin(tolerance, expected, actual, length, line);
|
||||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualIntArray(expected, actual, length);}
|
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) AssertEqualExampleStruct(expected, actual, line);
|
||||||
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertFloatArrayWithin(tolerance, expected, actual, length);}
|
|
||||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) UNITY_TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, __LINE__, NULL);
|
||||||
|
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
|
||||||
|
|
||||||
#endif // _TESTHELPER_H
|
#endif // _TESTHELPER_H
|
||||||
|
@ -2,17 +2,12 @@ require 'yaml'
|
|||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require '../auto/unity_test_summary'
|
require '../auto/unity_test_summary'
|
||||||
require '../auto/generate_test_runner'
|
require '../auto/generate_test_runner'
|
||||||
|
require '../auto/colour_reporter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
|
|
||||||
C_EXTENSION = '.c'
|
C_EXTENSION = '.c'
|
||||||
|
|
||||||
def report(message)
|
|
||||||
puts message
|
|
||||||
$stdout.flush
|
|
||||||
$stderr.flush
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
$cfg_file = config_file
|
$cfg_file = config_file
|
||||||
$cfg = YAML.load(File.read($cfg_file))
|
$cfg = YAML.load(File.read($cfg_file))
|
||||||
|
1
gcc.yml
1
gcc.yml
@ -33,3 +33,4 @@ linker:
|
|||||||
prefix: '-o'
|
prefix: '-o'
|
||||||
extension: '.exe'
|
extension: '.exe'
|
||||||
destination: *build_path
|
destination: *build_path
|
||||||
|
colour: true
|
@ -81,3 +81,4 @@ simulator:
|
|||||||
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
|
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
|
||||||
- -d
|
- -d
|
||||||
- sim
|
- sim
|
||||||
|
colour: true
|
@ -71,3 +71,4 @@ simulator:
|
|||||||
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
|
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
|
||||||
- -d
|
- -d
|
||||||
- sim
|
- sim
|
||||||
|
colour: true
|
@ -87,3 +87,4 @@ simulator:
|
|||||||
- -p
|
- -p
|
||||||
- [*core_config, 'MSP430F5438.ddf']
|
- [*core_config, 'MSP430F5438.ddf']
|
||||||
- -d sim
|
- -d sim
|
||||||
|
colour: true
|
@ -33,5 +33,5 @@ task :config, :config_file do |t, args|
|
|||||||
end
|
end
|
||||||
|
|
||||||
task :no_color do
|
task :no_color do
|
||||||
$color_output = false
|
$colour_output = false
|
||||||
end
|
end
|
||||||
|
@ -2,53 +2,17 @@ require 'yaml'
|
|||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'auto/unity_test_summary'
|
require 'auto/unity_test_summary'
|
||||||
require 'auto/generate_test_runner'
|
require 'auto/generate_test_runner'
|
||||||
require 'auto/colour_prompt'
|
require 'auto/colour_reporter'
|
||||||
#require 'auto/test_file_filter'
|
#require 'auto/test_file_filter'
|
||||||
|
|
||||||
module RakefileHelpers
|
module RakefileHelpers
|
||||||
|
|
||||||
C_EXTENSION = '.c'
|
C_EXTENSION = '.c'
|
||||||
$color_output = true
|
|
||||||
|
|
||||||
def report(message)
|
|
||||||
if not $color_output
|
|
||||||
puts($stdout.puts(message))
|
|
||||||
else
|
|
||||||
message.each_line do |line|
|
|
||||||
line.chomp!
|
|
||||||
if line.include?('Tests') &&
|
|
||||||
line.include?('Failures') &&
|
|
||||||
line.include?('Ignored')
|
|
||||||
if line.include?('0 Failures')
|
|
||||||
colour = :green
|
|
||||||
else
|
|
||||||
colour = :red
|
|
||||||
end
|
|
||||||
elsif line.include?('PASS') ||
|
|
||||||
line == 'OK'
|
|
||||||
colour = :green
|
|
||||||
elsif line.include? "Running Unity system tests..."
|
|
||||||
colour = :blue
|
|
||||||
elsif line.include?('FAIL') ||
|
|
||||||
line.include?('Expected') ||
|
|
||||||
line.include?('Memory Mismatch') ||
|
|
||||||
line.include?('not within delta')
|
|
||||||
colour = :red
|
|
||||||
elsif line.include?(' IGNORED')
|
|
||||||
colour = :yellow
|
|
||||||
else
|
|
||||||
colour = :blue
|
|
||||||
end
|
|
||||||
colour_puts colour, line
|
|
||||||
end
|
|
||||||
end
|
|
||||||
$stdout.flush
|
|
||||||
$stderr.flush
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_configuration(config_file)
|
def load_configuration(config_file)
|
||||||
$cfg_file = config_file
|
$cfg_file = config_file
|
||||||
$cfg = YAML.load(File.read($cfg_file))
|
$cfg = YAML.load(File.read($cfg_file))
|
||||||
|
$colour_output = false unless $cfg['colour']
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure_clean
|
def configure_clean
|
||||||
|
Reference in New Issue
Block a user