scsl/Test.cc

53 lines
759 B
C++
Raw Normal View History

2023-10-10 02:59:21 +00:00
//
// Created by kyle on 2023-10-09.
//
2023-10-10 13:02:21 +00:00
#include "Exceptions.h"
2023-10-10 02:59:21 +00:00
#include "Test.h"
#include <cassert>
2023-10-11 01:57:43 +00:00
#include <iostream>
#include <sstream>
2023-10-10 02:59:21 +00:00
2023-10-15 01:38:01 +00:00
namespace scsl {
2023-10-10 02:59:21 +00:00
void
TestAssert(bool condition, std::string message)
2023-10-10 02:59:21 +00:00
{
2023-10-15 01:38:01 +00:00
#if defined(NDEBUG) || defined(SCSL_NO_ASSERT)
2023-10-10 02:59:21 +00:00
if (!condition) {
throw AssertionFailed(message);
}
#else
if (!condition) {
std::cerr << message << std::endl;
}
assert(condition);
#endif
}
2023-10-11 01:57:43 +00:00
void
TestAssert(bool condition)
{
#if defined(NDEBUG)
if (condition) {
return;
}
2023-10-15 01:38:01 +00:00
#if defined(SCSL_NO_ASSERT)
2023-10-11 01:57:43 +00:00
std::cerr << "Assertion failed!\n";
#else
std::stringstream msg;
msg << "assertion failed at " << __FILE__ << ":" << __LINE__;
throw AssertionFailed(msg.str());
#endif
#else
assert(condition);
#endif
}
2023-10-15 01:38:01 +00:00
} // namespace scsl