|
3 | 3 | #include "cucumber_cpp/library/engine/Result.hpp" |
4 | 4 | #include "cucumber_cpp/library/engine/test_helper/ContextManagerInstance.hpp" |
5 | 5 | #include "cucumber_cpp/library/report/Report.hpp" |
| 6 | +#include <cstddef> |
| 7 | +#include <filesystem> |
6 | 8 | #include <gmock/gmock.h> |
7 | 9 | #include <gtest/gtest.h> |
| 10 | +#include <optional> |
| 11 | +#include <string> |
8 | 12 |
|
9 | 13 | namespace cucumber_cpp::library::engine |
10 | 14 | { |
11 | | - struct TestFailureHandler : testing::Test |
| 15 | + namespace |
12 | 16 | { |
13 | | - }; |
| 17 | + void ErrorWithFailureMessage(const char* failure) |
| 18 | + { |
| 19 | + CucumberAssertHelper{ testing::TestPartResult::kNonFatalFailure, "custom_file.cpp", 0, failure } = testing::Message(); |
| 20 | + } |
14 | 21 |
|
15 | | - TEST_F(TestFailureHandler, ConstructThisNeedsToBeExtendedAndSeparatedWorkInProgress) |
16 | | - { |
17 | | - test_helper::ContextManagerInstance contextManager; |
18 | | - report::ReportForwarderImpl reportHandler{ contextManager }; |
19 | | - TestAssertionHandlerImpl testAssertionHandler{ contextManager, reportHandler }; |
| 22 | + void ErrorWithUserMessage(const char* user) |
| 23 | + { |
| 24 | + CucumberAssertHelper{ testing::TestPartResult::kNonFatalFailure, "custom_file.cpp", 0, "" } = testing::Message() << user; |
| 25 | + } |
20 | 26 |
|
21 | | - ASSERT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::passed)); |
| 27 | + void ErrorWithFailureAndUserMessage(const char* failure, const char* user) |
| 28 | + { |
| 29 | + CucumberAssertHelper{ testing::TestPartResult::kNonFatalFailure, "custom_file.cpp", 0, failure } = testing::Message() << user; |
| 30 | + } |
| 31 | + |
| 32 | + struct ReportForwarderMock : report::ReportForwarderImpl |
| 33 | + { |
| 34 | + using ReportForwarderImpl::ReportForwarderImpl; |
| 35 | + virtual ~ReportForwarderMock() = default; |
22 | 36 |
|
23 | | - CucumberAssertHelper assertHelper{ testing::TestPartResult::kNonFatalFailure, __FILE__, __LINE__, "message" }; |
| 37 | + MOCK_METHOD(void, Failure, (const std::string& error, std::optional<std::filesystem::path> path, std::optional<std::size_t> line, std::optional<std::size_t> column), (override)); |
| 38 | + MOCK_METHOD(void, Error, (const std::string& error, std::optional<std::filesystem::path> path, std::optional<std::size_t> line, std::optional<std::size_t> column), (override)); |
| 39 | + }; |
| 40 | + |
| 41 | + struct TestFailureHandler : testing::Test |
| 42 | + { |
| 43 | + |
| 44 | + test_helper::ContextManagerInstance contextManager; |
| 45 | + ReportForwarderMock reportHandler{ contextManager }; |
| 46 | + TestAssertionHandlerImpl testAssertionHandler{ contextManager, reportHandler }; |
| 47 | + }; |
| 48 | + } |
| 49 | + |
| 50 | + TEST_F(TestFailureHandler, SetContextToFailed) |
| 51 | + { |
| 52 | + ASSERT_THAT(contextManager.CurrentContext().ExecutionStatus(), testing::Eq(Result::passed)); |
| 53 | + ASSERT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::passed)); |
| 54 | + ASSERT_THAT(contextManager.FeatureContext().ExecutionStatus(), testing::Eq(Result::passed)); |
| 55 | + ASSERT_THAT(contextManager.RuleContext().ExecutionStatus(), testing::Eq(Result::passed)); |
| 56 | + ASSERT_THAT(contextManager.ScenarioContext().ExecutionStatus(), testing::Eq(Result::passed)); |
24 | 57 | ASSERT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::passed)); |
25 | 58 |
|
26 | | - assertHelper = testing::Message("testing::Message") << "user message"; |
27 | | - ASSERT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 59 | + ErrorWithFailureMessage("failure"); |
| 60 | + |
| 61 | + EXPECT_THAT(contextManager.CurrentContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 62 | + EXPECT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 63 | + EXPECT_THAT(contextManager.FeatureContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 64 | + EXPECT_THAT(contextManager.RuleContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 65 | + EXPECT_THAT(contextManager.ScenarioContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 66 | + EXPECT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::failed)); |
| 67 | + } |
| 68 | + |
| 69 | + TEST_F(TestFailureHandler, ReportFailureMessage) |
| 70 | + { |
| 71 | + EXPECT_CALL(reportHandler, Failure("Failure Message", testing::_, testing::_, testing::_)); |
| 72 | + |
| 73 | + ErrorWithFailureMessage("Failure Message"); |
| 74 | + } |
| 75 | + |
| 76 | + TEST_F(TestFailureHandler, ReportUserMessage) |
| 77 | + { |
| 78 | + EXPECT_CALL(reportHandler, Failure("User Message", testing::_, testing::_, testing::_)); |
| 79 | + |
| 80 | + ErrorWithUserMessage("User Message"); |
| 81 | + } |
| 82 | + |
| 83 | + TEST_F(TestFailureHandler, ReportFailureAndUserMessage) |
| 84 | + { |
| 85 | + EXPECT_CALL(reportHandler, Failure("Failure Message\nUser Message", testing::_, testing::_, testing::_)); |
| 86 | + |
| 87 | + ErrorWithFailureAndUserMessage("Failure Message", "User Message"); |
28 | 88 | } |
29 | 89 | } |
0 commit comments