From 7dc4e10573131fa0b352d268f164f7a16a8d2e3e Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 15 Jun 2026 00:05:20 -0400 Subject: [PATCH] A simple way to have multiple test sets. --- meson.build | 2 + tests/main.cpp | 16 ++++++++ tests/sample1.cpp | 85 +++++++++++++++++++++------------------- tests/sample_failing.cpp | 73 ++++++++++------------------------ 4 files changed, 83 insertions(+), 93 deletions(-) create mode 100644 tests/main.cpp diff --git a/meson.build b/meson.build index d19262a..bd01bd1 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,8 @@ fuc2_dep = declare_dependency( executable('fuc2it', [ 'tests/sample1.cpp', + 'tests/sample_failing.cpp', + 'tests/main.cpp', ], cpp_args: cpp_args, link_args: link_args, diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..104091e --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,16 @@ +#include + +// you can also place these into a .hpp you include if +// they're too numerous to manage +namespace sample1 { + extern fuc2::Set TESTS; +} + +namespace sample_failing { + extern fuc2::Set TESTS; +} + +int main(int argc, char* argv[]) { + run(sample1::TESTS); + run(sample_failing::TESTS); +} diff --git a/tests/sample1.cpp b/tests/sample1.cpp index 86aae54..e22e337 100644 --- a/tests/sample1.cpp +++ b/tests/sample1.cpp @@ -5,62 +5,65 @@ using namespace fuc2; -void test_push_pop_back() { - std::deque ages; - for(int i = 0; i < 5; i++) { - ages.push_back(i * 34); - } +namespace sample1 { - CHECK(ages.size() == 5, "wrong count"); + void test_push_pop_back() { + std::deque ages; - for(int i = 0; i < 5; i++) { - ages.pop_back(); - fmt::println("count: {}", ages.size()); - } + for(int i = 0; i < 5; i++) { + ages.push_back(i * 34); + } - EQUAL(ages.size(), size_t(0), "wrong count"); - NOT_EQUAL(ages.size(), size_t(5), "wrong count"); -} + CHECK(ages.size() == 5, "wrong count"); -void test_push_pop_front() { - std::deque ages; + for(int i = 0; i < 5; i++) { + ages.pop_back(); + fmt::println("count: {}", ages.size()); + } - for(int i = 0; i < 5; i++) { - ages.push_front(i * 34); + EQUAL(ages.size(), size_t(0), "wrong count"); + NOT_EQUAL(ages.size(), size_t(5), "wrong count"); } - CHECK(ages.size() == 5, "wrong count"); + void test_push_pop_front() { + std::deque ages; + + for(int i = 0; i < 5; i++) { + ages.push_front(i * 34); + } + + CHECK(ages.size() == 5, "wrong count"); - for(int i = 0; i < 5; i++) { - ages.pop_front(); - fmt::println("count: {}", ages.size()); + for(int i = 0; i < 5; i++) { + ages.pop_front(); + fmt::println("count: {}", ages.size()); + } + + EQUAL(ages.size(), size_t(0), "wrong count"); } - NOT_EQUAL(ages.size(), size_t(0), "wrong count"); -} + void test_push_blows_up() { + std::deque ages; -void test_push_blows_up() { - std::deque ages; + auto runner = [&]() { + // uncomment this to see how the C++ stdlib sabotages you + // ages.pop_front(); - auto runner = [&]() { - // uncomment this to see how the C++ stdlib sabotages you - // ages.pop_front(); + ages.at(10); + }; - ages.at(10); - }; + BLOWS_UP(runner, "pop_front empty should crash"); + } - BLOWS_UP(runner, "pop_front empty should crash"); -} -int main(int argc, char* argv[]) { - return run({ + fuc2::Set TESTS{ .name="std::deque basic operations", - .options={ .fail_fast=false }, - .tests={ - {"push_pop_back", test_push_pop_back}, - {"push_pop_front", test_push_pop_front}, - {"push_blows_up", test_push_blows_up}, - } - }); + .options={ .fail_fast=false }, + .tests={ + {"push_pop_back", test_push_pop_back}, + {"push_pop_front", test_push_pop_front}, + {"push_blows_up", test_push_blows_up}, + } + }; } diff --git a/tests/sample_failing.cpp b/tests/sample_failing.cpp index 86aae54..46b29c6 100644 --- a/tests/sample_failing.cpp +++ b/tests/sample_failing.cpp @@ -3,64 +3,33 @@ #include #include -using namespace fuc2; +namespace sample_failing { + using namespace fuc2; -void test_push_pop_back() { - std::deque ages; + void fail_push_pop_back() { + std::deque ages; - for(int i = 0; i < 5; i++) { - ages.push_back(i * 34); - } - - CHECK(ages.size() == 5, "wrong count"); - - for(int i = 0; i < 5; i++) { - ages.pop_back(); - fmt::println("count: {}", ages.size()); - } - - EQUAL(ages.size(), size_t(0), "wrong count"); - NOT_EQUAL(ages.size(), size_t(5), "wrong count"); -} + for(int i = 0; i < 5; i++) { + ages.push_back(i * 34); + } -void test_push_pop_front() { - std::deque ages; + CHECK(ages.size() == 5, "wrong count"); - for(int i = 0; i < 5; i++) { - ages.push_front(i * 34); - } - - CHECK(ages.size() == 5, "wrong count"); + for(int i = 0; i < 5; i++) { + ages.pop_back(); + fmt::println("count: {}", ages.size()); + } - for(int i = 0; i < 5; i++) { - ages.pop_front(); - fmt::println("count: {}", ages.size()); + EQUAL(ages.size(), size_t(0), "wrong count"); + // THIS FAILS + EQUAL(ages.size(), size_t(5), "wrong count"); } - NOT_EQUAL(ages.size(), size_t(0), "wrong count"); -} - -void test_push_blows_up() { - std::deque ages; - - auto runner = [&]() { - // uncomment this to see how the C++ stdlib sabotages you - // ages.pop_front(); - - ages.at(10); - }; - - BLOWS_UP(runner, "pop_front empty should crash"); -} - -int main(int argc, char* argv[]) { - return run({ + fuc2::Set TESTS{ .name="std::deque basic operations", - .options={ .fail_fast=false }, - .tests={ - {"push_pop_back", test_push_pop_back}, - {"push_pop_front", test_push_pop_front}, - {"push_blows_up", test_push_blows_up}, - } - }); + .options={ .fail_fast=false }, + .tests={ + {"fail_pop_back", fail_push_pop_back}, + } + }; }