1 parent
e7186f17f0
commit
f0825fbd1a
13 files changed
+105
-36
No files matched your search
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
#include <Void/Testing/Reporter.hpp>
|
||||
#include <Void/Testing/Detail/Color.hpp>
|
||||
#include <Void/Stacktrace/Color.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace Void::Testing {
|
||||
class ConsoleReporter final : public Reporter {
|
||||
public:
|
||||
explicit ConsoleReporter(std::ostream& os, bool color_enabled = true) : os_(os) {
|
||||
Detail::Color::g_color_enabled = color_enabled;
|
||||
Void::Stacktrace::Color::g_color_enabled = color_enabled;
|
||||
}
|
||||
void on_run_start(const RunConfig& config, int total_tests) override;
|
||||
void on_suite_start(const std::string& suite_name, int test_count) override;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
namespace Void::Testing::Detail::Color {
|
||||
inline bool g_color_enabled{true};
|
||||
|
||||
constexpr std::string_view reset = "\033[0m";
|
||||
constexpr std::string_view bold = "\033[1m";
|
||||
constexpr std::string_view dim = "\033[2m";
|
||||
constexpr std::string_view bold_red = "\033[1;31m";
|
||||
constexpr std::string_view bold_green = "\033[1;32m";
|
||||
constexpr std::string_view bold_yellow = "\033[1;33m";
|
||||
constexpr std::string_view bold_blue = "\033[1;34m";
|
||||
constexpr std::string_view bold_magenta = "\033[1;35m";
|
||||
constexpr std::string_view bold_cyan = "\033[1;36m";
|
||||
constexpr std::string_view bold_white = "\033[1;37m";
|
||||
constexpr std::string_view red = "\033[31m";
|
||||
constexpr std::string_view green = "\033[32m";
|
||||
constexpr std::string_view yellow = "\033[33m";
|
||||
constexpr std::string_view cyan = "\033[36m";
|
||||
|
||||
inline std::string apply(std::string_view code, std::string_view text) {
|
||||
if (!g_color_enabled) return std::string{text};
|
||||
return std::string{code} + std::string{text} + std::string{reset};
|
||||
}
|
||||
inline std::string success(std::string_view text) { return apply(bold_green, text); }
|
||||
inline std::string fail(std::string_view text) { return apply(bold_red, text); }
|
||||
inline std::string skip(std::string_view text) { return apply(bold_yellow, text); }
|
||||
inline std::string info(std::string_view text) { return apply(bold_cyan, text); }
|
||||
inline std::string hint(std::string_view text) { return apply(dim, text); }
|
||||
inline std::string heading(std::string_view text) { return apply(bold_blue, text); }
|
||||
inline std::string emphasis(std::string_view text) { return apply(bold, text); }
|
||||
} // namespace Void::Testing::Detail::Color
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
namespace Void::Testing::Detail {
|
||||
struct StackFrame {
|
||||
std::string function_name;
|
||||
std::string source_file;
|
||||
int source_line{0};
|
||||
std::string source_snippet;
|
||||
};
|
||||
|
||||
std::vector<StackFrame> capture_stacktrace(unsigned skip_frames = 0, unsigned max_frames = 32);
|
||||
std::string read_source_snippet(const std::string& file, int line, int context_lines = 3);
|
||||
std::string format_stacktrace(const std::vector<StackFrame>& frames);
|
||||
void print_stacktrace(std::ostream& os, const std::vector<StackFrame>& frames);
|
||||
} // namespace Void::Testing::Detail
|
||||
Reference in new issue
Block a user