summaryrefslogtreecommitdiffstats
path: root/tests/test_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_main.cpp')
-rw-r--r--tests/test_main.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
new file mode 100644
index 0000000..d74c473
--- /dev/null
+++ b/tests/test_main.cpp
@@ -0,0 +1,43 @@
+#include "framework.hpp"
+
+#include <exception>
+#include <iostream>
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace cepis::testing {
+namespace {
+
+std::vector<std::pair<std::string, std::function<void()>>>& registry() {
+ static std::vector<std::pair<std::string, std::function<void()>>> tests;
+ return tests;
+}
+
+} // namespace
+
+void register_test(const char* name, std::function<void()> body) {
+ registry().emplace_back(name, std::move(body));
+}
+
+int run_all() {
+ int failures = 0;
+ for (const auto& [name, body] : registry()) {
+ try {
+ body();
+ std::cout << "ok " << name << '\n';
+ } catch (const std::exception& error) {
+ ++failures;
+ std::cout << "FAIL " << name << "\n " << error.what() << '\n';
+ } catch (...) {
+ ++failures;
+ std::cout << "FAIL " << name << "\n unknown exception\n";
+ }
+ }
+ std::cout << '\n' << registry().size() << " test(s), " << failures << " failure(s)" << std::endl;
+ return failures == 0 ? 0 : 1;
+}
+
+} // namespace cepis::testing
+
+int main() { return cepis::testing::run_all(); }