A small source refactor to make it easier to include in other projects without potentially clashing. Not that there's other people with fuc2 directories.

master
Zed A. Shaw 1 month ago
parent ca5cad83e2
commit 4f58ff285e
  1. 11
      include/fuc2/run.hpp
  2. 2
      include/fuc2/testing.hpp
  3. 3
      meson.build
  4. 46
      src/run.cpp
  5. 45
      src/testing.cpp
  6. 2
      tests/main.cpp
  7. 3
      tests/sample1.cpp
  8. 2
      tests/sample_failing.cpp

@ -0,0 +1,11 @@
#pragma once
#include <fuc2/testing.hpp>
/*
* This is kind of dumb right now but soon I'll have different run
* functions if you want to fork or thread and such. Possibly also
* for TAP output.
*/
namespace fuc2 {
int run(const Set& test_set);
}

@ -1,8 +1,6 @@
#pragma once
#include <source_location>
#include <string>
#include <stdexcept>
#include <iostream>
#include <fmt/core.h>
#include <functional>

@ -22,7 +22,8 @@ fmt = subproject('fmt').get_variable('fmt_dep')
dependencies = [fmt]
sources = [
'src/fuc2.cpp',
'src/testing.cpp',
'src/run.cpp',
]
fuc2_includes = include_directories('include')

@ -0,0 +1,46 @@
#include <string>
#include <fmt/core.h>
#include <fuc2/run.hpp>
namespace fuc2 {
int run(const Set& test_set) {
int fail_count = 0;
std::vector<std::string> errors;
fmt::println("################# {} \"{}\" ###############",
test_set.location.file_name(), test_set.name);
for(const auto& [name, test] : test_set.tests) {
bool did_fail = false;
fmt::println("----------- START {}", name);
try {
test();
} catch(const std::exception& e) {
fail_count++;
did_fail = true;
fmt::println("🚨 FAIL! {}", e.what());
errors.push_back(e.what());
if(test_set.options.fail_fast) {
break;
}
}
std::string pass_fail = did_fail ? "🔴" : "🟢";
fmt::println("{} {}\n==========", pass_fail, name);
}
if(fail_count > 0) {
fmt::println("🚨🚨🚨🚨🚨 FAIL COUNT: {} in {}", fail_count, test_set.location.file_name());
for(auto& msg : errors) {
fmt::println("---------\n{}", msg);
}
} else {
fmt::println("👍 ALL PASS: {}", test_set.location.file_name());
}
return fail_count;
}
}

@ -1,9 +1,7 @@
#include <source_location>
#include <string>
#include <stdexcept>
#include <iostream>
#include <fmt/core.h>
#include "fuc2.hpp"
#include "fuc2/testing.hpp"
namespace fuc2 {
std::string craft_error(
@ -49,45 +47,4 @@ namespace fuc2 {
throw std::runtime_error(craft_error("BLOWSUP", "", message, location));
}
}
int run(const Set& test_set) {
int fail_count = 0;
std::vector<std::string> errors;
fmt::println("################# {} \"{}\" ###############",
test_set.location.file_name(), test_set.name);
for(const auto& [name, test] : test_set.tests) {
bool did_fail = false;
fmt::println("----------- START {}", name);
try {
test();
} catch(const std::exception& e) {
fail_count++;
did_fail = true;
fmt::println("🚨 FAIL! {}", e.what());
errors.push_back(e.what());
if(test_set.options.fail_fast) {
break;
}
}
std::string pass_fail = did_fail ? "🔴" : "🟢";
fmt::println("{} {}\n==========", pass_fail, name);
}
if(fail_count > 0) {
fmt::println("🚨🚨🚨🚨🚨 FAIL COUNT: {} in {}", fail_count, test_set.location.file_name());
for(auto& msg : errors) {
fmt::println("---------\n{}", msg);
}
} else {
fmt::println("👍 ALL PASS: {}", test_set.location.file_name());
}
return fail_count;
}
}

@ -1,4 +1,4 @@
#include <fuc2.hpp>
#include <fuc2/run.hpp>
// you can also place these into a .hpp you include if
// they're too numerous to manage

@ -1,11 +1,10 @@
#include <fmt/core.h>
#include <deque>
#include <string>
#include <fuc2.hpp>
#include <fuc2/testing.hpp>
using namespace fuc2;
namespace sample1 {
void test_push_pop_back() {

@ -1,7 +1,7 @@
#include <fmt/core.h>
#include <deque>
#include <string>
#include <fuc2.hpp>
#include <fuc2/testing.hpp>
namespace sample_failing {
using namespace fuc2;

Loading…
Cancel
Save