Skip to content

Commit 08d653f

Browse files
authored
feat: add error handling without invoking the google test test environment (#104)
1 parent 016eb9f commit 08d653f

File tree

98 files changed

+2851
-1120
lines changed

Some content is hidden

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

98 files changed

+2851
-1120
lines changed

.vscode/launch.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99
"description": "Enter the tag to run",
1010
"type": "pickString",
1111
"options": [
12+
"@smoke",
1213
"@rule1 or @smoke",
1314
"@keyword-asterisk",
14-
"@result:UNDEFINED"
15+
"@result:UNDEFINED",
16+
"@result:FAILED",
17+
"@fail_feature"
1518
]
1619
},
1720
{
1821
"id": "features",
1922
"description": "Enter the tag to run",
2023
"type": "pickString",
2124
"options": [
22-
"cucumber-cpp-example/features",
23-
"test/features"
25+
"cucumber_cpp/example/features",
26+
"cucumber_cpp/acceptance_test/features"
2427
]
2528
}
2629
],
@@ -36,9 +39,10 @@
3639
"${input:features}",
3740
"--report",
3841
"console",
39-
"--com",
40-
"COMx",
41-
"--nordic",
42+
"junit-xml",
43+
// "--com",
44+
// "COMx",
45+
// "--nordic",
4246
"--tag",
4347
"${input:tag}"
4448
],

.vscode/settings.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"cmake.useCMakePresets": "always",
33
"cucumberautocomplete.steps": [
4-
"cucumber-cpp-example/steps/*.cpp",
5-
"test/steps/*.cpp"
4+
"cucumber_cpp/example/steps/*.cpp",
5+
"cucumber_cpp/acceptance_test/steps/*.cpp"
66
],
77
"cucumberautocomplete.gherkinDefinitionPart": "(GIVEN|WHEN|THEN|STEP)\\(",
88
"cucumberautocomplete.customParameters": [
@@ -20,5 +20,9 @@
2020
"C/C++ Include Guard.Remove Extension": false,
2121
"C/C++ Include Guard.Comment Style": "None",
2222
"C/C++ Include Guard.Path Skip": 0,
23-
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*"
23+
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*",
24+
"sonarlint.connectedMode.project": {
25+
"connectionId": "philips-software",
26+
"projectKey": "philips-software_amp-cucumber-cpp-runner"
27+
}
2428
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"label": "bats",
88
"type": "shell",
9-
"command": "bats --formatter junit cucumber_cpp/integration_test/test.bats | tee test-report.xml",
9+
"command": "bats --formatter junit cucumber_cpp/acceptance_test/test.bats | tee test-report.xml",
1010
"problemMatcher": []
1111
}
1212
]

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (CCR_BUILD_TESTS)
2727
ccr_enable_testing()
2828
endif()
2929

30-
set(CMAKE_CXX_STANDARD 20)
30+
set(CMAKE_CXX_STANDARD 23)
3131
set(CMAKE_CXX_STANDARD_REQUIRED On)
3232
set(CMAKE_CXX_EXTENSIONS Off)
3333

cucumber_cpp/acceptance_test/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main(int argc, char** argv)
55
{
6-
cucumber_cpp::Application application{};
6+
cucumber_cpp::library::Application application{};
77

88
return application.Run(argc, argv);
99
}

cucumber_cpp/acceptance_test/MainCustom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main(int argc, char** argv)
55
{
6-
cucumber_cpp::Application application{};
6+
cucumber_cpp::library::Application application{};
77

88
application.CliParser().add_flag("--required", *application.ProgramContext().EmplaceAt<bool>("--required"))->required();
99

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@fail_feature
2+
Feature: Simple feature file
3+
Background:
4+
Given a background step
5+
6+
Scenario: A failing scenario
7+
Given a given step
8+
When a when step
9+
Then an assertion is raised
10+
Then a then step
11+
12+
Scenario: An OK scenario
13+
Given a given step
14+
When a when step
15+
Then a then step
Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
@bats
22
Feature: Test scenario and step hook bindings
33

4-
Background:
5-
Given a background step
6-
7-
@scenariohook @stephook
8-
Scenario: Run Scenario and Step hooks
4+
@fail_scenariohook_before
5+
Scenario: Run failing Scenario hooks before
96
Given a given step
10-
When a when step
11-
Then a then step
127

13-
@scenariohook
14-
Scenario: Run only Scenario hooks
8+
@fail_scenariohook_after
9+
Scenario: Run failing Scenario hooks after
1510
Given a given step
16-
When a when step
17-
Then a then step
1811

19-
@stephook
20-
Scenario: Run only Step hooks
12+
@throw_scenariohook
13+
Scenario: Run throwing Scenario hooks
2114
Given a given step
22-
When a when step
23-
Then a then step
15+
16+
Rule: These scenarios have a background
17+
18+
Background:
19+
Given a background step
20+
21+
@scenariohook @stephook
22+
Scenario: Run Scenario and Step hooks
23+
Given a given step
24+
When a when step
25+
Then a then step
26+
27+
@scenariohook
28+
Scenario: Run only Scenario hooks
29+
Given a given step
30+
When a when step
31+
Then a then step
32+
33+
@stephook
34+
Scenario: Run only Step hooks
35+
Given a given step
36+
When a when step
37+
Then a then step

cucumber_cpp/acceptance_test/hooks/Hooks.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "cucumber_cpp/library/Hooks.hpp"
2+
#include "gmock/gmock.h"
23
#include <iostream>
4+
#include <string>
35

46
HOOK_BEFORE_ALL()
57
{
@@ -30,3 +32,18 @@ HOOK_AFTER_STEP("@stephook and @bats")
3032
{
3133
std::cout << "HOOK_AFTER_STEP\n";
3234
}
35+
36+
HOOK_BEFORE_SCENARIO("@fail_scenariohook_before")
37+
{
38+
ASSERT_THAT(false, testing::IsTrue());
39+
}
40+
41+
HOOK_AFTER_SCENARIO("@fail_scenariohook_after")
42+
{
43+
ASSERT_THAT(false, testing::IsTrue());
44+
}
45+
46+
HOOK_BEFORE_SCENARIO("@throw_scenariohook")
47+
{
48+
throw std::string{ "error" };
49+
}

cucumber_cpp/acceptance_test/steps/Steps.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ THEN("two expectations are raised")
4444
EXPECT_THAT(0, testing::Eq(1));
4545
EXPECT_THAT(1, testing::Eq(0));
4646
}
47+
48+
WHEN("I print {string} with value {int}", (const std::string& str, std::int32_t value))
49+
{
50+
std::cout << "print: " << str << " with value " << value;
51+
}

0 commit comments

Comments
 (0)