A simple way to have multiple test sets.

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

@ -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,

@ -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,6 +5,9 @@
using namespace fuc2;
namespace sample1 {
void test_push_pop_back() {
std::deque<int> ages;
@ -37,7 +40,7 @@ void test_push_pop_front() {
fmt::println("count: {}", ages.size());
}
NOT_EQUAL(ages.size(), size_t(0), "wrong count");
EQUAL(ages.size(), size_t(0), "wrong count");
}
void test_push_blows_up() {
@ -53,8 +56,8 @@ void test_push_blows_up() {
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={
@ -62,5 +65,5 @@ int main(int argc, char* argv[]) {
{"push_pop_front", test_push_pop_front},
{"push_blows_up", test_push_blows_up},
}
});
};
}

@ -3,9 +3,10 @@
#include <string>
#include <fuc2.hpp>
namespace sample_failing {
using namespace fuc2;
void test_push_pop_back() {
void fail_push_pop_back() {
std::deque<int> ages;
for(int i = 0; i < 5; i++) {
@ -20,47 +21,15 @@ void test_push_pop_back() {
}
EQUAL(ages.size(), size_t(0), "wrong count");
NOT_EQUAL(ages.size(), size_t(5), "wrong count");
// THIS FAILS
EQUAL(ages.size(), size_t(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++) {
ages.pop_front();
fmt::println("count: {}", ages.size());
}
NOT_EQUAL(ages.size(), size_t(0), "wrong count");
}
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({
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},
{"fail_pop_back", fail_push_pop_back},
}
});
};
}

Loading…
Cancel
Save