Compare commits
4 Commits
Release-1.
...
Release-1.
Author | SHA1 | Date | |
---|---|---|---|
e3b69e7aa9 | |||
50cd639923 | |||
fae8e82ba8 | |||
|
381a366846 |
@@ -1,6 +1,6 @@
|
||||
# 2024 Josh O'Leary @ Redacted Software
|
||||
|
||||
cmake_minimum_required(VERSION 3.18...3.25)
|
||||
cmake_minimum_required(VERSION 3.18...3.27)
|
||||
project(
|
||||
jtest
|
||||
VERSION 1.0
|
||||
@@ -32,7 +32,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-14.zip
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-16.zip
|
||||
)
|
||||
|
||||
|
||||
@@ -66,4 +66,4 @@ target_link_libraries(jtest PUBLIC Event jlog)
|
||||
add_executable(TestSuiteDemo main.cpp)
|
||||
|
||||
# link the new library target with the binary target
|
||||
target_link_libraries(TestSuiteDemo PUBLIC jtest)
|
||||
target_link_libraries(TestSuiteDemo PUBLIC jtest)
|
||||
|
@@ -14,73 +14,90 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace jtest
|
||||
{
|
||||
class check_fail {};
|
||||
class check_eq_fail : public check_fail {};
|
||||
class check_ne_fail : public check_fail {};
|
||||
namespace jtest {
|
||||
class check_fail {
|
||||
};
|
||||
|
||||
class check_eq_fail : public check_fail {
|
||||
};
|
||||
|
||||
class check_ne_fail : public check_fail {
|
||||
};
|
||||
|
||||
/// Raises an exception if the given condition is false.
|
||||
void check(bool condition)
|
||||
{
|
||||
void check(bool condition) {
|
||||
if (!condition)
|
||||
throw check_fail();
|
||||
}
|
||||
|
||||
/// Raises an exception if the given types do not evaluate as equal.
|
||||
template <typename T>
|
||||
void check_eq(T a, T b)
|
||||
{
|
||||
template<typename T>
|
||||
void check_eq(T a, T b) {
|
||||
if (a != b)
|
||||
throw check_eq_fail();
|
||||
}
|
||||
|
||||
/// Raises an exception if the given types do evaluate as equal.
|
||||
template <typename T>
|
||||
void check_ne(T a, T b)
|
||||
{
|
||||
template<typename T>
|
||||
void check_ne(T a, T b) {
|
||||
if (a == b)
|
||||
throw check_ne_fail();
|
||||
}
|
||||
|
||||
/// Raises an exception of the given float values are not equal (up to the given epsilon).
|
||||
void check_float_eq(float a, float b, float epsilon = 1e-3f)
|
||||
{
|
||||
if ( ! (std::abs(a - b) <= epsilon))
|
||||
void check_float_eq(float a, float b, float epsilon = 1e-3f) {
|
||||
if (!(std::abs(a - b) <= epsilon))
|
||||
throw check_eq_fail();
|
||||
}
|
||||
|
||||
void check_float_ne(float a, float b, float epsilon = 1e-3f)
|
||||
{
|
||||
if ( (std::abs(a - b) <= epsilon))
|
||||
void check_float_ne(float a, float b, float epsilon = 1e-3f) {
|
||||
if ((std::abs(a - b) <= epsilon))
|
||||
throw check_ne_fail();
|
||||
}
|
||||
|
||||
void check_float_eq_exact(float a, float b)
|
||||
{
|
||||
void check_float_eq_exact(float a, float b) {
|
||||
if (a != b)
|
||||
throw check_eq_fail();
|
||||
}
|
||||
|
||||
|
||||
void check_string_eq(std::string a, std::string b)
|
||||
{
|
||||
void check_string_eq(std::string a, std::string b) {
|
||||
if (a != b)
|
||||
throw check_eq_fail();
|
||||
}
|
||||
|
||||
void check_string_ne(std::string a, std::string b)
|
||||
{
|
||||
void check_string_ne(std::string a, std::string b) {
|
||||
if (a == b)
|
||||
throw check_ne_fail();
|
||||
}
|
||||
void check_throws(std::function<void()> callback);
|
||||
void check_nothrows(std::function<void()> callback);
|
||||
|
||||
void check_throws(std::function<void()> callback)
|
||||
{
|
||||
try {
|
||||
callback();
|
||||
throw check_fail();
|
||||
} catch(...)
|
||||
{
|
||||
// Do nothing, the callback threw as expected...
|
||||
}
|
||||
}
|
||||
void check_nothrows(std::function<void()> callback)
|
||||
{
|
||||
try {
|
||||
callback();
|
||||
} catch(...)
|
||||
{
|
||||
throw check_fail();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implement death check:
|
||||
// Spawn a new process, and execute the callback in that process.
|
||||
// This verifies that a piece of code would cause the process to terminate.
|
||||
void check_death(std::function<void()> callback);
|
||||
void check_death(std::function<void()> callback)
|
||||
{
|
||||
check_throws(callback);
|
||||
}
|
||||
|
||||
|
||||
/// Raises an exception, which causes the test to fail.
|
||||
|
Reference in New Issue
Block a user