This repository has been archived on 2025-02-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Pivot/test/test_assert.h
Persson-dev f5a282c455
All checks were successful
Linux arm64 / Build (push) Successful in 6m40s
allow tests in release mode
2024-05-04 12:42:26 +02:00

44 lines
1.3 KiB
C++

#pragma once
/**
* \file Test.h
* \brief File containing unit testing utilities
*/
#include <cstdlib>
#include <iostream>
/**
* \def TEST_SUCCESSFUL
* \brief Used in tests to indicate that a test was successful
*/
#define TEST_SUCCESSFUL 0
/**
* \def TEST_FAILED
* \brief Used in tests to indicate that a test failed
*/
#define TEST_FAILED 1
#ifndef __FUNCTION_NAME__
#ifdef _WIN32
#define __FUNCTION_NAME__ __FUNCTION__
#else
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
#endif
#endif
/**
* \def test_assert
* \param ... The expression to evaluate
* \brief Evaluates the expression and exits the program if not valid.
* \note It works like a basic assert() but also in release mode
*/
#define test_assert(...) \
if (!static_cast<bool>(__VA_ARGS__)) { \
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
std::exit(TEST_FAILED); \
}