Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Testing.hpp
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7#ifndef ENGINE_TESTRUNNER
8#define ENGINE_TESTRUNNER
9
10#define EXPAND(A) #A
11#define STRINGIFY(A) EXPAND(A)
12
13#include <vector>
14#include <string>
15#include <functional>
16#include <chrono>
17#include <iostream>
18
19namespace Testing {
20
53 class TestRunner {
54 private:
55 struct Test {
56 std::string name;
57 std::function<void()> test;
58 };
59
60 bool m_currentSuccess = true;
61
62 std::vector<Test> m_tests;
63 unsigned int m_passedTests = 0;
64 std::string m_testName;
65
66 std::vector<std::string> m_logs;
67
68 public:
69
79 static TestRunner& getInstance(std::string name = "Test");
80
87 void addTest(std::string name, std::function<void()> test);
88
93 void runTests();
94
101 void DebugLog(std::string message);
102
108 void DebugError(std::string message);
109
122 void Assert(bool condition, std::string message);
123
127 void PrintLogs();
128
134 unsigned int getTestCount();
135
141 unsigned int getPassedTestCount();
142 };
143};
144
145#endif
A Unit tester used to run C++ unit tests.
Definition Testing.hpp:53
void DebugLog(std::string message)
Definition Testing.cpp:48
unsigned int getTestCount()
Definition Testing.cpp:73
unsigned int getPassedTestCount()
Definition Testing.cpp:77
void addTest(std::string name, std::function< void()> test)
Definition Testing.cpp:18
void Assert(bool condition, std::string message)
Definition Testing.cpp:57
void PrintLogs()
Definition Testing.cpp:63
static TestRunner & getInstance(std::string name="Test")
Definition Testing.cpp:11
void DebugError(std::string message)
Definition Testing.cpp:52
void runTests()
Definition Testing.cpp:22