Skip to content

Commit

Permalink
Update change log and known issues.
Browse files Browse the repository at this point in the history
Fix bug with infinity and NaN handling.
  • Loading branch information
mvandervoord committed Nov 13, 2023
1 parent 3f7564e commit a1b1600
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ If you'd like to leave the hard work to us, you might be interested in Ceedling,

If you're new to Unity, we encourage you to tour the [getting started guide][].

You can also find the [change log][] and [known issues][] in our documentation.

## Getting Started

The [docs][] folder contains a [getting started guide][] and much more tips about using Unity.
Expand Down Expand Up @@ -226,5 +228,7 @@ This is useful for specifying more information about the problem.

[CI]: https://github.com/ThrowTheSwitch/Unity/workflows/CI/badge.svg
[getting started guide]: docs/UnityGettingStartedGuide.md
[change log]: docs/UnityChangeLog.md
[known issues]: docs/UnityKnownIssues.md
[docs]: docs/
[UnityAssertionsReference.md]: docs/UnityAssertionsReference.md
93 changes: 93 additions & 0 deletions docs/UnityChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Unity Test - Change Log

## A Note

This document captures significant features and fixes to the Unity project core source files
and scripts. More detail can be found in the history on Github.

This project is now tracking changes in more detail. Previous releases get less detailed as
we move back in histroy.

Prior to 2012, the project was hosted on SourceForge.net
Prior to 2008, the project was an internal project and not released to the public.

## Log

### Unity 2.6.0 ()

New Features:

- Fill out missing variations of arrays, within, etc.
- Add `TEST_PRINTF()`
- Add `TEST_MATRIX()` and `TEST_RANGE()` options and documentation
- Add support for searching `TEST_SOURCE_FILE()` for determining test dependencies
- Add Unity BDD plugin
- Add `UNITY_INCLUDE_EXEC_TIME` option to report test times
- Allow user to override test abort underlying mechanism

Significant Bugfixes:

- More portable validation of NaN and Infinity. Added `UNITY_IS_NAN` and `UNITY_IS_INF` options
- Add `UNITY_PROGMEM` configuration option
- Fix overflow detection of hex values when using arrays
- Fix scripts broken by Ruby standard changes

Other:

- Avoid pointer comparison when one is null to avoid compiler warnings
- Significant improvements to documentation
- Updates to match latest Ruby style specification
- Meson, CMake, PlatformIO builds

### Unity 2.5.2 (January 2021)

- improvements to RUN_TEST macro and generated RUN_TEST
- Fix `UNITY_TEST_ASSERT_BIT(S)_HIGH`
- Cleaner handling of details tracking by CMock

### Unity 2.5.1 (May 2020)

Mostly a bugfix and stability release.
Bonus Features:

- Optional TEST_PRINTF macro
- Improve self-testing procedures.

### Unity 2.5.0 (October 2019)

It's been a LONG time since the last release of Unity. Finally, here it is!
There are too many updates to list here, so some highlights:

- more standards compliant (without giving up on supporting ALL compilers, no matter how quirky)
- many more specialized assertions for better test feedback
- more examples for integrating into your world
- many many bugfixes and tweaks

### Unity 2.4.3 (November 2017)

- Allow suiteSetUp() and suiteTearDown() to be povided as normal C functions
- Fix & Expand Greater Than / Less Than assertions for integers
- Built-in option to colorize test results
- Documentation updates

### Unity 2.4.2 (September 2017)

- Fixed bug in UNTY_TEST_ASSERT_EACH_EQUAL_*
- Added TEST_ASSERT_GREATER_THAN and TEST_ASSERT_LESS_THAN
- Updated Module Generator to stop changing names when no style given
- Cleanup to custom float printing for accuracy
- Cleanup incorrect line numbers are partial name matching
- Reduce warnings from using popular function names as variable names

### Unity 2.4.1 (April 2017)

- test runner generator can inject defines as well as headers
- added a built-in floating point print routine instead of relying on printf
- updated to new coding and naming standard
- updated documentation to be markdown instead of pdf
- fixed many many little bugs, most of which were supplied by the community (you people are awesome!)
- coding standard actually enforced in CI

### Unity 2.4.0 (October, 2016)

- port from SourceForge and numerous bugfixes
11 changes: 11 additions & 0 deletions docs/UnityConfigurationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ _Example:_
#define UNITY_FLOAT_PRECISION 0.001f
```
#### `UNITY_IS_NAN` and `UNITY_IS_INF`
If your toolchain defines `isnan` and `isinf` in `math.h` as macros, nothing needs to be done. If your toolchain doesn't define these, Unity
will create these macros itself. You may override either or both of these defines to specify how you want to evaluate if a number is NaN or Infinity.

_Example:_

```C
#define UNITY_IS_NAN(n) ((n != n) ? 1 : 0)
```
### Miscellaneous
#### `UNITY_EXCLUDE_STDDEF_H`
Expand Down
13 changes: 13 additions & 0 deletions docs/UnityKnownIssues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Unity Test - Known Issues

## A Note

This project will do its best to keep track of significant bugs that might effect your usage of this
project and its supporting scripts. A more detailed and up-to-date list for cutting edge Unity can
be found on our Github repository.

## Issues

- No built-in validation of no-return functions
- Incomplete support for Printf-style formatting
- Incomplete support for VarArgs
34 changes: 17 additions & 17 deletions src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
{
UnityPrint("0");
}
else if (isnan(number))
else if (UNITY_IS_NAN(number))
{
UnityPrint("nan");
}
else if (isinf(number))
else if (UNITY_IS_INF(number))
{
UnityPrint("inf");
}
Expand Down Expand Up @@ -895,15 +895,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
#ifndef UNITY_EXCLUDE_FLOAT
/* Wrap this define in a function with variable types as float or double */
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
if (UNITY_IS_INF(expected) && UNITY_IS_INF(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
if (UNITY_NAN_CHECK) return 1; \
(diff) = (actual) - (expected); \
if ((diff) < 0) (diff) = -(diff); \
if ((delta) < 0) (delta) = -(delta); \
return !(isnan(diff) || isinf(diff) || ((diff) > (delta)))
return !(UNITY_IS_NAN(diff) || UNITY_IS_INF(diff) || ((diff) > (delta)))
/* This first part of this condition will catch any NaN or Infinite values */
#ifndef UNITY_NAN_NOT_EQUAL_NAN
#define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
#define UNITY_NAN_CHECK UNITY_IS_NAN(expected) && UNITY_IS_NAN(actual)
#else
#define UNITY_NAN_CHECK 0
#endif
Expand Down Expand Up @@ -954,12 +954,12 @@ void UnityAssertWithinFloatArray(const UNITY_FLOAT delta,
#endif
}

if (isinf(in_delta))
if (UNITY_IS_INF(in_delta))
{
return; /* Arrays will be force equal with infinite delta */
}

if (isnan(in_delta))
if (UNITY_IS_NAN(in_delta))
{
/* Delta must be correct number */
UnityPrintPointlessAndBail();
Expand Down Expand Up @@ -1098,21 +1098,21 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) && (actual > 0);
is_trait = UNITY_IS_INF(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) && (actual < 0);
is_trait = UNITY_IS_INF(actual) && (actual < 0);
break;

case UNITY_FLOAT_IS_NAN:
case UNITY_FLOAT_IS_NOT_NAN:
is_trait = isnan(actual) ? 1 : 0;
is_trait = UNITY_IS_NAN(actual) ? 1 : 0;
break;

case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
is_trait = !isinf(actual) && !isnan(actual);
is_trait = !UNITY_IS_INF(actual) && !UNITY_IS_NAN(actual);
break;

case UNITY_FLOAT_INVALID_TRAIT: /* Supress warning */
Expand Down Expand Up @@ -1182,12 +1182,12 @@ void UnityAssertWithinDoubleArray(const UNITY_DOUBLE delta,
#endif
}

if (isinf(in_delta))
if (UNITY_IS_INF(in_delta))
{
return; /* Arrays will be force equal with infinite delta */
}

if (isnan(in_delta))
if (UNITY_IS_NAN(in_delta))
{
/* Delta must be correct number */
UnityPrintPointlessAndBail();
Expand Down Expand Up @@ -1325,21 +1325,21 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) && (actual > 0);
is_trait = UNITY_IS_INF(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) && (actual < 0);
is_trait = UNITY_IS_INF(actual) && (actual < 0);
break;

case UNITY_FLOAT_IS_NAN:
case UNITY_FLOAT_IS_NOT_NAN:
is_trait = isnan(actual) ? 1 : 0;
is_trait = UNITY_IS_NAN(actual) ? 1 : 0;
break;

case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
is_trait = !isinf(actual) && !isnan(actual);
is_trait = !UNITY_IS_INF(actual) && !UNITY_IS_NAN(actual);
break;

case UNITY_FLOAT_INVALID_TRAIT: /* Supress warning */
Expand Down
23 changes: 16 additions & 7 deletions src/unity_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,25 @@
#endif
typedef UNITY_FLOAT_TYPE UNITY_FLOAT;

/* isinf & isnan macros should be provided by math.h */
#ifndef isinf
/* The value of Inf - Inf is NaN */
#define isinf(n) (isnan((n) - (n)) && !isnan(n))
#endif

/* isnan macro should be provided by math.h. Override if not macro */
#ifndef UNITY_IS_NAN
#ifndef isnan
/* NaN is the only floating point value that does NOT equal itself.
* Therefore if n != n, then it is NaN. */
#define isnan(n) ((n != n) ? 1 : 0)
#define UNITY_IS_NAN(n) ((n != n) ? 1 : 0)
#else
#define UNITY_IS_NAN(n) isnan(n)
#endif
#endif

/* isinf macro should be provided by math.h. Override if not macro */
#ifndef UNITY_IS_INF
#ifndef isinf
/* The value of Inf - Inf is NaN */
#define UNITY_IS_INF(n) (UNITY_IS_NAN((n) - (n)) && !UNITY_IS_NAN(n))
#else
#define UNITY_IS_INF(n) isinf(n)
#endif
#endif

#endif
Expand Down

0 comments on commit a1b1600

Please sign in to comment.