From 49510912edffbae3a4797690ee1774972c24c89b Mon Sep 17 00:00:00 2001 From: jay-tux Date: Mon, 28 Feb 2022 19:53:48 +0100 Subject: [PATCH 1/2] Moved from gtest to doctest (ewww Google) --- Doxyfile.mk | 2 +- inc/fpgen.hpp | 1 - test/Makefile | 6 +- test/conanfile.txt | 2 +- test/src/test_aggreg.cpp | 131 +++++++++++++++++------------------- test/src/test_chain.cpp | 13 ++-- test/src/test_generator.cpp | 34 +++++----- test/src/test_main.cpp | 4 +- test/src/test_manip.cpp | 122 ++++++++++++++------------------- test/src/test_sources.cpp | 56 +++++++-------- 10 files changed, 170 insertions(+), 201 deletions(-) diff --git a/Doxyfile.mk b/Doxyfile.mk index 1de091a..edf1ff4 100644 --- a/Doxyfile.mk +++ b/Doxyfile.mk @@ -2102,7 +2102,7 @@ MAN_LINKS = NO # captures the structure of the code including all documentation. # The default value is: NO. -GENERATE_XML = NO +GENERATE_XML = YES # The XML_OUTPUT tag is used to specify where the XML pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of diff --git a/inc/fpgen.hpp b/inc/fpgen.hpp index 6afedfe..f2ba0cf 100644 --- a/inc/fpgen.hpp +++ b/inc/fpgen.hpp @@ -5,6 +5,5 @@ #include "generator.hpp" #include "manipulators.hpp" #include "sources.hpp" -#include "stream.hpp" #endif diff --git a/test/Makefile b/test/Makefile index 691197b..f484ccf 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ DEPS=$(SOURCES:$(SRCD)/%.cpp=$(OBJD)/%.d) TESTS=generator sources manip aggreg chain TESTOBJ=$(TESTS:%=$(OBJD)/test_%.o) -CONAN_PKG_OVERRIDE=gtest +CONAN_PKG_OVERRIDE= CONAN_MODIFY=$(CONAN_PKG_OVERRIDE:%=-s %:compiler.version=11.2) all: dirs conan/conanbuildinfo.mak $(BIND)/_test @@ -18,7 +18,7 @@ dirs: @([ ! -d $(OBJD)/sources ] && mkdir -p $(OBJD)/sources) || true $(BIND)/_test: $(TESTOBJ) $(OBJD)/test_main.o - $(CC) $(LDXTRA) $(LDARGS) $^ -o $@ + $(CC) $(LDARGS) $(LDXTRA) $^ -o $@ $(BIND)/_test $(OBJD)/%.o: $(SRCD)/%.cpp Makefile @@ -26,7 +26,7 @@ $(OBJD)/%.o: $(SRCD)/%.cpp Makefile conan/conanbuildinfo.mak: conanfile.txt @([ ! -d conan/ ] && mkdir -p conan/) || true - cd conan && CC=gcc CXX=$(CC) conan install .. $(CONAN_MODIFY) --build=gtest + cd conan && CC=gcc CXX=$(CC) conan install .. $(CONAN_MODIFY) clean: find ./bin/ -type f | grep -v '.gitkeep' | xargs rm -rf diff --git a/test/conanfile.txt b/test/conanfile.txt index 021b071..f664807 100644 --- a/test/conanfile.txt +++ b/test/conanfile.txt @@ -1,5 +1,5 @@ [requires] -gtest/cci.20210126 + doctest/2.4.8 [generators] make diff --git a/test/src/test_aggreg.cpp b/test/src/test_aggreg.cpp index a5a9954..713be26 100644 --- a/test/src/test_aggreg.cpp +++ b/test/src/test_aggreg.cpp @@ -1,9 +1,8 @@ #include "aggregators.hpp" +#include "doctest/doctest.h" #include "generator.hpp" #include "manipulators.hpp" #include "sources.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include #include @@ -46,149 +45,143 @@ size_t sum_ref(size_t &old, size_t in) { return old; } -TEST(aggregate, empty) { +TEST_CASE("Aggregate empty generator") { auto gen = a_empty(); - // gen(); std::vector res; - EXPECT_EQ(0, fpgen::aggregate_to(gen, res).size()); + CHECK(0 == fpgen::aggregate_to(gen, res).size()); } -TEST(aggregate, vector) { +TEST_CASE("Aggregate to std::vector") { auto gen = values(); std::vector res; fpgen::aggregate_to(gen, res); - EXPECT_EQ(0, res[0]); - EXPECT_EQ(1, res[1]); - EXPECT_EQ(1, res[2]); - EXPECT_EQ(2, res[3]); - EXPECT_EQ(3, res[4]); - EXPECT_EQ(5, res[5]); - EXPECT_EQ(8, res[6]); - EXPECT_EQ(13, res[7]); - EXPECT_EQ(21, res[8]); - EXPECT_EQ(34, res[9]); - EXPECT_EQ(res.size(), 10); + CHECK(0 == res[0]); + CHECK(1 == res[1]); + CHECK(1 == res[2]); + CHECK(2 == res[3]); + CHECK(3 == res[4]); + CHECK(5 == res[5]); + CHECK(8 == res[6]); + CHECK(13 == res[7]); + CHECK(21 == res[8]); + CHECK(34 == res[9]); + CHECK(res.size() == 10); } -TEST(aggregate, vec_to_vec) { +TEST_CASE("Aggregate: std::vector to generator to std::vector") { std::vector in = {0, 1, 2, 3, 4, 5, 6}; std::vector out = {}; auto gen = fpgen::from(in); out = fpgen::aggregate_to(gen, out); - EXPECT_EQ(in, out); + CHECK(in == out); } -TEST(aggregate, map) { +TEST_CASE("Aggregate to std::map") { fpgen::generator sources[2] = {values(), values()}; auto gen = fpgen::zip(sources[0], sources[1]); std::map res; fpgen::tup_aggregate_to(gen, res); - EXPECT_EQ(0, res[0]); - EXPECT_EQ(1, res[1]); - EXPECT_EQ(2, res[2]); - EXPECT_EQ(3, res[3]); - EXPECT_EQ(5, res[5]); - EXPECT_EQ(8, res[8]); - EXPECT_EQ(13, res[13]); - EXPECT_EQ(21, res[21]); - EXPECT_EQ(34, res[34]); - EXPECT_EQ(res.size(), 9); + CHECK(0 == res[0]); + CHECK(1 == res[1]); + CHECK(2 == res[2]); + CHECK(3 == res[3]); + CHECK(5 == res[5]); + CHECK(8 == res[8]); + CHECK(13 == res[13]); + CHECK(21 == res[21]); + CHECK(34 == res[34]); + CHECK(res.size() == 9); } -TEST(aggregate, count_empty) { +TEST_CASE("Count empty generator") { auto gen = a_empty(); - // gen(); - EXPECT_EQ(0, fpgen::count(gen)); + CHECK(0 == fpgen::count(gen)); } -TEST(aggregate, count) { +TEST_CASE("Count generator") { auto gen = values(); - EXPECT_EQ(10, fpgen::count(gen)); + CHECK(10 == fpgen::count(gen)); } -TEST(fold, fold_noin_empty) { +TEST_CASE("Fold [using no-input, empty generator]") { auto gen = a_empty(); - // gen(); - EXPECT_EQ(0, fpgen::fold(gen, sum)); + CHECK(0 == fpgen::fold(gen, sum)); } -TEST(fold, fold_noin) { +TEST_CASE("Fold [using no-input, non-empty generator]") { auto gen = values(); - EXPECT_EQ(calc_sum(), fpgen::fold(gen, sum)); + CHECK(calc_sum() == fpgen::fold(gen, sum)); } -TEST(fold, fold_in_noref_empty) { +TEST_CASE("Fold [using input, empty generator]") { auto gen = a_empty(); - // gen(); - EXPECT_EQ(7, fpgen::fold(gen, sum, 7)); + CHECK(7 == fpgen::fold(gen, sum, 7)); } -TEST(fold, fold_in_noref) { +TEST_CASE("Fold [using input, non-empty generator]") { auto gen = values(); - EXPECT_EQ(calc_sum() + 7, fpgen::fold(gen, sum, 7)); + CHECK(calc_sum() + 7 == fpgen::fold(gen, sum, 7)); } -TEST(fold, fold_in_ref_empty) { +TEST_CASE("Fold [using ref input, empty generator]") { auto gen = a_empty(); - // gen(); size_t res = 7; - EXPECT_EQ(7, fpgen::fold_ref(gen, sum, res)); - EXPECT_EQ(7, res); + CHECK(7 == fpgen::fold_ref(gen, sum, res)); + CHECK(7 == res); } -TEST(fold, fold_in_ref) { +TEST_CASE("Fold [using ref input, non-epty generator]") { auto gen = values(); size_t res = 7; - EXPECT_EQ(calc_sum() + 7, fpgen::fold_ref(gen, sum, res)); - EXPECT_EQ(calc_sum() + 7, res); + CHECK(calc_sum() + 7 == fpgen::fold_ref(gen, sum, res)); + CHECK(calc_sum() + 7 == res); } -TEST(sum, empty) { +TEST_CASE("Sum empty generator") { auto gen = a_empty(); - // gen(); - EXPECT_EQ(0, fpgen::sum(gen)); + CHECK(0 == fpgen::sum(gen)); } -TEST(sum, normal) { +TEST_CASE("Sum over generator") { auto gen = values(); - EXPECT_EQ(calc_sum(), fpgen::sum(gen)); + CHECK(calc_sum() == fpgen::sum(gen)); } -TEST(foreach, empty) { +TEST_CASE("Foreach over empty generator") { auto gen = a_empty(); // gen(); size_t res = 0; fpgen::foreach (gen, [&res](size_t val) { res += val; }); - EXPECT_EQ(res, 0); + CHECK(res == 0); } -TEST(foreach, normal) { +TEST_CASE("Foreach over non-empty generator") { auto gen = values(); auto gen2 = values(); size_t res = 0; fpgen::foreach (gen, [&res](size_t val) { res += val; }); - EXPECT_EQ(res, fpgen::sum(gen2)); + CHECK(res == fpgen::sum(gen2)); } -TEST(stream, nosep) { +TEST_CASE("Output to stream, no separator") { std::vector vals = {1, 2, 3, 4, 5, 6}; auto gen = fpgen::from(vals); std::stringstream strm; fpgen::to_stream(gen, strm); - EXPECT_EQ(strm.str(), "123456"); + CHECK(strm.str() == "123456"); } -TEST(stream, sep) { +TEST_CASE("Output to stream, with separator") { std::vector vals = {1, 2, 3, 4, 5, 6, 7}; auto gen = fpgen::from(vals); std::stringstream strm; fpgen::to_stream(gen, strm, " "); - EXPECT_EQ(strm.str(), "1 2 3 4 5 6 7"); + CHECK(strm.str() == "1 2 3 4 5 6 7"); } -TEST(stream, lines_trail) { +TEST_CASE("Output to stream (by lines), with trailing line") { std::vector vals = {1, 2, 3, 4}; auto gen = fpgen::from(vals); std::stringstream strm; @@ -196,15 +189,15 @@ TEST(stream, lines_trail) { for (auto v : vals) expect << v << std::endl; fpgen::to_lines(gen, strm); - EXPECT_EQ(strm.str(), expect.str()); + CHECK(strm.str() == expect.str()); } -TEST(stream, lines_no_trail) { +TEST_CASE("Output to stream (by lines), without trailing line") { std::vector vals = {1, 2, 3, 4}; auto gen = fpgen::from(vals); std::stringstream strm; std::stringstream expect; expect << 1 << std::endl << 2 << std::endl << 3 << std::endl << 4; fpgen::to_lines_no_trail(gen, strm); - EXPECT_EQ(strm.str(), expect.str()); + CHECK(strm.str() == expect.str()); } diff --git a/test/src/test_chain.cpp b/test/src/test_chain.cpp index f9a4158..75ad3dc 100644 --- a/test/src/test_chain.cpp +++ b/test/src/test_chain.cpp @@ -1,9 +1,8 @@ #include "aggregators.hpp" +#include "doctest/doctest.h" #include "generator.hpp" #include "manipulators.hpp" #include "sources.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" using namespace fpgen; @@ -12,7 +11,7 @@ std::ostream &operator<<(std::ostream &in, std::tuple &other) { return in << "{ " << std::get<0>(other) << ", " << std::get<1>(other) << " }"; } -TEST(chain, simple_chain) { +TEST_CASE("Simple chain check") { /* Chain: -> [0..] -> [5..] -> [5..13] -> [15...169] \ @@ -27,10 +26,10 @@ TEST(chain, simple_chain) { size_t value = 5; for (auto v : zip(gen, second)) { - EXPECT_EQ(value * value, std::get<0>(v)); - EXPECT_EQ('a' + 2 + value, std::get<1>(v)); - EXPECT_TRUE(value <= 13); + CHECK(value * value == std::get<0>(v)); + CHECK('a' + 2 + value == std::get<1>(v)); + CHECK(value <= 13); value++; } - EXPECT_EQ(value, 14); + CHECK(value == 14); } diff --git a/test/src/test_generator.cpp b/test/src/test_generator.cpp index a63e552..d6b3331 100644 --- a/test/src/test_generator.cpp +++ b/test/src/test_generator.cpp @@ -1,6 +1,5 @@ +#include "doctest/doctest.h" #include "generator.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include fpgen::generator empty() { co_return; } @@ -20,46 +19,43 @@ fpgen::generator finite_squares(int min, int max) { co_return; // max *max; } -TEST(generator, accept_empty_gen) { - auto emptygen = empty(); - SUCCEED(); -} +TEST_CASE("Generator accepts empty generator") { auto emptygen = empty(); } -TEST(generator, iterator_empty_gen) { +TEST_CASE("Iterator over an empty generator") { auto gen = empty(); - // gen(); for (auto v : gen) { - FAIL(); + CHECK(false); // should fail } - SUCCEED(); } -TEST(generator, can_call_and_continue) { +TEST_CASE("Call-and-continue for a generator") { auto intgen = infinite(); int value = intgen(); - EXPECT_EQ(0, value); + CHECK(0 == value); value = intgen(); - EXPECT_EQ(1, value); + CHECK(1 == value); } -TEST(generator, can_while_over) { +TEST_CASE("Use while over a generator") { int value; int expect = 0; auto intgen2 = finite_squares(0, 12); while (intgen2) { value = intgen2(); - EXPECT_THAT(expect, testing::AllOf(testing::Le(12), testing::Ge(0))); - EXPECT_EQ(expect * expect, value); + CHECK(expect <= 12); + CHECK(expect >= 0); + CHECK(expect * expect == value); expect++; } } -TEST(generator, iterator) { +TEST_CASE("Iterate over a generator") { int expect = -4; auto intgen3 = finite_squares(-4, 8); for (auto value : intgen3) { - EXPECT_THAT(expect, testing::AllOf(testing::Le(8), testing::Ge(-4))); - EXPECT_EQ(expect * expect, value); + CHECK(expect <= 8); + CHECK(expect >= -4); + CHECK(expect * expect == value); expect++; } } diff --git a/test/src/test_main.cpp b/test/src/test_main.cpp index 4e26ef4..92675cb 100644 --- a/test/src/test_main.cpp +++ b/test/src/test_main.cpp @@ -1,3 +1,3 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest/doctest.h" #include "generator.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" diff --git a/test/src/test_manip.cpp b/test/src/test_manip.cpp index 9df732a..d2469e2 100644 --- a/test/src/test_manip.cpp +++ b/test/src/test_manip.cpp @@ -1,8 +1,7 @@ +#include "doctest/doctest.h" #include "generator.hpp" #include "manipulators.hpp" #include "sources.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include #include @@ -31,61 +30,52 @@ size_t mapper(size_t v) { return v * v; } bool is_even(size_t v) { return (v % 2 == 0); } bool over_100(size_t v) { return (v > 100); } -TEST(manipulators, map_empty) { +TEST_CASE("Map over empty generator") { auto gen = manip_empty(); - // gen(); for (auto v : fpgen::map(gen, mapper)) { - FAIL() << "Should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, map) { +TEST_CASE("Map over a non-empty generator") { auto gen = manip(); size_t i = 1; for (auto v : fpgen::map(gen, mapper)) { - EXPECT_EQ(i * i, v); - EXPECT_TRUE(i <= 1024); + CHECK(i * i == v); + CHECK(i <= 1024); i *= 2; } } -TEST(manipulators, zip_both_empty) { +TEST_CASE("Zip over two empty generator") { auto gen = manip_empty(); auto gen2 = manip_empty(); - // gen(); - // gen2(); for (auto v : fpgen::zip(gen, gen2)) { - FAIL() << "Should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, zip_first_empty) { +TEST_CASE("Zip, first generator is empty") { auto gen = manip_empty(); auto gen2 = fpgen::inc((size_t)0); - // gen(); for (auto v : fpgen::zip(gen, gen2)) { - FAIL() << "Should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, zip_second_empty) { +TEST_CASE("Zip, second generator is empty") { auto gen = fpgen::inc((size_t)0); auto gen2 = manip_empty(); - // gen2(); for (auto v : fpgen::zip(gen, gen2)) { - FAIL() << "Should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, zip_none_empty) { +TEST_CASE("Zip, both generators are non-empty") { auto gen = fpgen::inc((size_t)0); auto gen2 = manip(); @@ -93,132 +83,124 @@ TEST(manipulators, zip_none_empty) { size_t j = 1; for (auto v : fpgen::zip(gen, gen2)) { - EXPECT_EQ(std::get<0>(v), i); - EXPECT_EQ(std::get<1>(v), j); - EXPECT_TRUE(j <= 1024); - EXPECT_TRUE(i <= 10); + CHECK(std::get<0>(v) == i); + CHECK(std::get<1>(v) == j); + CHECK(j <= 1024); + CHECK(i <= 10); i++; j *= 2; } } -TEST(manipulators, filter_empty) { +TEST_CASE("Filter an empty generator") { auto gen = manip_empty(); - // gen(); size_t i = 0; for (auto v : fpgen::filter(gen, is_even)) { - FAIL(); + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, filter_to_empty) { +TEST_CASE("Filter to an empty generator") { auto gen = until12(); for (auto v : fpgen::filter(gen, over_100)) { - FAIL(); + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, filter_normal) { +TEST_CASE("Filter a generator") { auto gen = until12(); size_t i = 0; for (auto v : fpgen::filter(gen, is_even)) { - EXPECT_EQ(v, i); - EXPECT_TRUE(i <= 12); + CHECK(v == i); + CHECK(i <= 12); i += 2; } } -TEST(manipulators, drop_empty) { +TEST_CASE("Drop from an empty generator") { auto gen = drop(manip_empty(), 5); for (auto v : gen) { - FAIL() << "should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, drop_normal) { +TEST_CASE("Drop from a generator") { auto gen = drop(until12(), 5); size_t exp = 5; for (auto v : gen) { - EXPECT_EQ(v, exp); - EXPECT_TRUE(exp <= 12); + CHECK(v == exp); + CHECK(exp <= 12); exp++; } - EXPECT_EQ(exp, 13); + CHECK(exp == 13); } -TEST(manipulators, take_empty) { +TEST_CASE("Take from an empty generator") { auto gen = take(manip_empty(), 4); for (auto v : gen) { - FAIL() << "should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, take_normal) { +TEST_CASE("Take from a generator") { auto gen = take(fpgen::inc((size_t)0), 8); size_t exp = 0; for (auto v : gen) { - EXPECT_EQ(v, exp); - EXPECT_TRUE(exp <= 8); + CHECK(v == exp); + CHECK(exp <= 8); exp++; } - EXPECT_EQ(exp, 8); + CHECK(exp == 8); } -TEST(manipulators, drop_take) { +TEST_CASE("Drop & take from generator") { auto gen = take(drop(fpgen::inc((size_t)0), 4), 9); for (size_t exp = 4; exp < 13; exp++) { - EXPECT_TRUE(static_cast(gen)); - EXPECT_EQ(exp, gen()); + CHECK(static_cast(gen)); + CHECK(exp == gen()); } for (auto v : gen) { - FAIL() << "should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, drop_while_empty) { +TEST_CASE("Dropwhile over an empty generator") { auto gen = drop_while(manip_empty(), [](size_t v) { return v > 3; }); for (auto v : gen) { - FAIL() << "should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, drop_while_normal) { +TEST_CASE("Dropwhile over a generator") { auto gen = drop_while(until12(), [](size_t v) { return v < 5; }); size_t exp = 5; for (auto v : gen) { - EXPECT_EQ(v, exp); - EXPECT_TRUE(exp <= 12); + CHECK(v == exp); + CHECK(exp <= 12); exp++; } - EXPECT_EQ(exp, 13); + CHECK(exp == 13); } -TEST(manipulators, take_while_empty) { +TEST_CASE("Takewile over an empty generator") { auto gen = take_while(manip_empty(), [](size_t v) { return v < 4; }); for (auto v : gen) { - FAIL() << "should not return a value"; + CHECK(false); // should fail } - SUCCEED(); } -TEST(manipulators, take_while_normal) { +TEST_CASE("Takewhile over a generator") { auto gen = take_while(fpgen::inc((size_t)0), [](size_t v) { return v < 8; }); size_t exp = 0; for (auto v : gen) { - EXPECT_EQ(v, exp); - EXPECT_TRUE(exp <= 8); + CHECK(v == exp); + CHECK(exp <= 8); exp++; } - EXPECT_EQ(exp, 8); + CHECK(exp == 8); } diff --git a/test/src/test_sources.cpp b/test/src/test_sources.cpp index f7ac4d0..f81e13f 100644 --- a/test/src/test_sources.cpp +++ b/test/src/test_sources.cpp @@ -1,66 +1,66 @@ +#include "doctest/doctest.h" #include "generator.hpp" #include "sources.hpp" -#include "gmock/gmock.h" -#include "gtest/gtest.h" +#include #include #include #include #include #include -TEST(sources, from_vector) { +TEST_CASE("Generator from std::vector") { std::vector values = {0, 5, 1, 4, 2, 3}; size_t idx = 0; for (auto v : fpgen::from(values)) { - EXPECT_EQ(values[idx], v); + CHECK(values[idx] == v); idx++; } } -TEST(sources, from_set) { +TEST_CASE("Generator from std::set") { std::set srcs = {"key 1", "key 2", "key 3", "something"}; std::set todo = {"key 1", "key 2", "key 3", "something"}; for (auto v : fpgen::from(srcs)) { - EXPECT_NE(todo.find(v), todo.end()); + CHECK(todo.find(v) != todo.end()); todo.erase(v); } - EXPECT_TRUE(todo.empty()); + CHECK(todo.empty()); } -TEST(sources, enumerate_vector) { +TEST_CASE("Generator from enumerate over std::vector") { std::vector values = {'a', 'c', 'e', 'k', 'j', 't'}; size_t prev = 0; for (auto v : fpgen::enumerate(values)) { - EXPECT_EQ(std::get<0>(v), prev); - EXPECT_EQ(values[prev], std::get<1>(v)); + CHECK(std::get<0>(v) == prev); + CHECK(values[prev] == std::get<1>(v)); prev++; } } -TEST(sources, from_map_tup) { +TEST_CASE("Generator from std::map") { std::map map = {{"key 1", "value 1"}, {"key 2", "value 2"}, {"key 3", "value 3"}, {"something", "else"}}; std::set todo = {"key 1", "key 2", "key 3", "something"}; for (auto v : fpgen::from_tup(map)) { - EXPECT_NE(todo.find(std::get<0>(v)), todo.end()); - EXPECT_EQ(map[std::get<0>(v)], std::get<1>(v)); + CHECK(todo.find(std::get<0>(v)) != todo.end()); + CHECK(map[std::get<0>(v)] == std::get<1>(v)); todo.erase(std::get<0>(v)); } - EXPECT_TRUE(todo.empty()); + CHECK(todo.empty()); } -TEST(sources, incrementable) { +TEST_CASE("Incrementable generator (int)") { auto gen = fpgen::inc(0); for (int i = 0; i < 25; i++) { - EXPECT_EQ(gen(), i); + CHECK(gen() == i); } } -TEST(sources, incrementable_struct) { +TEST_CASE("Incrementable generator (struct)") { struct inc_struct { int value; inline inc_struct operator++() { @@ -77,11 +77,11 @@ TEST(sources, incrementable_struct) { auto gen = fpgen::inc(v1); for (int i = 0; i < 25; i++) { - EXPECT_EQ(gen().value, i); + CHECK(gen().value == i); } } -TEST(sources, instream) { +TEST_CASE("Generator from std::istream") { std::vector numbers = {1, 2, 3, 4, 5}; std::stringstream str; for (auto v : numbers) @@ -95,17 +95,17 @@ TEST(sources, instream) { auto gen = fpgen::from_stream(str, func); for (int i = 0; i < 5; i++) { bool genstate = gen; - EXPECT_TRUE(genstate); + CHECK(genstate); auto tmp = gen(); - EXPECT_EQ(tmp, numbers[i]); + CHECK(tmp == numbers[i]); std::cout << i << "," << tmp << std::endl; } bool genstate = gen; - EXPECT_FALSE(genstate); + CHECK(genstate); } -TEST(sources, lipsum_lines) { +TEST_CASE("Generator from std::istream, by lines") { std::string lipsum = R"( Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque diam magna, laoreet non dictum eget, scelerisque eu nibh. Cras luctus purus sit amet @@ -141,13 +141,13 @@ Etiam vel porta augue. Maecenas volutpat odio in lacus sagittis fermentum. std::stringstream strm; strm << lipsum; auto gen = fpgen::from_lines(strm); - EXPECT_EQ("", gen()); + CHECK("" == gen()); for (size_t i = 0; i < 10; i++) { bool gens = gen; - EXPECT_TRUE(gens); - EXPECT_EQ(gen(), lines[i]); + CHECK(gens); + CHECK(gen() == lines[i]); } - EXPECT_EQ(gen(), ""); + CHECK(gen() == ""); bool gens = gen; - EXPECT_FALSE(gens); + CHECK(!gens); } From 1950f8cd8c3f0c8378f1f7c49eae802a21bca843 Mon Sep 17 00:00:00 2001 From: jay-tux Date: Mon, 28 Feb 2022 20:10:04 +0100 Subject: [PATCH 2/2] Make tests run always, fix test issue --- test/Makefile | 2 +- test/src/test_sources.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index f484ccf..00c3c50 100644 --- a/test/Makefile +++ b/test/Makefile @@ -33,4 +33,4 @@ clean: find ./obj/ -type f | grep -v '.gitkeep' | xargs rm -rf find ./conan/ -type f | grep -v '.gitkeep' | xargs rm -rf -.PHONY: all dirs clean $(TESTS:%=$(BIND)/%) +.PHONY: all dirs clean $(TESTS:%=$(BIND)/%) $(BIND)/_test diff --git a/test/src/test_sources.cpp b/test/src/test_sources.cpp index f81e13f..4600bcd 100644 --- a/test/src/test_sources.cpp +++ b/test/src/test_sources.cpp @@ -102,7 +102,7 @@ TEST_CASE("Generator from std::istream") { } bool genstate = gen; - CHECK(genstate); + CHECK(!genstate); } TEST_CASE("Generator from std::istream, by lines") {