Compare commits
4 Commits
Release-1.
...
main
Author | SHA1 | Date | |
---|---|---|---|
1c39b8eda6 | |||
bae26cf80a | |||
76a384b892 | |||
e3b69e7aa9 |
@@ -24,18 +24,11 @@ include(cmake/CPM.cmake)
|
|||||||
file(GLOB_RECURSE jtest_HEADERS "include/jtest/*.h" "include/jtest/*.hpp")
|
file(GLOB_RECURSE jtest_HEADERS "include/jtest/*.h" "include/jtest/*.hpp")
|
||||||
file(GLOB_RECURSE jtest_SRC "src/jtest/*.c" "src/jtest/*.cpp")
|
file(GLOB_RECURSE jtest_SRC "src/jtest/*.c" "src/jtest/*.cpp")
|
||||||
|
|
||||||
# TODO: Fix Event needing to be included too, it should be an automatically-managed depencency of jlog!!!
|
|
||||||
CPMAddPackage(
|
|
||||||
NAME Event
|
|
||||||
URL https://git.redacted.cc/josh/Event/archive/Release-10.zip
|
|
||||||
)
|
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME jlog
|
NAME jlog
|
||||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-16.zip
|
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-19.zip
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
add_library(jtest SHARED ${jtest_SRC})
|
add_library(jtest SHARED ${jtest_SRC})
|
||||||
endif()
|
endif()
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Event.h>
|
#include <Event.h>
|
||||||
#include <EventConnection.h>
|
|
||||||
|
|
||||||
#include <jtest/Test.hpp>
|
#include <jtest/Test.hpp>
|
||||||
#include <jtest/UnitLogger.hpp>
|
#include <jtest/UnitLogger.hpp>
|
||||||
|
@@ -14,73 +14,90 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace jtest
|
namespace jtest {
|
||||||
{
|
class check_fail {
|
||||||
class check_fail {};
|
};
|
||||||
class check_eq_fail : public check_fail {};
|
|
||||||
class check_ne_fail : public 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.
|
/// Raises an exception if the given condition is false.
|
||||||
void check(bool condition)
|
void check(bool condition) {
|
||||||
{
|
|
||||||
if (!condition)
|
if (!condition)
|
||||||
throw check_fail();
|
throw check_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Raises an exception if the given types do not evaluate as equal.
|
/// Raises an exception if the given types do not evaluate as equal.
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void check_eq(T a, T b)
|
void check_eq(T a, T b) {
|
||||||
{
|
|
||||||
if (a != b)
|
if (a != b)
|
||||||
throw check_eq_fail();
|
throw check_eq_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Raises an exception if the given types do evaluate as equal.
|
/// Raises an exception if the given types do evaluate as equal.
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void check_ne(T a, T b)
|
void check_ne(T a, T b) {
|
||||||
{
|
|
||||||
if (a == b)
|
if (a == b)
|
||||||
throw check_ne_fail();
|
throw check_ne_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Raises an exception of the given float values are not equal (up to the given epsilon).
|
/// 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)
|
void check_float_eq(float a, float b, float epsilon = 1e-3f) {
|
||||||
{
|
if (!(std::abs(a - b) <= epsilon))
|
||||||
if ( ! (std::abs(a - b) <= epsilon))
|
|
||||||
throw check_eq_fail();
|
throw check_eq_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_float_ne(float a, float b, float epsilon = 1e-3f)
|
void check_float_ne(float a, float b, float epsilon = 1e-3f) {
|
||||||
{
|
if ((std::abs(a - b) <= epsilon))
|
||||||
if ( (std::abs(a - b) <= epsilon))
|
|
||||||
throw check_ne_fail();
|
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)
|
if (a != b)
|
||||||
throw check_eq_fail();
|
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)
|
if (a != b)
|
||||||
throw check_eq_fail();
|
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)
|
if (a == b)
|
||||||
throw check_ne_fail();
|
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:
|
// TODO: Implement death check:
|
||||||
// Spawn a new process, and execute the callback in that process.
|
// Spawn a new process, and execute the callback in that process.
|
||||||
// This verifies that a piece of code would cause the process to terminate.
|
// 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.
|
/// Raises an exception, which causes the test to fail.
|
||||||
|
2
main.cpp
2
main.cpp
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
mcolor::windowsSaneify();
|
||||||
|
|
||||||
jtest::Unit u{"jtest-demo"};
|
jtest::Unit u{"jtest-demo"};
|
||||||
u += jtest::Test{"check_true", [] () {
|
u += jtest::Test{"check_true", [] () {
|
||||||
jtest::check(true);
|
jtest::check(true);
|
||||||
|
@@ -21,7 +21,7 @@ namespace jtest {
|
|||||||
// TODO: output "Running Test Unit <name> with <N> tests.
|
// TODO: output "Running Test Unit <name> with <N> tests.
|
||||||
Log(std::format("Running test unit with {} tests...", tests_total));
|
Log(std::format("Running test unit with {} tests...", tests_total));
|
||||||
|
|
||||||
for (event_ptr &connection_ptr: this->listeners) {
|
for (EventPtr &connection_ptr: this->listeners) {
|
||||||
//ulog(std::format("Running Test <{}> [{}/{}]", connection_ptr->callback.Name(), tcnt, this->listeners.size()));
|
//ulog(std::format("Running Test <{}> [{}/{}]", connection_ptr->callback.Name(), tcnt, this->listeners.size()));
|
||||||
|
|
||||||
bool this_test_passed = false;
|
bool this_test_passed = false;
|
||||||
|
Reference in New Issue
Block a user