diff --git a/gtest/catalog.cc b/gtest/catalog.cc index 3edc821..39ab3ac 100644 --- a/gtest/catalog.cc +++ b/gtest/catalog.cc @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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}", diff --git a/gtest/file_io.cc b/gtest/file_io.cc index 2965d18..ec4e5d3 100644 --- a/gtest/file_io.cc +++ b/gtest/file_io.cc @@ -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 diff --git a/gtest/hooks.cc b/gtest/hooks.cc index 67445b4..60aa1ea 100644 --- a/gtest/hooks.cc +++ b/gtest/hooks.cc @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/gtest/registry.cc b/gtest/registry.cc index 5b572aa..4588d3f 100644 --- a/gtest/registry.cc +++ b/gtest/registry.cc @@ -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); } @@ -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); @@ -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); @@ -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); diff --git a/gtest/run_scenario_hooks.cc b/gtest/run_scenario_hooks.cc index 8679cd6..e69fcfb 100644 --- a/gtest/run_scenario_hooks.cc +++ b/gtest/run_scenario_hooks.cc @@ -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; @@ -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( diff --git a/gtest/run_scenarios.cc b/gtest/run_scenarios.cc index 7a3470f..9d603f9 100644 --- a/gtest/run_scenarios.cc +++ b/gtest/run_scenarios.cc @@ -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")); } @@ -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(); run_scenarios_2::expected_string = values[1].as(); @@ -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; @@ -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(); diff --git a/gtest/run_scenarios_tags.cc b/gtest/run_scenarios_tags.cc index 4eb9e3e..db7176b 100644 --- a/gtest/run_scenarios_tags.cc +++ b/gtest/run_scenarios_tags.cc @@ -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(); run_scenarios_tags::call_count++; diff --git a/gtest/stdout_print.cc b/gtest/stdout_print.cc index bab3978..7d5fe41 100644 --- a/gtest/stdout_print.cc +++ b/gtest/stdout_print.cc @@ -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}")); } diff --git a/gtest/test_results.cc b/gtest/test_results.cc index ef3f03f..97d0cce 100644 --- a/gtest/test_results.cc +++ b/gtest/test_results.cc @@ -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")); } }; diff --git a/src/defines.hpp b/src/defines.hpp index 05ac899..2d4867d 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -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& __cuke__doc__string__, \ [[maybe_unused]] const ::cuke::table& __cuke__table__); \ namespace \ @@ -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& __cuke__doc__string__, \ [[maybe_unused]] const ::cuke::table& __cuke__table__) diff --git a/src/get_args.hpp b/src/get_args.hpp index 3413e7c..3213616 100644 --- a/src/get_args.hpp +++ b/src/get_args.hpp @@ -1,5 +1,6 @@ #pragma once +#include "param_info.hpp" #include "value.hpp" namespace cuke::internal @@ -59,13 +60,15 @@ inline conversion get_arg(const cuke::value_array::iterator begin, } } -inline conversion get_arg(const cuke::value_array& values, std::size_t idx, - std::string_view file, std::size_t line) +inline conversion get_arg(const cuke::value_array& values, + const std::vector& parameter, + std::size_t idx, std::string_view file, + std::size_t line) { std::size_t zero_based_idx = idx - 1; if (zero_based_idx < values.max_size()) { - return conversion(values[zero_based_idx]); + return conversion(values[zero_based_idx + parameter[idx].offset]); } else { @@ -167,8 +170,9 @@ class string_or_vector * @return The value from the index in the given step */ -#define CUKE_ARG(index) \ - cuke::internal::get_arg(__cuke__values__, index, __FILE__, __LINE__) +#define CUKE_ARG(index) \ + cuke::internal::get_arg(__cuke__values__, __cuke__parameter_info__, index, \ + __FILE__, __LINE__) /** * @def CUKE_DOC_STRING() diff --git a/src/value.hpp b/src/value.hpp index ed3f1bf..ac38de8 100644 --- a/src/value.hpp +++ b/src/value.hpp @@ -121,6 +121,7 @@ namespace cuke::internal { using step_callback = void (*)(const cuke::value_array& args, + const std::vector& info, const std::vector& doc_string, const cuke::table& t); class step @@ -157,7 +158,7 @@ class step void call(const value_array& values, const std::vector& doc_string, const table& t) const { - m_callback(values, doc_string, t); + m_callback(values, m_type_info, doc_string, t); } type step_type() const noexcept { return m_type; }