From b10a0942143a3f84256371f2de81d05daa6574e6 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Sun, 21 Mar 2010 02:53:17 +0000 Subject: [PATCH] - 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 --- auto/colour_reporter.rb | 33 ++++++++++++++++++ auto/unity_test_summary.rb | 66 ++++++++--------------------------- examples/helper/UnityHelper.c | 32 +++-------------- examples/helper/UnityHelper.h | 16 ++++----- examples/rakefile_helper.rb | 7 +--- gcc.yml | 3 +- iar_arm_v4.yml | 3 +- iar_arm_v5.yml | 3 +- iar_msp430.yml | 3 +- rakefile.rb | 2 +- rakefile_helper.rb | 40 ++------------------- 11 files changed, 72 insertions(+), 136 deletions(-) create mode 100644 auto/colour_reporter.rb diff --git a/auto/colour_reporter.rb b/auto/colour_reporter.rb new file mode 100644 index 0000000..c8084a6 --- /dev/null +++ b/auto/colour_reporter.rb @@ -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 \ No newline at end of file diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index ba2c00e..d167d27 100644 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -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) diff --git a/examples/helper/UnityHelper.c b/examples/helper/UnityHelper.c index 5a3d08a..db4d310 100644 --- a/examples/helper/UnityHelper.c +++ b/examples/helper/UnityHelper.c @@ -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"); } diff --git a/examples/helper/UnityHelper.h b/examples/helper/UnityHelper.h index 75e962b..1fb3a0e 100644 --- a/examples/helper/UnityHelper.h +++ b/examples/helper/UnityHelper.h @@ -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 diff --git a/examples/rakefile_helper.rb b/examples/rakefile_helper.rb index 4933295..6da5973 100644 --- a/examples/rakefile_helper.rb +++ b/examples/rakefile_helper.rb @@ -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)) diff --git a/gcc.yml b/gcc.yml index bb34878..82783f3 100644 --- a/gcc.yml +++ b/gcc.yml @@ -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 diff --git a/iar_arm_v4.yml b/iar_arm_v4.yml index b6a222b..89efb95 100644 --- a/iar_arm_v4.yml +++ b/iar_arm_v4.yml @@ -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 diff --git a/iar_arm_v5.yml b/iar_arm_v5.yml index 8173acd..622dbc9 100644 --- a/iar_arm_v5.yml +++ b/iar_arm_v5.yml @@ -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 diff --git a/iar_msp430.yml b/iar_msp430.yml index fd16bf2..8fceaea 100644 --- a/iar_msp430.yml +++ b/iar_msp430.yml @@ -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 diff --git a/rakefile.rb b/rakefile.rb index a132bfb..cf8f610 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -33,5 +33,5 @@ task :config, :config_file do |t, args| end task :no_color do - $color_output = false + $colour_output = false end diff --git a/rakefile_helper.rb b/rakefile_helper.rb index 3bd3a00..1147de5 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -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 -- GitLab