A simple way to have multiple test sets.

master
Zed A. Shaw 11 hours ago
parent fc2dc6cac1
commit 7dc4e10573
  1. 2
      meson.build
  2. 16
      tests/main.cpp
  3. 85
      tests/sample1.cpp
  4. 73
      tests/sample_failing.cpp

@ -41,6 +41,8 @@ fuc2_dep = declare_dependency(
executable('fuc2it', [ executable('fuc2it', [
'tests/sample1.cpp', 'tests/sample1.cpp',
'tests/sample_failing.cpp',
'tests/main.cpp',
], ],
cpp_args: cpp_args, cpp_args: cpp_args,
link_args: link_args, link_args: link_args,

@ -0,0 +1,16 @@
#include <fuc2.hpp>
// 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);
}

@ -5,62 +5,65 @@
using namespace fuc2; using namespace fuc2;
void test_push_pop_back() {
std::deque<int> ages;
for(int i = 0; i < 5; i++) { namespace sample1 {
ages.push_back(i * 34);
}
CHECK(ages.size() == 5, "wrong count"); void test_push_pop_back() {
std::deque<int> ages;
for(int i = 0; i < 5; i++) { for(int i = 0; i < 5; i++) {
ages.pop_back(); ages.push_back(i * 34);
fmt::println("count: {}", ages.size()); }
}
EQUAL(ages.size(), size_t(0), "wrong count"); CHECK(ages.size() == 5, "wrong count");
NOT_EQUAL(ages.size(), size_t(5), "wrong count");
}
void test_push_pop_front() { for(int i = 0; i < 5; i++) {
std::deque<float> ages; ages.pop_back();
fmt::println("count: {}", ages.size());
}
for(int i = 0; i < 5; i++) { EQUAL(ages.size(), size_t(0), "wrong count");
ages.push_front(i * 34); NOT_EQUAL(ages.size(), size_t(5), "wrong count");
} }
CHECK(ages.size() == 5, "wrong count"); void test_push_pop_front() {
std::deque<float> 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++) { for(int i = 0; i < 5; i++) {
ages.pop_front(); ages.pop_front();
fmt::println("count: {}", ages.size()); 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<float> ages;
void test_push_blows_up() { auto runner = [&]() {
std::deque<float> ages; // uncomment this to see how the C++ stdlib sabotages you
// ages.pop_front();
auto runner = [&]() { ages.at(10);
// uncomment this to see how the C++ stdlib sabotages you };
// ages.pop_front();
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[]) { fuc2::Set TESTS{
return run({
.name="std::deque basic operations", .name="std::deque basic operations",
.options={ .fail_fast=false }, .options={ .fail_fast=false },
.tests={ .tests={
{"push_pop_back", test_push_pop_back}, {"push_pop_back", test_push_pop_back},
{"push_pop_front", test_push_pop_front}, {"push_pop_front", test_push_pop_front},
{"push_blows_up", test_push_blows_up}, {"push_blows_up", test_push_blows_up},
} }
}); };
} }

@ -3,64 +3,33 @@
#include <string> #include <string>
#include <fuc2.hpp> #include <fuc2.hpp>
using namespace fuc2; namespace sample_failing {
using namespace fuc2;
void test_push_pop_back() { void fail_push_pop_back() {
std::deque<int> ages; std::deque<int> ages;
for(int i = 0; i < 5; i++) { for(int i = 0; i < 5; i++) {
ages.push_back(i * 34); 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");
}
void test_push_pop_front() { CHECK(ages.size() == 5, "wrong count");
std::deque<float> ages;
for(int i = 0; i < 5; i++) { for(int i = 0; i < 5; i++) {
ages.push_front(i * 34); ages.pop_back();
} fmt::println("count: {}", ages.size());
}
CHECK(ages.size() == 5, "wrong count");
for(int i = 0; i < 5; i++) { EQUAL(ages.size(), size_t(0), "wrong count");
ages.pop_front(); // THIS FAILS
fmt::println("count: {}", ages.size()); EQUAL(ages.size(), size_t(5), "wrong count");
} }
NOT_EQUAL(ages.size(), size_t(0), "wrong count"); fuc2::Set TESTS{
}
void test_push_blows_up() {
std::deque<float> 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({
.name="std::deque basic operations", .name="std::deque basic operations",
.options={ .fail_fast=false }, .options={ .fail_fast=false },
.tests={ .tests={
{"push_pop_back", test_push_pop_back}, {"fail_pop_back", fail_push_pop_back},
{"push_pop_front", test_push_pop_front}, }
{"push_blows_up", test_push_blows_up}, };
}
});
} }

Loading…
Cancel
Save