22#include " ast.hpp"
33#include " log.hpp"
44#include " util.hpp"
5- #include " util_regex.hpp"
65
76namespace cuke ::results
87{
@@ -117,10 +116,10 @@ std::string scenarios_to_string()
117116 bool add_comma = false ;
118117 if (results::test_results ().scenarios_failed () > 0 )
119118 {
120- if ( log::colors_enabled ()) str.append (log::red);
119+ str.append (log::color:: red () );
121120 str.append (std::to_string (results::test_results ().scenarios_failed ()));
122121 str.append (" failed" );
123- if ( log::colors_enabled ()) str.append (log::reset_color );
122+ str.append (log::color::reset () );
124123 add_comma = true ;
125124 }
126125
@@ -130,10 +129,10 @@ std::string scenarios_to_string()
130129 {
131130 str.append (" , " );
132131 }
133- if ( log::colors_enabled ()) str.append (log::blue);
132+ str.append (log::color:: blue () );
134133 str.append (std::to_string (results::test_results ().scenarios_skipped ()));
135134 str.append (" skipped" );
136- if ( log::colors_enabled ()) str.append (log::reset_color );
135+ str.append (log::color::reset () );
137136 add_comma = true ;
138137 }
139138
@@ -143,10 +142,10 @@ std::string scenarios_to_string()
143142 {
144143 str.append (" , " );
145144 }
146- if ( log::colors_enabled ()) str.append (log::green);
145+ str.append (log::color:: green () );
147146 str.append (std::to_string (results::test_results ().scenarios_passed ()));
148147 str.append (" passed" );
149- if ( log::colors_enabled ()) str.append (log::reset_color );
148+ str.append (log::color::reset () );
150149 }
151150
152151 str += ' )' ;
@@ -166,10 +165,10 @@ std::string steps_to_string()
166165 bool add_comma = false ;
167166 if (results::test_results ().steps_failed () > 0 )
168167 {
169- if ( log::colors_enabled ()) str.append (log::red);
168+ str.append (log::color:: red () );
170169 str.append (std::to_string (results::test_results ().steps_failed ()));
171170 str.append (" failed" );
172- if ( log::colors_enabled ()) str.append (log::reset_color );
171+ str.append (log::color::reset () );
173172 add_comma = true ;
174173 }
175174
@@ -179,10 +178,10 @@ std::string steps_to_string()
179178 {
180179 str.append (" , " );
181180 }
182- if ( log::colors_enabled ()) str.append (log::yellow);
181+ str.append (log::color:: yellow () );
183182 str.append (std::to_string (results::test_results ().steps_undefined ()));
184183 str.append (" undefined" );
185- if ( log::colors_enabled ()) str.append (log::reset_color );
184+ str.append (log::color::reset () );
186185 add_comma = true ;
187186 }
188187
@@ -192,10 +191,10 @@ std::string steps_to_string()
192191 {
193192 str.append (" , " );
194193 }
195- if ( log::colors_enabled ()) str.append (log::blue);
194+ str.append (log::color:: blue () );
196195 str.append (std::to_string (results::test_results ().steps_skipped ()));
197196 str.append (" skipped" );
198- if ( log::colors_enabled ()) str.append (log::reset_color );
197+ str.append (log::color::reset () );
199198 add_comma = true ;
200199 }
201200
@@ -205,10 +204,10 @@ std::string steps_to_string()
205204 {
206205 str.append (" , " );
207206 }
208- if ( log::colors_enabled ()) str.append (log::green);
207+ str.append (log::color:: green () );
209208 str.append (std::to_string (results::test_results ().steps_passed ()));
210209 str.append (" passed" );
211- if ( log::colors_enabled ()) str.append (log::reset_color );
210+ str.append (log::color::reset () );
212211 }
213212
214213 str += ' )' ;
@@ -220,15 +219,15 @@ const char* to_color(test_status status)
220219 switch (status)
221220 {
222221 case cuke::results::test_status::passed:
223- return log::green;
222+ return log::color:: green () ;
224223 case cuke::results::test_status::failed:
225- return log::red;
224+ return log::color:: red () ;
226225 case cuke::results::test_status::skipped:
227- return log::blue;
226+ return log::color:: blue () ;
228227 case cuke::results::test_status::undefined:
229- return log::yellow;
228+ return log::color:: yellow () ;
230229 default :
231- return log::reset_color ;
230+ return log::color::reset () ;
232231 }
233232}
234233std::string to_string (test_status status)
@@ -277,7 +276,7 @@ void new_feature(const cuke::ast::feature_node& current)
277276 result.description = cuke::internal::to_string (current.description ());
278277 test_results ().data ().push_back (result);
279278}
280- void new_scenario (const cuke::ast::scenario_node& current)
279+ scenario& new_scenario (const cuke::ast::scenario_node& current)
281280{
282281 scenario result;
283282 result.id = current.id ();
@@ -287,8 +286,10 @@ void new_scenario(const cuke::ast::scenario_node& current)
287286 result.keyword = current.keyword ();
288287 result.tags = current.tags ();
289288 test_results ().back ().scenarios .push_back (result);
289+ return test_results ().back ().scenarios .back ();
290290}
291- void new_step (const cuke::ast::step_node& current)
291+ void remove_last_scenario () { test_results ().back ().scenarios .pop_back (); }
292+ step& new_step (const cuke::ast::step_node& current)
292293{
293294 step result;
294295 result.line = current.line ();
@@ -300,19 +301,32 @@ void new_step(const cuke::ast::step_node& current)
300301 result.table = current.data_table ();
301302
302303 test_results ().back ().scenarios .back ().steps .push_back (result);
304+ return test_results ().back ().scenarios .back ().steps .back ();
303305}
304306
305- void set_source_location ( const std::string& location )
307+ test_status final_result ( )
306308{
307- test_results ().back ().scenarios .back ().steps .back ().source_location =
308- location;
309- }
310- void set_scenario_to (test_status status)
311- {
312- test_results ().back ().scenarios .back ().status = status;
309+ if (test_results ().data ().empty ())
310+ {
311+ return test_status::passed;
312+ }
313+
314+ if (test_results ().scenarios_failed () == 0 )
315+ {
316+ return test_status::passed;
317+ }
318+ return test_status::failed;
313319}
320+
314321void set_step_to (test_status status)
315322{
316323 test_results ().back ().scenarios .back ().steps .back ().status = status;
317324}
325+
326+ feature& features_back () { return test_results ().back (); }
327+ scenario& scenarios_back () { return test_results ().back ().scenarios .back (); }
328+ step& steps_back ()
329+ {
330+ return test_results ().back ().scenarios .back ().steps .back ();
331+ }
318332} // namespace cuke::results
0 commit comments