Skip to content

Commit ed322ee

Browse files
committed
updated test results
1 parent 7384b8f commit ed322ee

File tree

6 files changed

+103
-42
lines changed

6 files changed

+103
-42
lines changed

src/asserts.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99

1010
namespace cuke::internal
1111
{
12+
1213
inline void internal_assert(bool condition, std::string_view error_msg)
1314
{
1415
if (condition == false)
1516
{
1617
cuke::results::set_step_to(cuke::results::test_status::failed);
18+
cuke::results::steps_back().error_msg = error_msg;
1719
if (!program_arguments().get_options().quiet)
1820
{
1921
println(color::red, error_msg);
2022
}
2123
}
2224
}
25+
2326
} // namespace cuke::internal
2427

2528
namespace cuke

src/get_args.hpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <type_traits>
77

88
#include "param_info.hpp"
9+
#include "util.hpp"
910
#include "value.hpp"
1011
#include "registry.hpp"
1112

@@ -61,17 +62,7 @@ class string_or_vector
6162

6263
operator std::string() const
6364
{
64-
std::ostringstream oss;
65-
for (const auto& str : m_data)
66-
{
67-
oss << str << ' ';
68-
}
69-
std::string result = oss.str();
70-
if (!result.empty())
71-
{
72-
result.pop_back();
73-
}
74-
return result;
65+
return to_string(m_data);
7566
}
7667

7768
operator std::vector<std::string>() const { return m_data; }

src/test_results.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "test_results.hpp"
2+
#include "ast.hpp"
23
#include "util.hpp"
34

45
namespace cuke::results
@@ -263,4 +264,68 @@ std::string step_prefix(test_status status)
263264
}
264265
}
265266

267+
void new_feature(const cuke::ast::feature_node& current)
268+
{
269+
feature result;
270+
result.id = current.name();
271+
result.uri = std::format("{}:{}", current.file(), current.line());
272+
result.tags = current.tags();
273+
result.keyword = current.keyword();
274+
test_results().data().push_back(result);
275+
}
276+
void new_scenario(const cuke::ast::scenario_node& current)
277+
{
278+
scenario result;
279+
result.id = std::format("{};{}", test_results().back().id, current.name());
280+
result.line = current.line();
281+
result.file = current.file();
282+
result.name = current.name();
283+
result.keyword = current.keyword();
284+
result.tags = current.tags();
285+
test_results().back().scenarios.push_back(result);
286+
}
287+
void new_scenario_outline(const cuke::ast::scenario_outline_node& current)
288+
{
289+
scenario result;
290+
result.id = std::format("{};{}", test_results().back().id, current.name());
291+
result.line = current.line();
292+
result.file = current.file();
293+
result.name = current.name();
294+
result.keyword = current.keyword();
295+
result.tags = current.tags();
296+
test_results().back().scenarios.push_back(result);
297+
}
298+
void new_step(const cuke::ast::step_node& current)
299+
{
300+
step result;
301+
result.line = current.line();
302+
result.id = std::format("{};{}", test_results().back().scenarios.back().id,
303+
current.name());
304+
result.name = current.name();
305+
result.file = current.file();
306+
result.keyword = current.keyword();
307+
result.doc_string = cuke::internal::to_string(current.doc_string());
308+
result.table = current.data_table();
309+
310+
test_results().back().scenarios.back().steps.emplace_back();
311+
}
312+
313+
void set_source_location(const std::string& location)
314+
{
315+
test_results().back().scenarios.back().steps.back().source_location =
316+
location;
317+
}
318+
319+
void set_feature_to(test_status status)
320+
{
321+
test_results().back().status = status;
322+
}
323+
void set_scenario_to(test_status status)
324+
{
325+
test_results().back().scenarios.back().status = status;
326+
}
327+
void set_step_to(test_status status)
328+
{
329+
test_results().back().scenarios.back().steps.back().status = status;
330+
}
266331
} // namespace cuke::results

src/test_results.hpp

+12-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include <memory>
43
#include <vector>
54
#include <string>
65

6+
#include "ast.hpp"
77
#include "util.hpp"
88
#include "table.hpp"
99

@@ -27,6 +27,7 @@ struct step
2727
std::string keyword;
2828
std::string source_location;
2929
std::string doc_string;
30+
std::string error_msg;
3031
cuke::table table;
3132
};
3233
struct scenario
@@ -38,7 +39,7 @@ struct scenario
3839
std::string file;
3940
std::string keyword;
4041
std::vector<step> steps{};
41-
std::vector<std::pair<std::string, std::size_t>> tags;
42+
std::vector<std::string> tags;
4243
};
4344
struct feature
4445
{
@@ -47,7 +48,7 @@ struct feature
4748
std::string keyword;
4849
std::string name;
4950
std::string uri;
50-
std::vector<std::pair<std::string, std::size_t>> tags;
51+
std::vector<std::string> tags;
5152
std::vector<scenario> scenarios{};
5253
};
5354

@@ -104,29 +105,14 @@ class test_result
104105
return test_status::failed;
105106
}
106107

107-
static void new_feature() { test_results().data().emplace_back(); }
108-
static void new_scenario() { test_results().back().scenarios.emplace_back(); }
109-
static void new_scenario_outline()
110-
{
111-
test_results().back().scenarios.emplace_back();
112-
}
113-
static void new_step()
114-
{
115-
test_results().back().scenarios.back().steps.emplace_back();
116-
}
117-
118-
static void set_feature_to(test_status status)
119-
{
120-
test_results().back().status = status;
121-
}
122-
static void set_scenario_to(test_status status)
123-
{
124-
test_results().back().scenarios.back().status = status;
125-
}
126-
static void set_step_to(test_status status)
127-
{
128-
test_results().back().scenarios.back().steps.back().status = status;
129-
}
108+
void new_feature(const cuke::ast::feature_node& current);
109+
void new_scenario(const cuke::ast::scenario_node& current);
110+
void new_scenario_outline(const cuke::ast::scenario_outline_node& current);
111+
void new_step(const cuke::ast::step_node& current);
112+
void set_source_location(const std::string& location);
113+
void set_feature_to(test_status status);
114+
void set_scenario_to(test_status status);
115+
void set_step_to(test_status status);
130116

131117
[[nodiscard]] static feature& features_back() { return test_results().back(); }
132118
[[nodiscard]] static scenario& scenarios_back()

src/test_runner.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ static void execute_step(cuke::ast::step_node step, OptionalRow&&... row)
8484
{
8585
if (skip_step())
8686
{
87-
results::new_step();
87+
results::new_step(step);
8888
results::steps_back().status = results::test_status::skipped;
8989
update_step_status();
9090
return;
9191
}
92-
results::new_step();
92+
results::new_step(step);
9393
cuke::internal::step_finder finder(step.name(),
9494
std::forward<OptionalRow>(row)...);
9595
auto it = finder.find(cuke::registry().steps().begin(),
9696
cuke::registry().steps().end());
9797
if (it != cuke::registry().steps().end())
9898
{
99+
results::set_source_location(it->source_location());
99100
cuke::registry().run_hook_before_step();
100101
it->call(finder.values(), step.doc_string(), step.data_table());
101102
cuke::registry().run_hook_after_step();
@@ -244,7 +245,7 @@ class test_runner
244245
void visit(const cuke::ast::feature_node& feature)
245246
{
246247
push_tags(feature.tags());
247-
results::new_feature();
248+
results::new_feature(feature);
248249
m_printer->print(feature);
249250
if (feature.has_background())
250251
{
@@ -255,7 +256,7 @@ class test_runner
255256
{
256257
push_tags(scenario.tags());
257258
cuke::registry().run_hook_before(m_tags.container);
258-
results::new_scenario();
259+
results::new_scenario(scenario);
259260
if (skip_scenario(m_lines, scenario.line()) || !tags_valid())
260261
{
261262
results::scenarios_back().status = results::test_status::skipped;
@@ -288,7 +289,7 @@ class test_runner
288289
}
289290
for (std::size_t row = 1; row < example.table().row_count(); ++row)
290291
{
291-
results::new_scenario();
292+
results::new_scenario_outline(scenario_outline);
292293
std::size_t row_file_line = example.line_table_begin() + row;
293294
cuke::registry().run_hook_before(m_tags.container);
294295
if (skip_scenario(m_lines, row_file_line))

src/util.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
namespace cuke::internal
1212
{
1313

14+
[[nodiscard]] static std::string to_string(const std::vector<std::string>& data)
15+
{
16+
std::ostringstream oss;
17+
for (const auto& str : data)
18+
{
19+
oss << str << ' ';
20+
}
21+
std::string result = oss.str();
22+
if (!result.empty())
23+
{
24+
result.pop_back();
25+
}
26+
return result;
27+
}
28+
1429
enum class color
1530
{
1631
standard,

0 commit comments

Comments
 (0)