A very simple testing framework that rejects all previous testing designs and aims for plain wording, simple usability, and ease of debugging. You will never ask where a failure was ever again.
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.
fuc2/include/fuc2.hpp

58 lines
1.6 KiB

#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);
}