You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
|
12 hours ago
|
#pragma once
|
||
|
|
#include <source_location>
|
||
|
|
#include <string>
|
||
|
|
#include <stdexcept>
|
||
|
|
#include <iostream>
|
||
|
|
#include <fmt/core.h>
|
||
|
|
#include <functional>
|
||
|
|
|
||
|
|
namespace fuc2 {
|
||
|
|
using Func = std::function<void()>;
|
||
|
|
using Case = std::pair<std::string, Func>;
|
||
|
|
|
||
|
|
struct Options {
|
||
|
|
bool fail_fast;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Set {
|
||
|
|
std::string name;
|
||
|
|
Options options;
|
||
|
|
std::vector<Case> tests;
|
||
|
|
std::source_location location = std::source_location::current();
|
||
|
|
};
|
||
|
|
|
||
|
|
std::string craft_error(
|
||
|
|
const std::string& type,
|
||
|
|
const std::string& test,
|
||
|
|
const std::string &message,
|
||
|
|
const std::source_location location,
|
||
|
|
const std::source_location test_sig =
|
||
|
|
std::source_location::current());
|
||
|
|
|
||
|
|
void CHECK(bool test, const std::string &message="",
|
||
|
|
const std::source_location location = std::source_location::current());
|
||
|
|
|
||
|
|
void EQUAL(auto v1, auto v2, const std::string &message="",
|
||
|
|
const std::source_location location = std::source_location::current())
|
||
|
|
{
|
||
|
|
if(v1 != v2) {
|
||
|
|
auto test_value = fmt::format("{} != {}", v1, v2);
|
||
|
|
throw std::runtime_error(craft_error("EQUAL", test_value, message, location));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void NOT_EQUAL(auto v1, auto v2, const std::string &message="",
|
||
|
|
const std::source_location location = std::source_location::current())
|
||
|
|
{
|
||
|
|
if(v1 == v2) {
|
||
|
|
auto test_value = fmt::format("{} == {}", v1, v2);
|
||
|
|
throw std::runtime_error(craft_error("NOT_EQUAL", test_value, message, location));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void BLOWS_UP(std::function<void()> cb, const std::string &message,
|
||
|
|
const std::source_location location = std::source_location::current());
|
||
|
|
|
||
|
|
int run(const Set& test_set);
|
||
|
|
}
|