Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global hooks, global attachments, hook types #102

Merged
merged 25 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd5bc7c
add and extend schema definitions
davidjgoss Aug 2, 2024
017d451
update CHANGELOG.md
davidjgoss Aug 2, 2024
773087f
regenerate code
davidjgoss Aug 2, 2024
127809b
fix the java tests
davidjgoss Aug 3, 2024
1222bd8
fix: update dotnet ctor
davidjgoss Aug 4, 2024
745ac05
Merge branch 'main' into feat/global-hooks
davidjgoss Aug 4, 2024
f1c5520
fix: update dotnet ctor
davidjgoss Aug 4, 2024
d19c1f8
fix: remove defunct test
davidjgoss Aug 4, 2024
42a9d82
Merge branch 'main' into feat/global-hooks
davidjgoss Aug 22, 2024
a3bc6bd
chore: regenerate code for comments
davidjgoss Aug 22, 2024
4228da4
add unique identifier per hook run
davidjgoss Aug 22, 2024
521bb63
recast as TestRunHook(Started|Finished)
davidjgoss Sep 20, 2024
7392334
Merge branch 'main' into feat/global-hooks
davidjgoss Sep 20, 2024
3fd35b9
fix bad merge on CHANGELOG.md
davidjgoss Sep 20, 2024
ffe2924
remove errant cpp files
davidjgoss Sep 20, 2024
f7ca9f4
add type enum to Hook
davidjgoss Sep 20, 2024
596184d
update CHANGELOG.md
davidjgoss Sep 20, 2024
c23af44
dont do testRunStartedId on TestCase, yet
davidjgoss Sep 22, 2024
1f37341
rework CHANGELOG.md headings
davidjgoss Sep 22, 2024
a5ee40d
Merge branch 'main' into feat/global-hooks
davidjgoss Sep 22, 2024
9e21688
Merge branch 'main' into feat/global-hooks
davidjgoss Sep 24, 2024
57d3df7
add testRunStartedId to TestCase
davidjgoss Oct 15, 2024
edcd5d7
Merge branch 'main' into feat/global-hooks
davidjgoss Oct 15, 2024
9434e5c
Merge branch 'main' into feat/global-hooks
davidjgoss Oct 26, 2024
d29111e
update CHANGELOG.md
davidjgoss Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add new `TestRunHookStarted` and `TestRunHookFinished` messages ([#102](https://github.com/cucumber/messages/pull/102))

### Changed
- BREAKING CHANGE: Add `id` property to `TestRunStarted`, optionally reference in `TestCase`, `Attachment` and `TestRunFinished` ([#102](https://github.com/cucumber/messages/pull/102))
- BREAKING CHANGE: Add `type` property to `Hook` ([#102](https://github.com/cucumber/messages/pull/102))

## [26.0.1] - 2024-09-22
### Changed
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ schemas = \
./jsonschema/TestRunFinished.json \
./jsonschema/TestRunStarted.json \
./jsonschema/Duration.json \
./jsonschema/TestStepResult.json \
./jsonschema/TestStepFinished.json \
./jsonschema/TestStepStarted.json \
./jsonschema/TestRunHookFinished.json \
./jsonschema/TestRunHookStarted.json \
./jsonschema/UndefinedParameterType.json \
./jsonschema/Envelope.json

Expand Down
2 changes: 2 additions & 0 deletions cpp/include/messages/cucumber/messages/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include <cucumber/messages/test_case_finished.hpp>
#include <cucumber/messages/test_case_started.hpp>
#include <cucumber/messages/test_run_finished.hpp>
#include <cucumber/messages/test_run_hook_finished.hpp>
#include <cucumber/messages/test_run_hook_started.hpp>
#include <cucumber/messages/test_run_started.hpp>
#include <cucumber/messages/test_step_finished.hpp>
#include <cucumber/messages/test_step_result.hpp>
Expand Down
1 change: 1 addition & 0 deletions cpp/include/messages/cucumber/messages/attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct attachment
std::optional<std::string> test_case_started_id;
std::optional<std::string> test_step_id;
std::optional<std::string> url;
std::optional<std::string> test_run_started_id;

std::string to_string() const;

Expand Down
4 changes: 4 additions & 0 deletions cpp/include/messages/cucumber/messages/envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <cucumber/messages/test_run_started.hpp>
#include <cucumber/messages/test_step_finished.hpp>
#include <cucumber/messages/test_step_started.hpp>
#include <cucumber/messages/test_run_hook_started.hpp>
#include <cucumber/messages/test_run_hook_finished.hpp>
#include <cucumber/messages/undefined_parameter_type.hpp>

namespace cucumber::messages {
Expand Down Expand Up @@ -59,6 +61,8 @@ struct envelope
std::optional<cucumber::messages::test_run_started> test_run_started;
std::optional<cucumber::messages::test_step_finished> test_step_finished;
std::optional<cucumber::messages::test_step_started> test_step_started;
std::optional<cucumber::messages::test_run_hook_started> test_run_hook_started;
std::optional<cucumber::messages::test_run_hook_finished> test_run_hook_finished;
std::optional<cucumber::messages::undefined_parameter_type> undefined_parameter_type;

std::string to_string() const;
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/messages/cucumber/messages/hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <nlohmann/json.hpp>

#include <cucumber/messages/source_reference.hpp>
#include <cucumber/messages/hook_type.hpp>

namespace cucumber::messages {

Expand All @@ -24,6 +25,7 @@ struct hook
std::optional<std::string> name;
cucumber::messages::source_reference source_reference;
std::optional<std::string> tag_expression;
std::optional<cucumber::messages::hook_type> type;

std::string to_string() const;

Expand Down
23 changes: 23 additions & 0 deletions cpp/include/messages/cucumber/messages/hook_type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <string_view>

namespace cucumber::messages {

enum class hook_type
{
BEFORE_TEST_RUN,
AFTER_TEST_RUN,
BEFORE_TEST_CASE,
AFTER_TEST_CASE,
BEFORE_TEST_STEP,
AFTER_TEST_STEP
};

std::string_view
to_string(hook_type v);

std::ostream&
operator<<(std::ostream& os, hook_type v);

}
1 change: 1 addition & 0 deletions cpp/include/messages/cucumber/messages/test_case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct test_case
std::string id;
std::string pickle_id;
std::vector<cucumber::messages::test_step> test_steps;
std::optional<std::string> test_run_started_id;

std::string to_string() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct test_run_finished
bool success;
cucumber::messages::timestamp timestamp;
std::optional<cucumber::messages::exception> exception;
std::optional<std::string> test_run_started_id;

std::string to_string() const;

Expand Down
39 changes: 39 additions & 0 deletions cpp/include/messages/cucumber/messages/test_run_hook_finished.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <vector>
#include <string>
#include <optional>

#include <nlohmann/json.hpp>

#include <cucumber/messages/test_step_result.hpp>
#include <cucumber/messages/timestamp.hpp>

namespace cucumber::messages {

using json = nlohmann::json;

//
// Represents the TestRunHookFinished message in Cucumber's message protocol
// @see <a href=https://github.com/cucumber/messages>Github - Cucumber - Messages</a>
//
// Generated code

struct test_run_hook_finished
{
std::string test_run_hook_started_id;
cucumber::messages::test_step_result result;
cucumber::messages::timestamp timestamp;

std::string to_string() const;

void to_json(json& j) const;
std::string to_json() const;
};

std::ostream&
operator<<(std::ostream& os, const test_run_hook_finished& msg);

void to_json(json& j, const test_run_hook_finished& m);

}
39 changes: 39 additions & 0 deletions cpp/include/messages/cucumber/messages/test_run_hook_started.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <vector>
#include <string>
#include <optional>

#include <nlohmann/json.hpp>

#include <cucumber/messages/timestamp.hpp>

namespace cucumber::messages {

using json = nlohmann::json;

//
// Represents the TestRunHookStarted message in Cucumber's message protocol
// @see <a href=https://github.com/cucumber/messages>Github - Cucumber - Messages</a>
//
// Generated code

struct test_run_hook_started
{
std::string id;
std::string test_run_started_id;
std::string hook_id;
cucumber::messages::timestamp timestamp;

std::string to_string() const;

void to_json(json& j) const;
std::string to_json() const;
};

std::ostream&
operator<<(std::ostream& os, const test_run_hook_started& msg);

void to_json(json& j, const test_run_hook_started& m);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using json = nlohmann::json;
struct test_run_started
{
cucumber::messages::timestamp timestamp;
std::optional<std::string> id;

std::string to_string() const;

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ attachment::to_string() const
cucumber::messages::to_string(oss, ", test_case_started_id=", test_case_started_id);
cucumber::messages::to_string(oss, ", test_step_id=", test_step_id);
cucumber::messages::to_string(oss, ", url=", url);
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);

return oss.str();
}
Expand All @@ -33,6 +34,7 @@ attachment::to_json(json& j) const
cucumber::messages::to_json(j, camelize("test_case_started_id"), test_case_started_id);
cucumber::messages::to_json(j, camelize("test_step_id"), test_step_id);
cucumber::messages::to_json(j, camelize("url"), url);
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
}

std::string
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ envelope::to_string() const
cucumber::messages::to_string(oss, ", test_run_started=", test_run_started);
cucumber::messages::to_string(oss, ", test_step_finished=", test_step_finished);
cucumber::messages::to_string(oss, ", test_step_started=", test_step_started);
cucumber::messages::to_string(oss, ", test_run_hook_started=", test_run_hook_started);
cucumber::messages::to_string(oss, ", test_run_hook_finished=", test_run_hook_finished);
cucumber::messages::to_string(oss, ", undefined_parameter_type=", undefined_parameter_type);

return oss.str();
Expand All @@ -50,6 +52,8 @@ envelope::to_json(json& j) const
cucumber::messages::to_json(j, camelize("test_run_started"), test_run_started);
cucumber::messages::to_json(j, camelize("test_step_finished"), test_step_finished);
cucumber::messages::to_json(j, camelize("test_step_started"), test_step_started);
cucumber::messages::to_json(j, camelize("test_run_hook_started"), test_run_hook_started);
cucumber::messages::to_json(j, camelize("test_run_hook_finished"), test_run_hook_finished);
cucumber::messages::to_json(j, camelize("undefined_parameter_type"), undefined_parameter_type);
}

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hook::to_string() const
cucumber::messages::to_string(oss, ", name=", name);
cucumber::messages::to_string(oss, ", source_reference=", source_reference);
cucumber::messages::to_string(oss, ", tag_expression=", tag_expression);
cucumber::messages::to_string(oss, ", type=", type);

return oss.str();
}
Expand All @@ -25,6 +26,7 @@ hook::to_json(json& j) const
cucumber::messages::to_json(j, camelize("name"), name);
cucumber::messages::to_json(j, camelize("source_reference"), source_reference);
cucumber::messages::to_json(j, camelize("tag_expression"), tag_expression);
cucumber::messages::to_json(j, camelize("type"), type);
}

std::string
Expand Down
33 changes: 33 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/hook_type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <unordered_map>

#include <cucumber/messages/hook_type.hpp>

namespace cucumber::messages {

std::string_view
to_string(hook_type v)
{
using map_type = std::unordered_map<hook_type, std::string_view>;

static const map_type m = {
{ hook_type::BEFORE_TEST_RUN, "BEFORE_TEST_RUN" },
{ hook_type::AFTER_TEST_RUN, "AFTER_TEST_RUN" },
{ hook_type::BEFORE_TEST_CASE, "BEFORE_TEST_CASE" },
{ hook_type::AFTER_TEST_CASE, "AFTER_TEST_CASE" },
{ hook_type::BEFORE_TEST_STEP, "BEFORE_TEST_STEP" },
{ hook_type::AFTER_TEST_STEP, "AFTER_TEST_STEP" }
};

return m.at(v);
}

std::ostream&
operator<<(std::ostream& os, hook_type v)
{
os << to_string(v);

return os;
}

}
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/test_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test_case::to_string() const
cucumber::messages::to_string(oss, "id=", id);
cucumber::messages::to_string(oss, ", pickle_id=", pickle_id);
cucumber::messages::to_string(oss, ", test_steps=", test_steps);
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);

return oss.str();
}
Expand All @@ -23,6 +24,7 @@ test_case::to_json(json& j) const
cucumber::messages::to_json(j, camelize("id"), id);
cucumber::messages::to_json(j, camelize("pickle_id"), pickle_id);
cucumber::messages::to_json(j, camelize("test_steps"), test_steps);
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
}

std::string
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/test_run_finished.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_run_finished::to_string() const
cucumber::messages::to_string(oss, ", success=", success);
cucumber::messages::to_string(oss, ", timestamp=", timestamp);
cucumber::messages::to_string(oss, ", exception=", exception);
cucumber::messages::to_string(oss, ", test_run_started_id=", test_run_started_id);

return oss.str();
}
Expand All @@ -25,6 +26,7 @@ test_run_finished::to_json(json& j) const
cucumber::messages::to_json(j, camelize("success"), success);
cucumber::messages::to_json(j, camelize("timestamp"), timestamp);
cucumber::messages::to_json(j, camelize("exception"), exception);
cucumber::messages::to_json(j, camelize("test_run_started_id"), test_run_started_id);
}

std::string
Expand Down
52 changes: 52 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/test_run_hook_finished.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <sstream>

#include <cucumber/messages/utils.hpp>
#include <cucumber/messages/test_run_hook_finished.hpp>

namespace cucumber::messages {

std::string
test_run_hook_finished::to_string() const
{
std::ostringstream oss;

cucumber::messages::to_string(oss, "test_run_hook_started_id=", test_run_hook_started_id);
cucumber::messages::to_string(oss, ", result=", result);
cucumber::messages::to_string(oss, ", timestamp=", timestamp);

return oss.str();
}

void
test_run_hook_finished::to_json(json& j) const
{
cucumber::messages::to_json(j, camelize("test_run_hook_started_id"), test_run_hook_started_id);
cucumber::messages::to_json(j, camelize("result"), result);
cucumber::messages::to_json(j, camelize("timestamp"), timestamp);
}

std::string
test_run_hook_finished::to_json() const
{
std::ostringstream oss;
json j;

to_json(j);

oss << j;

return oss.str();
}

std::ostream&
operator<<(std::ostream& os, const test_run_hook_finished& msg)
{
os << msg.to_string();

return os;
}

void to_json(json& j, const test_run_hook_finished& m)
{ m.to_json(j); }

}
Loading
Loading