From f5ce02f135764f7b964c66d90519ad44f14b07aa Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Fri, 13 Aug 2010 00:32:34 +0000 Subject: [PATCH] - removed pointless cast from UnityPrint - test executable returns number of failures as exit status - caught up lame text docs git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@90 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e --- auto/generate_test_runner.rb | 7 +- docs/Unity Summary.txt | 131 ++++++++++++++++------------------- examples/rakefile_helper.rb | 6 +- src/unity.c | 5 +- src/unity_internals.h | 2 +- 5 files changed, 69 insertions(+), 82 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 0845019..3d8e6ae 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -25,7 +25,6 @@ class UnityTestRunnerGenerator yaml_guts = YAML.load_file(config_file) yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock] options[:cexception] = 1 unless (yaml_goodness[:plugins] & ['cexception', :cexception]).empty? - options[:coverage ] = 1 if (yaml_goodness[:coverage]) options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering]) options[:framework] = (yaml_goodness[:framework] || :unity) options[:includes] << (yaml_goodness[:includes]) @@ -126,7 +125,6 @@ class UnityTestRunnerGenerator output.puts('#include ') output.puts('#include ') output.puts('#include "CException.h"') if @options[:cexception] - output.puts('#include "BullseyeCoverage.h"') if @options[:coverage] mocks.each do |mock| output.puts("#include \"#{mock.gsub('.h','')}.h\"") end @@ -230,9 +228,7 @@ class UnityTestRunnerGenerator end output.puts() - output.puts(" UnityEnd();") - output.puts(" cov_write();") if @options[:coverage] - output.puts(" return 0;") + output.puts(" return UnityEnd();") output.puts("}") end end @@ -242,7 +238,6 @@ if ($0 == __FILE__) usage = ["usage: ruby #{__FILE__} (yaml) (options) input_test_file output_test_runner (includes)", " blah.yml - will use config options in the yml file (see CMock docs)", " -cexception - include cexception support", - " -coverage - include bullseye coverage support", " -order - include cmock order-enforcement support" ] options = { :includes => [] } diff --git a/docs/Unity Summary.txt b/docs/Unity Summary.txt index b1bb79f..5384b6e 100644 --- a/docs/Unity Summary.txt +++ b/docs/Unity Summary.txt @@ -90,85 +90,51 @@ This test is automatically marked as a failure. The message is output stating w Numerical Assertions: Integers ------------------------------ +TEST_ASSERT_EQUAL_INT(expected, actual) +TEST_ASSERT_EQUAL_INT8(expected, actual) +TEST_ASSERT_EQUAL_INT16(expected, actual) +TEST_ASSERT_EQUAL_INT32(expected, actual) +TEST_ASSERT_EQUAL_INT64(expected, actual) + +Compare two integers for equality and display errors as signed integers. A cast will be performed +to your natural integer size so often this can just be used. When you need to specify the exact size, +like when comparing arrays, you can use a specific version: + + + +TEST_ASSERT_EQUAL_UINT(expected, actual) + +Compare two integers for equality and display errors as unsigned integers. Like INT, there are +variants for different sizes also. + + + +TEST_ASSERT_EQUAL_HEX(expected, actual) + +Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, +you can specify the size... here the size will also effect how many nibbles are shown (for example, HEX16 +will show 4 nibbles). + +_ARRAY + +You can append _ARRAY to any of these macros to make an array comparison of that type. Here you will +need to care a bit more about the actual size of the value being checked. You will also specify an +additional argument which is the number of elements to compare. For example: + +TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, elements) + + TEST_ASSERT_EQUAL(expected, actual) Another way of calling TEST_ASSERT_EQUAL_INT -TEST_ASSERT_EQUAL_INT(expected, actual) -Compare two integers for equality and display errors as signed integers. - -TEST_ASSERT_EQUAL_UINT(expected, actual) - -Compare two integers for equality and display errors as unsigned integers. - -TEST_ASSERT_EQUAL_HEX8(expected, actual) - -Compare two integers for equality and display errors as an 8-bit hex value - -TEST_ASSERT_EQUAL_HEX16(expected, actual) - -Compare two integers for equality and display errors as an 16-bit hex value - -TEST_ASSERT_EQUAL_HEX32(expected, actual) - -Compare two integers for equality and display errors as an 32-bit hex value - -TEST_ASSERT_EQUAL_HEX(expected, actual) - -Another way of calling TEST_ASSERT_EQUAL_HEX32 TEST_ASSERT_INT_WITHIN(delta, expected, actual) -Asserts that the actual value is within plus or minus delta of the expected value. +Asserts that the actual value is within plus or minus delta of the expected value. This also comes in +size specific variants. -TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) - -Another way of calling TEST_ASSERT_EQUAL_INT_MESSAGE - -TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) - -Compare two integers for equality and display errors as signed integers. Outputs a custom message on failure. - -TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) - -Compare two integers for equality and display errors as unsigned integers. Outputs a custom message on failure. - -TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) - -Compare two integers for equality and display errors as an 8-bit hex value. Outputs a custom message on failure. - -TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) - -Compare two integers for equality and display errors as an 16-bit hex value. Outputs a custom message on failure. - -TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) - -Compare two integers for equality and display errors as an 32-bit hex value. Outputs a custom message on failure. - -TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) - -Another way of calling TEST_ASSERT_EQUAL_HEX32_MESSAGE - ------------------------------------- -Numerical Assertions: Integer Arrays ------------------------------------- - -TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) - -Compare two arrays for equality and display errors as signed integers. - -TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) - -Compare two arrays for equality and display errors as unsigned integers. - -TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) - -Compare two arrays for equality and display errors as 32-bit hex values. - -TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) - -Another way of calling TEST_ASSERT_EQUAL_HEX32_ARRAY. ----------------------------- Numerical Assertions: Bitwise @@ -202,6 +168,10 @@ TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) Asserts that the actual value is within plus or minus delta of the expected value. +TEST_ASSERT_EQUAL_FLOAT(expected, actual) + +Asserts that two floating point values are "equal" within a small % delta of the expected value. + ----------------- String Assertions ----------------- @@ -228,3 +198,24 @@ TEST_ASSERT_NOT_NULL(pointer) Fails if the pointer is equal to NULL + +----------------- +Memory Assertions +----------------- + +TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) + +Compare two blocks of memory. This is a good generic assertion for types that can't be coerced into acting like +standard types... but since it's a memory compare, you have to be careful that your data types are packed. + +-------- +_MESSAGE +-------- + +you can append _MESSAGE to any of the macros to make them take an additional argument. This argument +is a string that will be printed at the end of the failure strings. This is useful for specifying more +information about the problem. + + + + diff --git a/examples/rakefile_helper.rb b/examples/rakefile_helper.rb index d908087..4d2fb29 100644 --- a/examples/rakefile_helper.rb +++ b/examples/rakefile_helper.rb @@ -139,11 +139,11 @@ module RakefileHelpers return {:command => command, :pre_support => pre_support, :post_support => post_support} end - def execute(command_string, verbose=true) + def execute(command_string, verbose=true, raise_on_fail=true) report command_string output = `#{command_string}`.chomp report(output) if (verbose && !output.nil? && (output.length > 0)) - if $?.exitstatus != 0 + if (($?.exitstatus != 0) and (raise_on_fail)) raise "Command failed. (Returned #{$?.exitstatus})" end return output @@ -215,7 +215,7 @@ module RakefileHelpers else cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" end - output = execute(cmd_str) + output = execute(cmd_str, true, false) test_results = $cfg['compiler']['build_path'] + test_base if output.match(/OK$/m).nil? test_results += '.testfail' diff --git a/src/unity.c b/src/unity.c index 6645cb9..9d8d29d 100644 --- a/src/unity.c +++ b/src/unity.c @@ -34,7 +34,7 @@ const char* UnityStrNullPointerForActual = " Actual pointer was NULL"; void UnityPrint(const char* string) { - unsigned char* pch = (unsigned char*)string; + const char* pch = string; if (pch != NULL) { @@ -796,7 +796,7 @@ void UnityBegin(void) } //----------------------------------------------- -void UnityEnd(void) +int UnityEnd(void) { UnityPrint("-----------------------"); UNITY_PRINT_CR_LF; @@ -816,4 +816,5 @@ void UnityEnd(void) UnityPrint("FAIL"); } UNITY_PRINT_CR_LF; + return Unity.TestFailures; } diff --git a/src/unity_internals.h b/src/unity_internals.h index 0639b82..07fbbaa 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -187,7 +187,7 @@ extern struct _Unity Unity; //------------------------------------------------------- void UnityBegin(void); -void UnityEnd(void); +int UnityEnd(void); void UnityConcludeTest(void); //-------------------------------------------------------