Skip to content

Commit

Permalink
extended step callback signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoSe1990 committed Nov 6, 2024
1 parent 320abd7 commit a4e5585
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 65 deletions.
44 changes: 22 additions & 22 deletions gtest/catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Step a step with {int} and {string}
Step another step with {word} and {}
)";
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"a step with {int} and {string}"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"another step with {word} and {}"));

EXPECT_EQ(expected, cuke::catalog::as_readable_text());
Expand All @@ -38,13 +38,13 @@ When something happens
Then we expect a lot
)";
cuke::registry().push_step(
step([](const cuke::value_array& values, const auto&, const auto&) {},
step([](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"a given step", step::type::given));
cuke::registry().push_step(
step([](const cuke::value_array& values, const auto&, const auto&) {},
step([](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"something happens", step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array& values, const auto&, const auto&) {},
step([](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"we expect a lot", step::type::then));

EXPECT_EQ(expected, cuke::catalog::as_readable_text());
Expand All @@ -67,31 +67,31 @@ Step h
)";

cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "a",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "b",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "b",
step::type::then));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "c",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "c",
step::type::given));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "d",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "d",
step::type::given));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "e",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "e",
step::type::then));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "f",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "f",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "g",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "g",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "h",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "h",
step::type::step));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "i",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "i",
step::type::when));

EXPECT_EQ(expected, cuke::catalog::as_readable_text());
Expand Down Expand Up @@ -124,10 +124,10 @@ TEST_F(catalog, as_json_1)
})";

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"a step with {int} and {string}"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"another step with {word} and {}"));

EXPECT_EQ(expected, cuke::catalog::as_json());
Expand All @@ -141,22 +141,22 @@ TEST_F(catalog, as_json_2)
R"({"steps_catalog":[{"definition":"lets start with {}, {double} and {int}","function":"func3","type":"Given","var_types":["anonymous","double","int"]},{"definition":"lets start with {float} and {double}","function":"func4","type":"Given","var_types":["float","double"]},{"definition":"something with {string} and {long} happens","function":"func2","type":"When","var_types":["string","long"]},{"definition":"{float} added to {double}","function":"func5","type":"When","var_types":["float","double"]},{"definition":"step with {byte} and {word}","function":"func1","type":"Then","var_types":["byte","word"]},{"definition":"we have a lot {},{double},{int},{word},{string},{string},{int},{int},{string},{float},{byte}","function":"func6","type":"Then","var_types":["anonymous","double","int","word","string","string","int","int","string","float","byte"]}]})";

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"step with {byte} and {word}", step::type::then, "func1"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"something with {string} and {long} happens", step::type::when, "func2"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"lets start with {}, {double} and {int}", step::type::given, "func3"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"lets start with {float} and {double}", step::type::given, "func4"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"{float} added to {double}", step::type::when, "func5"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"we have a lot "
"{},{double},{int},{word},{string},{string},{int},{int},{string},{float},"
"{byte}",
Expand Down
4 changes: 2 additions & 2 deletions gtest/file_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class file_io : public ::testing::Test
void SetUp() override
{
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&) {},
[](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"a step with {int} and {string}"));
}
void TearDown() override
Expand Down
10 changes: 5 additions & 5 deletions gtest/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class hooks_before : public ::testing::Test
cuke::internal::hook([]() { hook_called = true; }));

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{
ASSERT_TRUE(hook_called);
step_called = true;
Expand Down Expand Up @@ -58,7 +58,7 @@ class hooks_after : public ::testing::Test
cuke::internal::hook([]() { hook_called = true; }));

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{
ASSERT_FALSE(hook_called);
step_called = true;
Expand Down Expand Up @@ -99,7 +99,7 @@ class hooks_after_tagged : public ::testing::Test
cuke::internal::hook([]() { hook_called = true; }, "@tag"));

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{
ASSERT_FALSE(hook_called);
step_called = true;
Expand Down Expand Up @@ -159,7 +159,7 @@ class hooks_before_all : public ::testing::Test
cuke::internal::hook([]() { hook_called = true; }));

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{
ASSERT_TRUE(hook_called);
step_called = true;
Expand Down Expand Up @@ -204,7 +204,7 @@ class hooks_after_all : public ::testing::Test
cuke::internal::hook([]() { hook_called = true; }));

cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{
ASSERT_FALSE(hook_called);
step_called = true;
Expand Down
32 changes: 16 additions & 16 deletions gtest/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class registry_tests : public ::testing::Test
TEST_F(registry_tests, steps)
{
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
EXPECT_EQ(cuke::registry().steps().size(), 1);
}

Expand Down Expand Up @@ -71,12 +71,12 @@ TEST_F(registry_tests, default_order)
{
using namespace cuke::internal;
cuke::registry().push_step(step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {},
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"another step"));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {},
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"a given step", step::type::given));

ASSERT_EQ(cuke::registry().steps().size(), 3);
Expand All @@ -89,12 +89,12 @@ TEST_F(registry_tests, sort_by_type_1)
{
using namespace cuke::internal;
cuke::registry().push_step(step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {},
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"another step"));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {},
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"a given step", step::type::given));

ASSERT_EQ(cuke::registry().steps().size(), 3);
Expand All @@ -109,31 +109,31 @@ TEST_F(registry_tests, sort_by_type_2)
{
using namespace cuke::internal;
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "a",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "b",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "b",
step::type::then));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "c",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "c",
step::type::given));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "d",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "d",
step::type::given));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "e",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "e",
step::type::then));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "f",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "f",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "g",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "g",
step::type::when));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "h",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "h",
step::type::step));
cuke::registry().push_step(
step([](const cuke::value_array&, const auto&, const auto&) {}, "i",
step([](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "i",
step::type::when));

ASSERT_EQ(cuke::registry().steps().size(), 9);
Expand Down
6 changes: 3 additions & 3 deletions gtest/run_scenario_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class run_scenario_hooks : public ::testing::Test
cuke::registry().push_hook_after_step(hook([]() { ++after_step_calls; }));

cuke::registry().push_step(step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
}

static std::size_t before_calls;
Expand Down Expand Up @@ -86,11 +86,11 @@ class run_scenario_hook_skip : public ::testing::Test
cuke::registry().clear();

cuke::registry().push_step(step(
[](const cuke::value_array&, const auto&, const auto&) { ++calls; },
[](const cuke::value_array&, const auto&, const auto&, const auto&) { ++calls; },
"a step"));

cuke::registry().push_step(step(
[](const cuke::value_array&, const auto&, const auto&) { ++calls; },
[](const cuke::value_array&, const auto&, const auto&, const auto&) { ++calls; },
"a step with {int}"));

cuke::registry().push_hook_before(
Expand Down
8 changes: 4 additions & 4 deletions gtest/run_scenarios.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class run_scenarios_1 : public ::testing::Test
call_count = 0;
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{ run_scenarios_1::call_count++; }, "a step"));
}

Expand Down Expand Up @@ -103,7 +103,7 @@ class run_scenarios_2 : public ::testing::Test
expected_string = "";
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&)
[](const cuke::value_array& values, const auto&, const auto&, const auto&)
{
run_scenarios_2::expected_int = values[0].as<unsigned int>();
run_scenarios_2::expected_string = values[1].as<std::string>();
Expand Down Expand Up @@ -159,7 +159,7 @@ class run_scenarios_3 : public ::testing::Test
call_count = 0;
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&)
[](const cuke::value_array& values, const auto&, const auto&, const auto&)
{ ++call_count; }, "a step with {int}"));
}
static std::size_t call_count;
Expand Down Expand Up @@ -200,7 +200,7 @@ class run_scenarios_4 : public ::testing::Test
anonymous_value = "";
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&)
[](const cuke::value_array& values, const auto&, const auto&, const auto&)
{
ASSERT_EQ(values.size(), 2);
word_value = values.at(0).as<std::string>();
Expand Down
4 changes: 2 additions & 2 deletions gtest/run_scenarios_tags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class run_scenarios_tags : public ::testing::Test
test_value = 0;
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{ run_scenarios_tags::call_count++; }, "a step"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&)
[](const cuke::value_array& values, const auto&, const auto&, const auto&)
{
run_scenarios_tags::test_value = values.at(0).as<std::size_t>();
run_scenarios_tags::call_count++;
Expand Down
6 changes: 3 additions & 3 deletions gtest/stdout_print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class stdout_print : public ::testing::Test
cuke::results::test_results().clear();
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {}, "a step"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{ cuke::is_true(false); }, "this fails"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array& values, const auto&, const auto&) {},
[](const cuke::value_array& values, const auto&, const auto&, const auto&) {},
"a step with {int} and {string}"));
}

Expand Down
5 changes: 3 additions & 2 deletions gtest/test_results.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class test_results_1 : public ::testing::Test
cuke::results::test_results().clear();
cuke::registry().clear();
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&) {}, "a step"));
[](const cuke::value_array&, const auto&, const auto&, const auto&) {},
"a step"));
cuke::registry().push_step(cuke::internal::step(
[](const cuke::value_array&, const auto&, const auto&)
[](const cuke::value_array&, const auto&, const auto&, const auto&)
{ cuke::is_true(false); }, "this fails"));
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define _STEP(function_name, step_definition, type) \
void function_name( \
[[maybe_unused]] const ::cuke::value_array& __cuke__values__, \
[[maybe_unused]] const std::vector<::cuke::internal::param_info>& \
__cuke__parameter_info__, \
[[maybe_unused]] const std::vector<std::string>& __cuke__doc__string__, \
[[maybe_unused]] const ::cuke::table& __cuke__table__); \
namespace \
Expand All @@ -25,6 +27,8 @@
} \
void function_name( \
[[maybe_unused]] const ::cuke::value_array& __cuke__values__, \
[[maybe_unused]] const std::vector<::cuke::internal::param_info>& \
__cuke__parameter_info__, \
[[maybe_unused]] const std::vector<std::string>& __cuke__doc__string__, \
[[maybe_unused]] const ::cuke::table& __cuke__table__)

Expand Down
Loading

0 comments on commit a4e5585

Please sign in to comment.