Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RobLoach/raylib-assert
Minimalistic assertion library for unit testing raylib.
https://github.com/RobLoach/raylib-assert
raylib
Last synced: 3 months ago
JSON representation
Minimalistic assertion library for unit testing raylib.
- Host: GitHub
- URL: https://github.com/RobLoach/raylib-assert
- Owner: RobLoach
- License: zlib
- Created: 2022-01-11T02:33:36.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-10T19:55:03.000Z (10 months ago)
- Last Synced: 2024-04-20T06:31:33.585Z (7 months ago)
- Topics: raylib
- Language: C
- Homepage:
- Size: 154 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-raylib - raylib-assert
README
# raylib-assert
Minimalistic [assertion](https://en.wikipedia.org/wiki/Assertion_(software_development)) library for [raylib](https://www.raylib.com).
## Example
``` c
#include "raylib.h"
#include "raylib-assert.h"int main(void)
{
Assert(10 == 10);
// => Reports nothing, since the assert passes.Assert(IsWindowReady());
// => ASSERT: IsWindowReady() (main.c:22)Assert(IsWindowReady(), "Window has not been created");
// => ASSERT: Window has not been created (main.c:25)int x = 10;
int y = 20;
AssertEqual(x, y, "%i and %i aren't the same!", x, y);
// => ASSERT: 10 and 20 aren't the same! (main.c:30)AssertFail("DESTROY ALL HUMANS!");
// => ASSERT: DESTROY ALL HUMANS! (main.c: 35)Image image = LoadImage("NotFound.png");
AssertImage(image);
// => ASSERT: Image not loaded (image) (main.c: 40)
}
```## API
``` c
Assert(condition, [message], [params]); // Asserts whether the given condition is true, with the given message parameters.
AssertNot(condition, [message], [params]); // Asserts whether the given condition is false.
AssertEqual(expected, actual, [message], [params]); // Asserts that the expected parameter is the same as the actual parameter.
AssertNotEqual(unexpected, actual, [message], [params]); // Asserts that the expected parameter is not the same as the actual parameter.
AssertFail([message], [params]); // Sets a failed assertion, with the given message.
AssertImage(image, [message], [params]); // Asserts whether the given image has been loaded properly.
AssertTexture(texture, [message], [params]); // Asserts whether the given texture has been loaded properly.
AssertColorSame(color1, color2, [message], [params]); // Asserts whether the given colors are the same.
AssertImageSame(image1, image2, [message], [params]); // Asserts whether the given images are the same.
AssertVector2Same(vector1, vector2, [message], [params]); // Asserts whether the given vector2s are the same.
```## Options
You are able to change the behavior of assertions by making some defines prior to including `raylib-assert.h`:
``` c
// #define RAYLIB_ASSERT_LOG LOG_FATAL
// #define RAYLIB_ASSERT_NDEBUG
// #define RAYLIB_ASSERT_TRACELOG TraceLog
// #define RAYLIB_ASSERT_TEXTFORMAT TextFormat
#include "raylib-assert.h"
```### `RAYLIB_ASSERT_LOG`
The trace log level to use when reporting to TraceLog() on failed assertions. By default, will report to `LOG_FATAL`. This will result in a forceful exit of the program, and fail the application. To have failed assertions simply report a warning with `LOG_WARNING` instead, you can use...
``` c
#define RAYLIB_ASSERT_LOG LOG_WARNING
```### `RAYLIB_ASSERT_NDEBUG`
Assertions can be completely ignored by defining `RAYLIB_ASSERT_NDEBUG` prior to including the file. This is enabled automatically if [`NDEBUG`](https://www.oreilly.com/library/view/c-in-a/059600298X/re171.html) is in use.
``` c
#define RAYLIB_ASSERT_NDEBUG
```### `RAYLIB_ASSERT_TRACELOG`
Allows changing which `TraceLog()` function the assertion library uses to output messages.
``` c
#define RAYLIB_ASSERT_TRACELOG TraceLog
```### `RAYLIB_ASSERT_TEXTFORMAT`
Allows changing which `TextFormat()` function the assertion library uses to output messages.
``` c
#define RAYLIB_ASSERT_TEXTFORMAT TextFormat
```## License
raylib-assert is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.