提交 b10a0942 编写于 作者: M mvandervoord

- 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
上级 07d2848d
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
\ No newline at end of file
......@@ -22,8 +22,8 @@ class UnityTestSummary
results = @targets.map {|target| target.gsub(/\\/,'/')}
# Dig through each result file, looking for details on pass/fail:
failure_output = ""
ignore_output = ""
failure_output = []
ignore_output = []
results.each do |result_file|
lines = File.readlines(result_file).map { |line| line.chomp }
......@@ -32,8 +32,8 @@ class UnityTestSummary
else
summary_line = -2
output = get_details(result_file, lines)
failure_output += output[:failures] if !output[:failures].empty?
ignore_output += output[:ignores] if !output[:ignores].empty?
failure_output << output[:failures] unless output[:failures].empty?
ignore_output << output[:ignores] unless output[:ignores].empty?
tests,failures,ignored = parse_test_summary(lines[summary_line])
@total_tests += tests
@failures += failures
......@@ -46,7 +46,7 @@ class UnityTestSummary
@report += "--------------------------\n"
@report += "UNITY IGNORED TEST SUMMARY\n"
@report += "--------------------------\n"
@report += ignore_output
@report += ignore_output.flatten.join("\n")
end
if @failures > 0
......@@ -54,7 +54,7 @@ class UnityTestSummary
@report += "--------------------------\n"
@report += "UNITY FAILED TEST SUMMARY\n"
@report += "--------------------------\n"
@report += failure_output
@report += failure_output.flatten.join("\n")
end
@report += "\n"
......@@ -86,53 +86,17 @@ class UnityTestSummary
@@root=nil
def get_details(result_file, lines)
fail_lines = [] # indices of lines with failures
ignore_lines = [] # indices of lines with ignores
lines.each_with_index do |line,i|
if (i < (lines.length - 2) && !(line =~ /PASS$/))
if line =~ /(^.*\.c):(\d+)/
if line =~ /IGNORED$/
ignore_lines << i
else
fail_lines << i
end
elsif line =~ /IGNORED$/
ignore_lines << i
end
results = { :failures => [], :ignores => [], :successes => [] }
lines.each do |line|
line_out = line.gsub(/\//, "\\")
src_file,src_line,test_name,status,msg = line.split(/:/)
case(status)
when 'IGNORE' then results[:ignores] << line_out
when 'FAIL' then results[:failures] << line_out
when 'PASS' then results[:successes] << line_out
end
end
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}
return results
end
def parse_test_summary(summary)
......
......@@ -5,41 +5,19 @@
static char message[1024];
void AssertEqualUintArray(const unsigned int* expected, const unsigned 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_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)
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 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");
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
UNITY_TEST_ASSERT_EQUAL_INT(expected.y, actual.y, line, "Example Struct Failed For Field y");
}
......@@ -3,15 +3,13 @@
#include "Types.h"
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
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);
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length, const unsigned short line);
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line);
#define TEST_ASSERT_EQUAL_uint32_ARRAY(expected, actual, length) {AssertEqualUintArray(expected, actual, length);}
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualIntArray(expected, actual, length);}
#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 UNITY_TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length, line, message) AssertFloatArrayWithin(tolerance, expected, actual, length, line);
#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) 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
......@@ -2,17 +2,12 @@ require 'yaml'
require 'fileutils'
require '../auto/unity_test_summary'
require '../auto/generate_test_runner'
require '../auto/colour_reporter'
module RakefileHelpers
C_EXTENSION = '.c'
def report(message)
puts message
$stdout.flush
$stderr.flush
end
def load_configuration(config_file)
$cfg_file = config_file
$cfg = YAML.load(File.read($cfg_file))
......
......@@ -32,4 +32,5 @@ linker:
bin_files:
prefix: '-o'
extension: '.exe'
destination: *build_path
\ No newline at end of file
destination: *build_path
colour: true
\ No newline at end of file
......@@ -80,4 +80,5 @@ simulator:
- -p
- [*tools_root, 'arm\config\ioat91sam7X256.ddf']
- -d
- sim
\ No newline at end of file
- sim
colour: true
\ No newline at end of file
......@@ -70,4 +70,5 @@ simulator:
- -p
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
- -d
- sim
\ No newline at end of file
- sim
colour: true
\ No newline at end of file
......@@ -86,4 +86,5 @@ simulator:
- --cpu MSP430F5438
- -p
- [*core_config, 'MSP430F5438.ddf']
- -d sim
\ No newline at end of file
- -d sim
colour: true
\ No newline at end of file
......@@ -33,5 +33,5 @@ task :config, :config_file do |t, args|
end
task :no_color do
$color_output = false
$colour_output = false
end
......@@ -2,53 +2,17 @@ require 'yaml'
require 'fileutils'
require 'auto/unity_test_summary'
require 'auto/generate_test_runner'
require 'auto/colour_prompt'
require 'auto/colour_reporter'
#require 'auto/test_file_filter'
module RakefileHelpers
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)
$cfg_file = config_file
$cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
end
def configure_clean
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册