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}, + } + }; }