Skip to content

Commit a204309

Browse files
authored
Add global hooks, global attachments, hook types (#102)
1 parent 8b91a8d commit a204309

File tree

77 files changed

+2050
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2050
-112
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
### Added
10+
- Add new `TestRunHookStarted` and `TestRunHookFinished` messages ([#102](https://github.com/cucumber/messages/pull/102))
11+
12+
### Changed
13+
- BREAKING CHANGE: Add `id` property to `TestRunStarted`, optionally reference in `TestCase`, `Attachment` and `TestRunFinished` ([#102](https://github.com/cucumber/messages/pull/102))
14+
- BREAKING CHANGE: Add `type` property to `Hook` ([#102](https://github.com/cucumber/messages/pull/102))
915

1016
## [26.0.1] - 2024-09-22
1117
### Changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ schemas = \
1919
./jsonschema/TestRunFinished.json \
2020
./jsonschema/TestRunStarted.json \
2121
./jsonschema/Duration.json \
22+
./jsonschema/TestStepResult.json \
2223
./jsonschema/TestStepFinished.json \
2324
./jsonschema/TestStepStarted.json \
25+
./jsonschema/TestRunHookFinished.json \
26+
./jsonschema/TestRunHookStarted.json \
2427
./jsonschema/UndefinedParameterType.json \
2528
./jsonschema/Envelope.json
2629

cpp/include/messages/cucumber/messages/all.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <cucumber/messages/test_case_finished.hpp>
4848
#include <cucumber/messages/test_case_started.hpp>
4949
#include <cucumber/messages/test_run_finished.hpp>
50+
#include <cucumber/messages/test_run_hook_finished.hpp>
51+
#include <cucumber/messages/test_run_hook_started.hpp>
5052
#include <cucumber/messages/test_run_started.hpp>
5153
#include <cucumber/messages/test_step_finished.hpp>
5254
#include <cucumber/messages/test_step_result.hpp>

cpp/include/messages/cucumber/messages/attachment.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct attachment
4141
std::optional<std::string> test_case_started_id;
4242
std::optional<std::string> test_step_id;
4343
std::optional<std::string> url;
44+
std::optional<std::string> test_run_started_id;
4445

4546
std::string to_string() const;
4647

cpp/include/messages/cucumber/messages/envelope.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <cucumber/messages/test_run_started.hpp>
2323
#include <cucumber/messages/test_step_finished.hpp>
2424
#include <cucumber/messages/test_step_started.hpp>
25+
#include <cucumber/messages/test_run_hook_started.hpp>
26+
#include <cucumber/messages/test_run_hook_finished.hpp>
2527
#include <cucumber/messages/undefined_parameter_type.hpp>
2628

2729
namespace cucumber::messages {
@@ -59,6 +61,8 @@ struct envelope
5961
std::optional<cucumber::messages::test_run_started> test_run_started;
6062
std::optional<cucumber::messages::test_step_finished> test_step_finished;
6163
std::optional<cucumber::messages::test_step_started> test_step_started;
64+
std::optional<cucumber::messages::test_run_hook_started> test_run_hook_started;
65+
std::optional<cucumber::messages::test_run_hook_finished> test_run_hook_finished;
6266
std::optional<cucumber::messages::undefined_parameter_type> undefined_parameter_type;
6367

6468
std::string to_string() const;

cpp/include/messages/cucumber/messages/hook.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <nlohmann/json.hpp>
88

99
#include <cucumber/messages/source_reference.hpp>
10+
#include <cucumber/messages/hook_type.hpp>
1011

1112
namespace cucumber::messages {
1213

@@ -24,6 +25,7 @@ struct hook
2425
std::optional<std::string> name;
2526
cucumber::messages::source_reference source_reference;
2627
std::optional<std::string> tag_expression;
28+
std::optional<cucumber::messages::hook_type> type;
2729

2830
std::string to_string() const;
2931

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <string_view>
4+
5+
namespace cucumber::messages {
6+
7+
enum class hook_type
8+
{
9+
BEFORE_TEST_RUN,
10+
AFTER_TEST_RUN,
11+
BEFORE_TEST_CASE,
12+
AFTER_TEST_CASE,
13+
BEFORE_TEST_STEP,
14+
AFTER_TEST_STEP
15+
};
16+
17+
std::string_view
18+
to_string(hook_type v);
19+
20+
std::ostream&
21+
operator<<(std::ostream& os, hook_type v);
22+
23+
}

cpp/include/messages/cucumber/messages/test_case.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct test_case
2727
std::string id;
2828
std::string pickle_id;
2929
std::vector<cucumber::messages::test_step> test_steps;
30+
std::optional<std::string> test_run_started_id;
3031

3132
std::string to_string() const;
3233

cpp/include/messages/cucumber/messages/test_run_finished.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct test_run_finished
2525
bool success;
2626
cucumber::messages::timestamp timestamp;
2727
std::optional<cucumber::messages::exception> exception;
28+
std::optional<std::string> test_run_started_id;
2829

2930
std::string to_string() const;
3031

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <string>
5+
#include <optional>
6+
7+
#include <nlohmann/json.hpp>
8+
9+
#include <cucumber/messages/test_step_result.hpp>
10+
#include <cucumber/messages/timestamp.hpp>
11+
12+
namespace cucumber::messages {
13+
14+
using json = nlohmann::json;
15+
16+
//
17+
// Represents the TestRunHookFinished message in Cucumber's message protocol
18+
// @see <a href=https://github.com/cucumber/messages>Github - Cucumber - Messages</a>
19+
//
20+
// Generated code
21+
22+
struct test_run_hook_finished
23+
{
24+
std::string test_run_hook_started_id;
25+
cucumber::messages::test_step_result result;
26+
cucumber::messages::timestamp timestamp;
27+
28+
std::string to_string() const;
29+
30+
void to_json(json& j) const;
31+
std::string to_json() const;
32+
};
33+
34+
std::ostream&
35+
operator<<(std::ostream& os, const test_run_hook_finished& msg);
36+
37+
void to_json(json& j, const test_run_hook_finished& m);
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <string>
5+
#include <optional>
6+
7+
#include <nlohmann/json.hpp>
8+
9+
#include <cucumber/messages/timestamp.hpp>
10+
11+
namespace cucumber::messages {
12+
13+
using json = nlohmann::json;
14+
15+
//
16+
// Represents the TestRunHookStarted message in Cucumber's message protocol
17+
// @see <a href=https://github.com/cucumber/messages>Github - Cucumber - Messages</a>
18+
//
19+
// Generated code
20+
21+
struct test_run_hook_started
22+
{
23+
std::string id;
24+
std::string test_run_started_id;
25+
std::string hook_id;
26+
cucumber::messages::timestamp timestamp;
27+
28+
std::string to_string() const;
29+
30+
void to_json(json& j) const;
31+
std::string to_json() const;
32+
};
33+
34+
std::ostream&
35+
operator<<(std::ostream& os, const test_run_hook_started& msg);
36+
37+
void to_json(json& j, const test_run_hook_started& m);
38+
39+
}

cpp/include/messages/cucumber/messages/test_run_started.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using json = nlohmann::json;
2121
struct test_run_started
2222
{
2323
cucumber::messages::timestamp timestamp;
24+
std::optional<std::string> id;
2425

2526
std::string to_string() const;
2627

cpp/src/lib/messages/cucumber/messages/attachment.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ attachment::to_string() const
1818
cucumber::messages::to_string(oss, ", test_case_started_id=", test_case_started_id);
1919
cucumber::messages::to_string(oss, ", test_step_id=", test_step_id);
2020
cucumber::messages::to_string(oss, ", url=", url);
21+
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);
2122

2223
return oss.str();
2324
}
@@ -33,6 +34,7 @@ attachment::to_json(json& j) const
3334
cucumber::messages::to_json(j, camelize("test_case_started_id"), test_case_started_id);
3435
cucumber::messages::to_json(j, camelize("test_step_id"), test_step_id);
3536
cucumber::messages::to_json(j, camelize("url"), url);
37+
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
3638
}
3739

3840
std::string

cpp/src/lib/messages/cucumber/messages/envelope.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ envelope::to_string() const
2626
cucumber::messages::to_string(oss, ", test_run_started=", test_run_started);
2727
cucumber::messages::to_string(oss, ", test_step_finished=", test_step_finished);
2828
cucumber::messages::to_string(oss, ", test_step_started=", test_step_started);
29+
cucumber::messages::to_string(oss, ", test_run_hook_started=", test_run_hook_started);
30+
cucumber::messages::to_string(oss, ", test_run_hook_finished=", test_run_hook_finished);
2931
cucumber::messages::to_string(oss, ", undefined_parameter_type=", undefined_parameter_type);
3032

3133
return oss.str();
@@ -50,6 +52,8 @@ envelope::to_json(json& j) const
5052
cucumber::messages::to_json(j, camelize("test_run_started"), test_run_started);
5153
cucumber::messages::to_json(j, camelize("test_step_finished"), test_step_finished);
5254
cucumber::messages::to_json(j, camelize("test_step_started"), test_step_started);
55+
cucumber::messages::to_json(j, camelize("test_run_hook_started"), test_run_hook_started);
56+
cucumber::messages::to_json(j, camelize("test_run_hook_finished"), test_run_hook_finished);
5357
cucumber::messages::to_json(j, camelize("undefined_parameter_type"), undefined_parameter_type);
5458
}
5559

cpp/src/lib/messages/cucumber/messages/hook.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ hook::to_string() const
1414
cucumber::messages::to_string(oss, ", name=", name);
1515
cucumber::messages::to_string(oss, ", source_reference=", source_reference);
1616
cucumber::messages::to_string(oss, ", tag_expression=", tag_expression);
17+
cucumber::messages::to_string(oss, ", type=", type);
1718

1819
return oss.str();
1920
}
@@ -25,6 +26,7 @@ hook::to_json(json& j) const
2526
cucumber::messages::to_json(j, camelize("name"), name);
2627
cucumber::messages::to_json(j, camelize("source_reference"), source_reference);
2728
cucumber::messages::to_json(j, camelize("tag_expression"), tag_expression);
29+
cucumber::messages::to_json(j, camelize("type"), type);
2830
}
2931

3032
std::string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <unordered_map>
3+
4+
#include <cucumber/messages/hook_type.hpp>
5+
6+
namespace cucumber::messages {
7+
8+
std::string_view
9+
to_string(hook_type v)
10+
{
11+
using map_type = std::unordered_map<hook_type, std::string_view>;
12+
13+
static const map_type m = {
14+
{ hook_type::BEFORE_TEST_RUN, "BEFORE_TEST_RUN" },
15+
{ hook_type::AFTER_TEST_RUN, "AFTER_TEST_RUN" },
16+
{ hook_type::BEFORE_TEST_CASE, "BEFORE_TEST_CASE" },
17+
{ hook_type::AFTER_TEST_CASE, "AFTER_TEST_CASE" },
18+
{ hook_type::BEFORE_TEST_STEP, "BEFORE_TEST_STEP" },
19+
{ hook_type::AFTER_TEST_STEP, "AFTER_TEST_STEP" }
20+
};
21+
22+
return m.at(v);
23+
}
24+
25+
std::ostream&
26+
operator<<(std::ostream& os, hook_type v)
27+
{
28+
os << to_string(v);
29+
30+
return os;
31+
}
32+
33+
}

cpp/src/lib/messages/cucumber/messages/test_case.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test_case::to_string() const
1313
cucumber::messages::to_string(oss, "id=", id);
1414
cucumber::messages::to_string(oss, ", pickle_id=", pickle_id);
1515
cucumber::messages::to_string(oss, ", test_steps=", test_steps);
16+
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);
1617

1718
return oss.str();
1819
}
@@ -23,6 +24,7 @@ test_case::to_json(json& j) const
2324
cucumber::messages::to_json(j, camelize("id"), id);
2425
cucumber::messages::to_json(j, camelize("pickle_id"), pickle_id);
2526
cucumber::messages::to_json(j, camelize("test_steps"), test_steps);
27+
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
2628
}
2729

2830
std::string

cpp/src/lib/messages/cucumber/messages/test_run_finished.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test_run_finished::to_string() const
1414
cucumber::messages::to_string(oss, ", success=", success);
1515
cucumber::messages::to_string(oss, ", timestamp=", timestamp);
1616
cucumber::messages::to_string(oss, ", exception=", exception);
17+
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);
1718

1819
return oss.str();
1920
}
@@ -25,6 +26,7 @@ test_run_finished::to_json(json& j) const
2526
cucumber::messages::to_json(j, camelize("success"), success);
2627
cucumber::messages::to_json(j, camelize("timestamp"), timestamp);
2728
cucumber::messages::to_json(j, camelize("exception"), exception);
29+
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
2830
}
2931

3032
std::string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <sstream>
2+
3+
#include <cucumber/messages/utils.hpp>
4+
#include <cucumber/messages/test_run_hook_finished.hpp>
5+
6+
namespace cucumber::messages {
7+
8+
std::string
9+
test_run_hook_finished::to_string() const
10+
{
11+
std::ostringstream oss;
12+
13+
cucumber::messages::to_string(oss, "test_run_hook_started_id=", test_run_hook_started_id);
14+
cucumber::messages::to_string(oss, ", result=", result);
15+
cucumber::messages::to_string(oss, ", timestamp=", timestamp);
16+
17+
return oss.str();
18+
}
19+
20+
void
21+
test_run_hook_finished::to_json(json& j) const
22+
{
23+
cucumber::messages::to_json(j, camelize("test_run_hook_started_id"), test_run_hook_started_id);
24+
cucumber::messages::to_json(j, camelize("result"), result);
25+
cucumber::messages::to_json(j, camelize("timestamp"), timestamp);
26+
}
27+
28+
std::string
29+
test_run_hook_finished::to_json() const
30+
{
31+
std::ostringstream oss;
32+
json j;
33+
34+
to_json(j);
35+
36+
oss << j;
37+
38+
return oss.str();
39+
}
40+
41+
std::ostream&
42+
operator<<(std::ostream& os, const test_run_hook_finished& msg)
43+
{
44+
os << msg.to_string();
45+
46+
return os;
47+
}
48+
49+
void to_json(json& j, const test_run_hook_finished& m)
50+
{ m.to_json(j); }
51+
52+
}

0 commit comments

Comments
 (0)