@@ -17,14 +17,6 @@ namespace cuke
1717
1818namespace
1919{
20- void verbose_start (const ast::scenario_node& scenario)
21- {
22- log::verbose (" [ VERBOSE ] ----------------------------------" ,
23- log::new_line);
24- log::verbose (std::format (" [ VERBOSE ] Scenario Start '{}' - File: {}:{}" ,
25- scenario.name (), scenario.file (), scenario.line ()),
26- log::new_line);
27- }
2820void verbose_end ()
2921{
3022 log::verbose (" [ VERBOSE ] Scenario end" , log::new_line);
@@ -59,16 +51,18 @@ void verbose_ignore()
5951 log::new_line);
6052}
6153
62- [[nodiscard]] bool tags_valid (const ast::scenario_node& scenario,
63- const internal::tag_expression& tag_expression)
54+ [[nodiscard]] bool tags_valid (const scenario_pipeline_context& context)
6455{
65- if (tag_expression.empty ())
56+ if (context. tag_expression .empty ())
6657 {
6758 verbose_no_tags ();
6859 return true ;
6960 }
70- bool tag_evaluation = tag_expression.evaluate (scenario.tags ());
71- verbose_evaluate_tags (scenario, tag_evaluation, tag_expression.expression ());
61+ bool tag_evaluation =
62+ context.tag_expression .evaluate (context.scenario .tags ());
63+
64+ verbose_evaluate_tags (context.scenario , tag_evaluation,
65+ context.tag_expression .expression ());
7266
7367 return tag_evaluation;
7468}
@@ -156,54 +150,61 @@ void log_helper(const cuke::ast::step_node& step, results::test_status status)
156150 return false ;
157151}
158152
159- void update_scenario_status (std::string_view name, std::string_view file,
160- std::size_t line, bool skipped)
153+ [[nodiscard]] bool has_undefined_steps (const std::vector<results::step>& steps)
161154{
162- const auto & steps = results::scenarios_back ().steps ;
155+ return std::any_of (
156+ steps.begin (), steps.end (), [](const auto & step)
157+ { return step.status == results::test_status::undefined; });
158+ }
163159
164- if (skipped)
160+ [[nodiscard]] bool has_failed_or_undefined_steps (
161+ const std::vector<results::step>& steps)
162+ {
163+ return std::any_of (steps.begin (), steps.end (),
164+ [](const auto & step)
165+ {
166+ return step.status == results::test_status::failed ||
167+ step.status == results::test_status::undefined;
168+ });
169+ }
170+
171+ void update_scenario_status (scenario_pipeline_context& context)
172+ {
173+ const auto & steps = results::scenarios_back ().steps ;
174+ if (context.skip_scenario )
165175 {
166176#ifdef UNDEFINED_STEPS_ARE_A_FAILURE
167- if (std::any_of (steps.begin (), steps.end (), [](const auto & step)
168- { return step.status == results::test_status::undefined; }))
177+ if (has_undefined_steps (steps))
169178 {
170- results::scenarios_back () .status = results::test_status::failed;
179+ context. result .status = results::test_status::failed;
171180 }
172181 else
173182#endif // UNDEFINED_STEPS_ARE_A_FAILURE
174- results::scenarios_back () .status = results::test_status::skipped;
183+ context. result .status = results::test_status::skipped;
175184 }
176185 else if (internal::get_runtime_options ().fail_scenario ().is_set )
177186 {
178187 const std::string& msg =
179188 internal::get_runtime_options ().fail_scenario ().msg ;
180189 log::error (msg, log::new_line);
181- results::scenarios_back ().status = results::test_status::failed;
182- std::for_each (results::scenarios_back ().steps .begin (),
183- results::scenarios_back ().steps .end (),
184- [&msg](results::step& step) { step.error_msg = msg; });
190+ context.result .status = results::test_status::failed;
191+ for (results::step& step : context.result .steps )
192+ {
193+ step.error_msg = msg;
194+ }
185195 }
186196 else
187197 {
188- if (std::any_of (steps.begin (), steps.end (),
189- [](const auto & step)
190- {
191- return step.status == results::test_status::failed ||
192- step.status == results::test_status::undefined;
193- }))
198+ if (has_failed_or_undefined_steps (steps))
194199 {
195- {
196- results::scenarios_back ().status = results::test_status::failed;
197- }
200+ context.result .status = results::test_status::failed;
198201 }
199202 }
200203
201204 internal::get_runtime_options ().reset_fail_scenario ();
202- results::test_results ().add_scenario (results::scenarios_back () .status );
205+ results::test_results ().add_scenario (context. result .status );
203206}
204207
205- } // namespace
206-
207208void skip_step (step_pipeline_context& context)
208209{
209210 const bool continue_on_failure_or_prev_step_failed = []()
@@ -308,39 +309,40 @@ void run_step(const ast::step_node& step, bool scenario_already_skpped)
308309 }
309310}
310311
311- void setup_scenario (scenario_pipeline_context& context)
312+ void verbose_start_print (scenario_pipeline_context& context)
312313{
313- verbose_start (context.scenario );
314+ log::verbose (" [ VERBOSE ] ----------------------------------" ,
315+ log::new_line);
316+ log::verbose (std::format (" [ VERBOSE ] Scenario Start '{}' - File: {}:{}" ,
317+ context.scenario .name (), context.scenario .file (),
318+ context.scenario .line ()),
319+ log::new_line);
314320}
315321void hook_before_scenario (scenario_pipeline_context& context)
316322{
317323 cuke::registry ().run_hook_before (context.scenario .tags ());
318324}
319325void is_scenario_ignored (scenario_pipeline_context& context)
320326{
321- if (ignore_flag () || !tags_valid (context. scenario , context. tag_expression ))
327+ if (ignore_flag () || !tags_valid (context))
322328 {
323329 verbose_ignore ();
324330 verbose_end ();
325331 internal::get_runtime_options ().skip_scenario (false );
326332 context.ignore = true ;
333+ results::remove_last_scenario ();
327334 }
328335}
329336void is_scenario_skipped (scenario_pipeline_context& context)
330337{
331338 context.skip_scenario =
332339 skip_flag () || program_arguments ().get_options ().dry_run ;
333- }
334- void init_scenario (scenario_pipeline_context& context)
335- {
336- results::new_scenario (context.scenario );
337340
338341 if (context.skip_scenario )
339342 {
340343 verbose_skip ();
341- results::scenarios_back () .status = results::test_status::skipped;
344+ context. result .status = results::test_status::skipped;
342345 }
343-
344346 log_helper (context.scenario );
345347}
346348void run_background (scenario_pipeline_context& context)
@@ -368,30 +370,33 @@ void hook_after_scenario(scenario_pipeline_context& context)
368370 cuke::registry ().run_hook_after (context.scenario .tags ());
369371 }
370372}
371- void teardown_scenario (scenario_pipeline_context& context )
373+ void reset_user_context (scenario_pipeline_context&)
372374{
373- update_scenario_status (context.scenario .name (), context.scenario .file (),
374- context.scenario .line (), context.skip_scenario );
375375 cuke::internal::reset_context ();
376-
376+ }
377+ void verbose_end_print (scenario_pipeline_context& context)
378+ {
377379 verbose_end ();
378380 log::info (log::new_line);
379381}
380382
381383// clang-format off
382384std::vector<void (*)(scenario_pipeline_context&)> scenario_pipeline = {
383- setup_scenario ,
385+ verbose_start_print ,
384386 hook_before_scenario,
385387 is_scenario_ignored,
386388 is_scenario_skipped,
387- init_scenario,
388389 run_background,
389- run_all_steps,
390- hook_after_scenario,
391- teardown_scenario
390+ run_all_steps,
391+ hook_after_scenario,
392+ update_scenario_status,
393+ reset_user_context,
394+ verbose_end_print
392395};
393396// clang-format on
394397
398+ } // namespace
399+
395400void test_runner::setup () const { cuke::registry ().run_hook_before_all (); }
396401void test_runner::teardown () const { cuke::registry ().run_hook_after_all (); }
397402void test_runner::run () const
@@ -440,7 +445,8 @@ void test_runner::visit(
440445void test_runner::run_scenario (const ast::scenario_node& scenario) const
441446{
442447 scenario_pipeline_context context{.scenario = scenario,
443- .tag_expression = m_tag_expression};
448+ .tag_expression = m_tag_expression,
449+ .result = results::new_scenario (scenario)};
444450 for (const auto & pipeline_step : scenario_pipeline)
445451 {
446452 pipeline_step (context);
0 commit comments