Skip to content

Minimalistic assertion library for unit testing raylib.

License

Notifications You must be signed in to change notification settings

RobLoach/raylib-assert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

raylib-assert

Minimalistic assertion library for raylib.

Example

#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

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:

// #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...

#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 is in use.

#define RAYLIB_ASSERT_NDEBUG

RAYLIB_ASSERT_TRACELOG

Allows changing which TraceLog() function the assertion library uses to output messages.

#define RAYLIB_ASSERT_TRACELOG TraceLog

RAYLIB_ASSERT_TEXTFORMAT

Allows changing which TextFormat() function the assertion library uses to output messages.

#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 for further details.

About

Minimalistic assertion library for unit testing raylib.

Topics

Resources

License

Stars

Watchers

Forks