diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 12:28:10 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 12:28:10 -0300 |
| commit | b71faa6e95a0736f1ff171e006b171467b65db90 (patch) | |
| tree | 7580c3ab515e8f50726dc68dbc240995ff4a1a4c /tests/test_main.cpp | |
| download | cpp-b71faa6e95a0736f1ff171e006b171467b65db90.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'tests/test_main.cpp')
| -rw-r--r-- | tests/test_main.cpp | 43 |
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(); } |