mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-21 09:27:53 +08:00
We're going to use the C99 isinf() and isnan() macros wherever possible now. If your compiler doesn't support this, define UNITY_EXCLUDE_MATH_H and it will go back to the old method
This commit is contained in:
Binary file not shown.
Binary file not shown.
33
src/unity.c
33
src/unity.c
@ -44,13 +44,10 @@ const char UnityStrResultsTests[] = " Tests ";
|
||||
const char UnityStrResultsFailures[] = " Failures ";
|
||||
const char UnityStrResultsIgnored[] = " Ignored ";
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
#ifdef UNITY_FLOAT_NEEDS_ZERO
|
||||
// Dividing by these constants produces +/- infinity.
|
||||
// The rationale is given in UnityAssertFloatIsInf's body.
|
||||
static const _UF f_zero = 0.0f;
|
||||
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||
static const _UD d_zero = 0.0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// compiler-generic print formatting masks
|
||||
@ -738,29 +735,30 @@ void UnityAssertFloatSpecial(const _UF actual,
|
||||
//We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
|
||||
case UNITY_FLOAT_IS_INF:
|
||||
case UNITY_FLOAT_IS_NOT_INF:
|
||||
is_trait = ((1.0f / f_zero) == actual) ? 1 : 0;
|
||||
is_trait = isinf(actual) & ispos(actual);
|
||||
break;
|
||||
case UNITY_FLOAT_IS_NEG_INF:
|
||||
case UNITY_FLOAT_IS_NOT_NEG_INF:
|
||||
is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0;
|
||||
is_trait = isinf(actual) & isneg(actual);
|
||||
break;
|
||||
|
||||
//NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
|
||||
case UNITY_FLOAT_IS_NAN:
|
||||
case UNITY_FLOAT_IS_NOT_NAN:
|
||||
is_trait = (actual == actual) ? 0 : 1;
|
||||
is_trait = isnan(actual);
|
||||
break;
|
||||
|
||||
//A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
|
||||
case UNITY_FLOAT_IS_DET:
|
||||
case UNITY_FLOAT_IS_NOT_DET:
|
||||
if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) )
|
||||
if (isinf(actual) | isnan(actual))
|
||||
is_trait = 0;
|
||||
else
|
||||
is_trait = 1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_trait != should_be_trait)
|
||||
@ -894,35 +892,36 @@ void UnityAssertDoubleSpecial(const _UD actual,
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
switch(style)
|
||||
switch(style)
|
||||
{
|
||||
//To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
|
||||
//We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
|
||||
case UNITY_FLOAT_IS_INF:
|
||||
case UNITY_FLOAT_IS_NOT_INF:
|
||||
is_trait = ((1.0 / d_zero) == actual) ? 1 : 0;
|
||||
is_trait = isinf(actual) & ispos(actual);
|
||||
break;
|
||||
case UNITY_FLOAT_IS_NEG_INF:
|
||||
case UNITY_FLOAT_IS_NOT_NEG_INF:
|
||||
is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0;
|
||||
is_trait = isinf(actual) & isneg(actual);
|
||||
break;
|
||||
|
||||
//NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
|
||||
case UNITY_FLOAT_IS_NAN:
|
||||
case UNITY_FLOAT_IS_NOT_NAN:
|
||||
is_trait = (actual == actual) ? 0 : 1;
|
||||
is_trait = isnan(actual);
|
||||
break;
|
||||
|
||||
//A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
|
||||
case UNITY_FLOAT_IS_DET:
|
||||
case UNITY_FLOAT_IS_NOT_DET:
|
||||
if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) )
|
||||
if (isinf(actual) | isnan(actual))
|
||||
is_trait = 0;
|
||||
else
|
||||
is_trait = 1;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_trait != should_be_trait)
|
||||
|
@ -36,6 +36,11 @@
|
||||
//apparently this is not a constant expression: (sizeof(unsigned int *) * 256 - 1) so we have to just let this fall through
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXCLUDE_MATH_H
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Guess Widths If Not Specified
|
||||
//-------------------------------------------------------
|
||||
@ -214,6 +219,23 @@ typedef _US64 _U_SINT;
|
||||
#endif
|
||||
typedef UNITY_FLOAT_TYPE _UF;
|
||||
|
||||
#ifndef isinf
|
||||
#define isinf(n) (((1.0f / f_zero) == n) ? 1 : 0) || (((-1.0f / f_zero) == n) ? 1 : 0)
|
||||
#define UNITY_FLOAT_NEEDS_ZERO
|
||||
#endif
|
||||
|
||||
#ifndef isnan
|
||||
#define isnan(n) ((n != n) ? 1 : 0)
|
||||
#endif
|
||||
|
||||
#ifndef isneg
|
||||
#define isneg(n) ((n < 0.0f) ? 1 : 0)
|
||||
#endif
|
||||
|
||||
#ifndef ispos
|
||||
#define ispos(n) ((n > 0.0f) ? 1 : 0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
83
test/targets/clang_file.yml
Normal file
83
test/targets/clang_file.yml
Normal file
@ -0,0 +1,83 @@
|
||||
---
|
||||
compiler:
|
||||
path: clang
|
||||
source_path: '../src/'
|
||||
unit_tests_path: &unit_tests_path 'tests/'
|
||||
build_path: &build_path 'build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-Wall'
|
||||
- '-Wextra'
|
||||
- '-Werror'
|
||||
- '-Wcast-qual'
|
||||
- '-Wconversion'
|
||||
- '-Wdisabled-optimization'
|
||||
- '-Wformat=2'
|
||||
- '-Winit-self'
|
||||
- '-Winline'
|
||||
- '-Winvalid-pch'
|
||||
- '-Wmissing-declarations'
|
||||
- '-Wmissing-include-dirs'
|
||||
- '-Wmissing-prototypes'
|
||||
- '-Wnonnull'
|
||||
- '-Wpacked'
|
||||
- '-Wpointer-arith'
|
||||
- '-Wredundant-decls'
|
||||
- '-Wswitch-default'
|
||||
- '-Wstrict-aliasing'
|
||||
- '-Wstrict-overflow=5'
|
||||
- '-Wuninitialized'
|
||||
- '-Wunused'
|
||||
- '-Wunreachable-code'
|
||||
- '-Wreturn-type'
|
||||
- '-Wshadow'
|
||||
- '-Wundef'
|
||||
- '-Wwrite-strings'
|
||||
- '-Wno-missing-declarations'
|
||||
- '-Wno-missing-prototypes'
|
||||
- '-Wno-nested-externs'
|
||||
- '-Wno-redundant-decls'
|
||||
- '-Wno-unused-parameter'
|
||||
- '-Wno-variadic-macros'
|
||||
- '-Wbad-function-cast'
|
||||
- '-fms-extensions'
|
||||
- '-fno-omit-frame-pointer'
|
||||
- '-ffloat-store'
|
||||
- '-fno-common'
|
||||
- '-fstrict-aliasing'
|
||||
- '-std=gnu99'
|
||||
- '-pedantic'
|
||||
- '-O0'
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
- UNITY_INCLUDE_DOUBLE
|
||||
- UNITY_SUPPORT_64
|
||||
- UNITY_OUTPUT_RESULTS_FILE
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.o'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: gcc
|
||||
options:
|
||||
- -lm
|
||||
- '-m64'
|
||||
includes:
|
||||
prefix: '-I'
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.exe'
|
||||
destination: *build_path
|
||||
colour: true
|
||||
:unity:
|
||||
:plugins: []
|
46
test/targets/gcc_manual_math.yml
Normal file
46
test/targets/gcc_manual_math.yml
Normal file
@ -0,0 +1,46 @@
|
||||
compiler:
|
||||
path: gcc
|
||||
source_path: '../src/'
|
||||
unit_tests_path: &unit_tests_path 'tests/'
|
||||
build_path: &build_path 'build/'
|
||||
options:
|
||||
- '-c'
|
||||
- '-m64'
|
||||
- '-Wall'
|
||||
- '-Wno-address'
|
||||
- '-std=c99'
|
||||
- '-pedantic'
|
||||
includes:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
items:
|
||||
- UNITY_EXCLUDE_MATH_H
|
||||
- UNITY_INCLUDE_DOUBLE
|
||||
- UNITY_SUPPORT_TEST_CASES
|
||||
- UNITY_SUPPORT_64
|
||||
object_files:
|
||||
prefix: '-o'
|
||||
extension: '.o'
|
||||
destination: *build_path
|
||||
linker:
|
||||
path: gcc
|
||||
options:
|
||||
- -lm
|
||||
- '-m64'
|
||||
includes:
|
||||
prefix: '-I'
|
||||
object_files:
|
||||
path: *build_path
|
||||
extension: '.o'
|
||||
bin_files:
|
||||
prefix: '-o'
|
||||
extension: '.exe'
|
||||
destination: *build_path
|
||||
colour: true
|
||||
:unity:
|
||||
:plugins: []
|
Reference in New Issue
Block a user