mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-20 14:07:07 +08:00
- rework to not bother with any of the ever-changing test frameworks in Ruby (sigh) for self-testing
- started working on cleaner floating point support. more coming.
This commit is contained in:
@ -33,9 +33,11 @@ task :unit => [:prepare_for_tests] do
|
|||||||
run_tests get_unit_test_files
|
run_tests get_unit_test_files
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:scripts) do |t|
|
desc "Test unity's helper scripts"
|
||||||
t.pattern = 'test/test_*.rb'
|
task :scripts => [:prepare_for_tests] do
|
||||||
t.verbose = true
|
Dir['test/test_*.rb'].each do |scriptfile|
|
||||||
|
require "./"+scriptfile
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Generate test summary"
|
desc "Generate test summary"
|
||||||
|
@ -83,6 +83,15 @@ module RakefileHelpers
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should(behave, &block)
|
||||||
|
if block
|
||||||
|
puts "Should " + behave
|
||||||
|
yield block
|
||||||
|
else
|
||||||
|
puts "UNIMPLEMENTED CASE: Should #{behave}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def build_compiler_fields
|
def build_compiler_fields
|
||||||
command = tackit($cfg['compiler']['path'])
|
command = tackit($cfg['compiler']['path'])
|
||||||
if $cfg['compiler']['defines']['items'].nil?
|
if $cfg['compiler']['defines']['items'].nil?
|
||||||
|
47
src/unity.c
47
src/unity.c
@ -28,6 +28,7 @@ const char* UnityStrDelta = " Values Not Within Delta ";
|
|||||||
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
||||||
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
|
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
|
||||||
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
|
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
|
||||||
|
const char* UnityStrNot = "Not ";
|
||||||
const char* UnityStrInf = "Infinity";
|
const char* UnityStrInf = "Infinity";
|
||||||
const char* UnityStrNegInf = "Negative Infinity";
|
const char* UnityStrNegInf = "Negative Infinity";
|
||||||
const char* UnityStrNaN = "NaN";
|
const char* UnityStrNaN = "NaN";
|
||||||
@ -614,6 +615,7 @@ void UnityAssertFloatsWithin(const _UF delta,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertFloatIsInf(const _UF actual,
|
void UnityAssertFloatIsInf(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
@ -624,16 +626,21 @@ void UnityAssertFloatIsInf(const _UF actual,
|
|||||||
// produces
|
// produces
|
||||||
// error C2124: divide or mod by zero
|
// error C2124: divide or mod by zero
|
||||||
// As a workaround, place 0 into a variable.
|
// As a workaround, place 0 into a variable.
|
||||||
if ((1.0f / f_zero) != actual)
|
_U_SINT is_inf = ((1.0f / f_zero) == actual) ? 1 : 0;
|
||||||
|
if (is_inf != should_be)
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
#ifdef UNITY_FLOAT_VERBOSE
|
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrint(UnityStrExpected);
|
||||||
|
if (!should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
UnityPrint(UnityStrInf);
|
UnityPrint(UnityStrInf);
|
||||||
UnityPrint(UnityStrWas);
|
UnityPrint(UnityStrWas);
|
||||||
|
#ifdef UNITY_FLOAT_VERBOSE
|
||||||
UnityPrintFloat(actual);
|
UnityPrintFloat(actual);
|
||||||
#else
|
#else
|
||||||
UnityPrint(UnityStrDelta);
|
if (should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
|
UnityPrint(UnityStrInf);
|
||||||
#endif
|
#endif
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
@ -642,22 +649,28 @@ void UnityAssertFloatIsInf(const _UF actual,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertFloatIsNegInf(const _UF actual,
|
void UnityAssertFloatIsNegInf(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
UNITY_SKIP_EXECUTION;
|
UNITY_SKIP_EXECUTION;
|
||||||
|
|
||||||
// The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
|
// The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
|
||||||
if ((-1.0f / f_zero) != actual)
|
_U_SINT is_inf = ((-1.0f / f_zero) == actual) ? 1 : 0;
|
||||||
|
if (is_inf != should_be)
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
#ifdef UNITY_FLOAT_VERBOSE
|
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrint(UnityStrExpected);
|
||||||
|
if (!should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
UnityPrint(UnityStrNegInf);
|
UnityPrint(UnityStrNegInf);
|
||||||
UnityPrint(UnityStrWas);
|
UnityPrint(UnityStrWas);
|
||||||
|
#ifdef UNITY_FLOAT_VERBOSE
|
||||||
UnityPrintFloat(actual);
|
UnityPrintFloat(actual);
|
||||||
#else
|
#else
|
||||||
UnityPrint(UnityStrDelta);
|
if (should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
|
UnityPrint(UnityStrNegInf);
|
||||||
#endif
|
#endif
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
@ -666,21 +679,30 @@ void UnityAssertFloatIsNegInf(const _UF actual,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertFloatIsNaN(const _UF actual,
|
void UnityAssertFloatIsNaN(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
UNITY_SKIP_EXECUTION;
|
UNITY_SKIP_EXECUTION;
|
||||||
|
|
||||||
if (actual == actual)
|
//NaN is the only floating point value that does NOT
|
||||||
|
//equal itself. Therefore if Actual == Actual, then it
|
||||||
|
//is NOT NaN.
|
||||||
|
_U_SINT is_nan = (actual == actual) ? 0 : 1;
|
||||||
|
if (is_nan != should_be)
|
||||||
{
|
{
|
||||||
UnityTestResultsFailBegin(lineNumber);
|
UnityTestResultsFailBegin(lineNumber);
|
||||||
#ifdef UNITY_FLOAT_VERBOSE
|
|
||||||
UnityPrint(UnityStrExpected);
|
UnityPrint(UnityStrExpected);
|
||||||
|
if (!should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
UnityPrint(UnityStrNaN);
|
UnityPrint(UnityStrNaN);
|
||||||
UnityPrint(UnityStrWas);
|
UnityPrint(UnityStrWas);
|
||||||
|
#ifdef UNITY_FLOAT_VERBOSE
|
||||||
UnityPrintFloat(actual);
|
UnityPrintFloat(actual);
|
||||||
#else
|
#else
|
||||||
UnityPrint(UnityStrDelta);
|
if (should_be)
|
||||||
|
UnityPrint(UnityStrNot);
|
||||||
|
UnityPrint(UnityStrNaN);
|
||||||
#endif
|
#endif
|
||||||
UnityAddMsgIfSpecified(msg);
|
UnityAddMsgIfSpecified(msg);
|
||||||
UNITY_FAIL_AND_BAIL;
|
UNITY_FAIL_AND_BAIL;
|
||||||
@ -786,6 +808,7 @@ void UnityAssertDoublesWithin(const _UD delta,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertDoubleIsInf(const _UD actual,
|
void UnityAssertDoubleIsInf(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
@ -810,6 +833,7 @@ void UnityAssertDoubleIsInf(const _UD actual,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertDoubleIsNegInf(const _UD actual,
|
void UnityAssertDoubleIsNegInf(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
@ -834,6 +858,7 @@ void UnityAssertDoubleIsNegInf(const _UD actual,
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void UnityAssertDoubleIsNaN(const _UD actual,
|
void UnityAssertDoubleIsNaN(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber)
|
const UNITY_LINE_TYPE lineNumber)
|
||||||
{
|
{
|
||||||
@ -1093,8 +1118,8 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
|
|||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
#ifdef UNITY_SUPPORT_WEAK
|
#ifdef UNITY_SUPPORT_WEAK
|
||||||
void setUp(void) { }
|
UNITY_WEAK void setUp(void) { }
|
||||||
void tearDown(void) { }
|
UNITY_WEAK void tearDown(void) { }
|
||||||
#else
|
#else
|
||||||
void setUp(void);
|
void setUp(void);
|
||||||
void tearDown(void);
|
void tearDown(void);
|
||||||
|
12
src/unity.h
12
src/unity.h
@ -174,6 +174,9 @@
|
|||||||
#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL)
|
#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, NULL)
|
||||||
#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL)
|
#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, NULL)
|
||||||
#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL)
|
#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, __LINE__, NULL)
|
||||||
|
|
||||||
//Double (If Enabled)
|
//Double (If Enabled)
|
||||||
#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL)
|
#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||||
@ -182,6 +185,9 @@
|
|||||||
#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL)
|
#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, NULL)
|
||||||
#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL)
|
#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, NULL)
|
||||||
#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL)
|
#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, NULL)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, NULL)
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// Test Asserts (with additional messages)
|
// Test Asserts (with additional messages)
|
||||||
@ -260,6 +266,9 @@
|
|||||||
#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message)
|
#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, __LINE__, message)
|
||||||
#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message)
|
#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, __LINE__, message)
|
||||||
#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message)
|
#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_FLOAT_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, __LINE__, message)
|
||||||
|
|
||||||
//Double (If Enabled)
|
//Double (If Enabled)
|
||||||
#define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message)
|
#define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, __LINE__, message)
|
||||||
@ -268,4 +277,7 @@
|
|||||||
#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message)
|
#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, __LINE__, message)
|
||||||
#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message)
|
#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, __LINE__, message)
|
||||||
#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message)
|
#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, __LINE__, message)
|
||||||
|
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, __LINE__, message)
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,7 +274,7 @@ extern int UNITY_OUTPUT_CHAR(int);
|
|||||||
|
|
||||||
#ifndef UNITY_WEAK
|
#ifndef UNITY_WEAK
|
||||||
#ifdef UNITY_SUPPORT_WEAK
|
#ifdef UNITY_SUPPORT_WEAK
|
||||||
#define UNITY_WEAK __attribute__((weak))
|
#define UNITY_WEAK UNITY_SUPPORT_WEAK
|
||||||
#else
|
#else
|
||||||
#define UNITY_WEAK
|
#define UNITY_WEAK
|
||||||
#endif
|
#endif
|
||||||
@ -438,14 +438,17 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
|
|||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertFloatIsInf(const _UF actual,
|
void UnityAssertFloatIsInf(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertFloatIsNegInf(const _UF actual,
|
void UnityAssertFloatIsNegInf(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertFloatIsNaN(const _UF actual,
|
void UnityAssertFloatIsNaN(const _UF actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
#endif
|
#endif
|
||||||
@ -464,14 +467,17 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
|
|||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertDoubleIsInf(const _UD actual,
|
void UnityAssertDoubleIsInf(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertDoubleIsNegInf(const _UD actual,
|
void UnityAssertDoubleIsNegInf(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
|
|
||||||
void UnityAssertDoubleIsNaN(const _UD actual,
|
void UnityAssertDoubleIsNaN(const _UD actual,
|
||||||
|
const _U_SINT should_be,
|
||||||
const char* msg,
|
const char* msg,
|
||||||
const UNITY_LINE_TYPE lineNumber);
|
const UNITY_LINE_TYPE lineNumber);
|
||||||
#endif
|
#endif
|
||||||
@ -550,9 +556,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
|
|||||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
|
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UnityAssertFloatIsInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UnityAssertFloatIsNegInf((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UnityAssertFloatIsNaN((_UF)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UNITY_EXCLUDE_DOUBLE
|
#ifdef UNITY_EXCLUDE_DOUBLE
|
||||||
@ -566,9 +575,12 @@ void UnityAssertDoubleIsNaN(const _UD actual,
|
|||||||
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UD)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message)
|
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UD)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, (UNITY_LINE_TYPE)line, message)
|
||||||
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((_UD*)(expected), (_UD*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), (message), (UNITY_LINE_TYPE)line)
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 1, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UnityAssertDoubleIsInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UnityAssertDoubleIsNegInf((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
|
#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UnityAssertDoubleIsNaN((_UD)(actual), 0, (message), (UNITY_LINE_TYPE)line)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,12 +4,6 @@
|
|||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
ruby_version = RUBY_VERSION.split('.')
|
|
||||||
if (ruby_version[1].to_i == 9) and (ruby_version[2].to_i > 1)
|
|
||||||
require 'rubygems'
|
|
||||||
gem 'test-unit'
|
|
||||||
end
|
|
||||||
require 'test/unit'
|
|
||||||
require './auto/generate_test_runner.rb'
|
require './auto/generate_test_runner.rb'
|
||||||
|
|
||||||
TEST_FILE = 'test/testdata/testsample.c'
|
TEST_FILE = 'test/testdata/testsample.c'
|
||||||
@ -17,20 +11,20 @@ TEST_MOCK = 'test/testdata/mocksample.c'
|
|||||||
OUT_FILE = 'build/testsample_'
|
OUT_FILE = 'build/testsample_'
|
||||||
EXP_FILE = 'test/expectdata/testsample_'
|
EXP_FILE = 'test/expectdata/testsample_'
|
||||||
|
|
||||||
class TestGenerateTestRunner < Test::Unit::TestCase
|
$generate_test_runner_failures = 0
|
||||||
def setup
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
end
|
|
||||||
|
|
||||||
def verify_output_equal(subtest)
|
def verify_output_equal(subtest)
|
||||||
expected = File.read(EXP_FILE + subtest + '.c').gsub(/\r\n/,"\n")
|
expected = File.read(EXP_FILE + subtest + '.c').gsub(/\r\n/,"\n")
|
||||||
actual = File.read(OUT_FILE + subtest + '.c').gsub(/\r\n/,"\n")
|
actual = File.read(OUT_FILE + subtest + '.c').gsub(/\r\n/,"\n")
|
||||||
assert_equal(expected, actual, "Generated File Sub-Test '#{subtest}' Failed")
|
if (expected != actual)
|
||||||
|
report(" #{subtest}:FAIL")
|
||||||
|
$generate_test_runner_failures += 1
|
||||||
|
else
|
||||||
|
report(" #{subtest}:PASS")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ShouldGenerateARunnerByCreatingRunnerWithOptions
|
should "GenerateARunnerByCreatingRunnerWithOptions" do
|
||||||
sets = { 'def' => nil,
|
sets = { 'def' => nil,
|
||||||
'new1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
|
'new1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
|
||||||
'new2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
|
'new2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
|
||||||
@ -44,7 +38,7 @@ class TestGenerateTestRunner < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ShouldGenerateARunnerByRunningRunnerWithOptions
|
should "GenerateARunnerByRunningRunnerWithOptions" do
|
||||||
sets = { 'run1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
|
sets = { 'run1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true },
|
||||||
'run2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
|
'run2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" }
|
||||||
}
|
}
|
||||||
@ -57,7 +51,7 @@ class TestGenerateTestRunner < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ShouldGenerateARunnerByPullingYamlOptions
|
should "GenerateARunnerByPullingYamlOptions" do
|
||||||
subtest = 'yaml'
|
subtest = 'yaml'
|
||||||
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
|
cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
|
||||||
`#{cmdstr}`
|
`#{cmdstr}`
|
||||||
@ -68,7 +62,7 @@ class TestGenerateTestRunner < Test::Unit::TestCase
|
|||||||
verify_output_equal('mock_' + subtest)
|
verify_output_equal('mock_' + subtest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ShouldGenerateARunnerByPullingCommandlineOptions
|
should "GenerateARunnerByPullingCommandlineOptions" do
|
||||||
subtest = 'cmd'
|
subtest = 'cmd'
|
||||||
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
|
cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\""
|
||||||
`#{cmdstr}`
|
`#{cmdstr}`
|
||||||
@ -79,7 +73,7 @@ class TestGenerateTestRunner < Test::Unit::TestCase
|
|||||||
verify_output_equal('mock_' + subtest)
|
verify_output_equal('mock_' + subtest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ShouldGenerateARunnerThatUsesParameterizedTests
|
should "GenerateARunnerThatUsesParameterizedTests" do
|
||||||
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
|
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,4 +85,4 @@ class TestGenerateTestRunner < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
raise "There were #{$generate_test_runner_failures.to_s} failures while testing generate_test_runner.rb" if ($generate_test_runner_failures > 0)
|
||||||
|
@ -9,7 +9,10 @@
|
|||||||
|
|
||||||
// Dividing by these constants produces +/- infinity.
|
// Dividing by these constants produces +/- infinity.
|
||||||
// The rationale is given in UnityAssertFloatIsInf's body.
|
// The rationale is given in UnityAssertFloatIsInf's body.
|
||||||
|
#ifndef UNITY_EXCLUDE_FLOAT
|
||||||
static const _UF f_zero = 0.0f;
|
static const _UF f_zero = 0.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_DOUBLE
|
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||||
static const _UD d_zero = 0.0;
|
static const _UD d_zero = 0.0;
|
||||||
#endif
|
#endif
|
||||||
@ -2332,17 +2335,47 @@ void testFloatsNotEqualPlusMinusInf(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFloatIsInf(void)
|
void testFloatIsPosInf1(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero);
|
TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFloatIsPosInf2(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f / f_zero);
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFloatIsNegInf1(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero);
|
TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFloatIsNotInf(void)
|
void testFloatIsNegInf2(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(-3.0f / f_zero);
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFloatIsNotPosInf1(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
@ -2353,6 +2386,15 @@ void testFloatIsNotInf(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testFloatIsNotPosInf2(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void testFloatIsNotNegInf(void)
|
void testFloatIsNotNegInf(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
@ -2364,7 +2406,7 @@ void testFloatIsNotNegInf(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFloatIsNan(void)
|
void testFloatIsNan1(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
@ -2373,7 +2415,18 @@ void testFloatIsNan(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFloatIsNotNan(void)
|
void testFloatIsNan2(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
EXPECT_ABORT_BEGIN
|
||||||
|
TEST_ASSERT_FLOAT_IS_NOT_NAN(0.0f / f_zero);
|
||||||
|
VERIFY_FAILS_END
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void testFloatIsNotNan1(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
@ -2384,6 +2437,15 @@ void testFloatIsNotNan(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testFloatIsNotNan2(void)
|
||||||
|
{
|
||||||
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
TEST_IGNORE();
|
||||||
|
#else
|
||||||
|
TEST_ASSERT_FLOAT_IS_NOT_NAN(234.9f);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void testFloatInfIsNotNan(void)
|
void testFloatInfIsNotNan(void)
|
||||||
{
|
{
|
||||||
#ifdef UNITY_EXCLUDE_FLOAT
|
#ifdef UNITY_EXCLUDE_FLOAT
|
||||||
|
Reference in New Issue
Block a user