Skip to content

Instantly share code, notes, and snippets.

@cheng-alvin
Last active December 12, 2023 09:34
Show Gist options
  • Save cheng-alvin/d4ed6222d8615c85998b0452a96c4df2 to your computer and use it in GitHub Desktop.
Save cheng-alvin/d4ed6222d8615c85998b0452a96c4df2 to your computer and use it in GitHub Desktop.
This is the labrador testing framework built for the Jas assembler project. The testing framwork allows code to be tested and have the verbose overloading be done by the preprocessor.
// Headers can be obtained at: https://github.com/cheng-alvin/jas.
// Licensed under the MIT license, free of any charge, NO warranty.
// Please see: https://github.com/cheng-alvin/jas/blob/main/LICENSE.
#include "color.h"
#include "null.h"
#include <stdio.h>
/**
* @author cheng-alvin
*
* This is the labrador testing framework built for the Jas
* assembler project. The testing framwork allows code to be tested
* and have the verbose overloading be done by the preprocessor.
*
* The testing framework is used to test components of the Jas
* assembler project and can be ported to other projects as well,
* noting the perquisites needed to do so.
*
* @note null.h and color.h are required for the testing framework,
* they can all be found inside the include directory.
*/
#define TEST(name) \
int main(void)
#define ASSERT(expr) \
if (!(expr)) { \
printf(RED BOLD "failure\n\n" RESET BOLD "REASON: `" #expr "` did not match with expected result.\n" RESET); \
exit(1); \
}
#define SHOULD_EQUAL(a, b) ASSERT(a == b)
#define SHOULD_NOT_EQUAL(a, b) ASSERT(a != b)
#define SHOULD_BE_TRUE(a) ASSERT(a)
#define SHOULD_BE_FALSE(a) ASSERT(!a)
#define SHOULD_BE_NULL(a) ASSERT(a == NULL)
#define PASS exit(0);
// Headers can be obtained at: https://github.com/cheng-alvin/jas.
// Licensed under the MIT license, free of any charge, NO warranty.
// Please see: https://github.com/cheng-alvin/jas/blob/main/LICENSE.
#include <stdio.h>
#include <stdlib.h>
#include "color.h"
#include "null.h"
TEST(foo) {
int bar = baz(); // Calls function to be tested
SHOULD_EQUAL(bar, 0) // Checks if it equates
PASS // Passes the test by returning 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment