Skip to content

Commit c235f1a

Browse files
committed
add undefined, unknown-parameter-type and unused-steps compatibility tests, improved ambiguous test
1 parent e94534c commit c235f1a

File tree

17 files changed

+167
-113
lines changed

17 files changed

+167
-113
lines changed

compatibility/ambiguous/ambiguous.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ STEP(R"(^a (.*?) with (.*?)$)", (const std::string& arg1, const std::string& arg
66
// no-op
77
}
88

9-
STEP(R"(^a step with (.*)$)", (const std::string& arg1))
9+
STEP(R"(^a step with (.*?)$)", (const std::string& arg1))
1010
{
1111
// no-op
1212
}

compatibility/ambiguous/ambiguous.ndjson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"Ambiguous steps","description":" Multiple step definitions that match a pickle step result in an AMBIGUOUS status, since Cucumnber cannot determine\n which one to execute.","children":[{"scenario":{"id":"1","tags":[],"location":{"line":5,"column":3},"keyword":"Scenario","name":"Multiple step definitions for a step","description":"","steps":[{"id":"0","location":{"line":6,"column":5},"keyword":"Given ","keywordType":"Context","text":"a step with multiple definitions"}],"examples":[]}}]},"comments":[],"uri":"samples/ambiguous/ambiguous.feature"}}
44
{"pickle":{"id":"3","uri":"samples/ambiguous/ambiguous.feature","location":{"line":5,"column":3},"astNodeIds":["1"],"tags":[],"name":"Multiple step definitions for a step","language":"en","steps":[{"id":"2","text":"a step with multiple definitions","type":"Context","astNodeIds":["0"]}]}}
55
{"stepDefinition":{"id":"4","pattern":{"type":"REGULAR_EXPRESSION","source":"^a (.*?) with (.*?)$"},"sourceReference":{"uri":"samples/ambiguous/ambiguous.ts","location":{"line":3}}}}
6-
{"stepDefinition":{"id":"5","pattern":{"type":"REGULAR_EXPRESSION","source":"^a step with (.*)$"},"sourceReference":{"uri":"samples/ambiguous/ambiguous.ts","location":{"line":7}}}}
6+
{"stepDefinition":{"id":"5","pattern":{"type":"REGULAR_EXPRESSION","source":"^a step with (.*?)$"},"sourceReference":{"uri":"samples/ambiguous/ambiguous.ts","location":{"line":7}}}}
77
{"testRunStarted":{"id":"6","timestamp":{"seconds":0,"nanos":0}}}
8-
{"testCase":{"id":"7","pickleId":"3","testSteps":[{"id":"8","pickleStepId":"2","stepDefinitionIds":["4","5"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"start":2,"value":"step","children":[]}},{"group":{"start":12,"value":"multiple definitions","children":[]}}]},{"stepMatchArguments":[{"group":{"start":12,"value":"multiple definitions","children":[]},"parameterTypeName":""}]}]}],"testRunStartedId":"6"}}
8+
{"testCase":{"id":"7","pickleId":"3","testSteps":[{"id":"8","pickleStepId":"2","stepDefinitionIds":["4","5"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"start":2,"value":"step","children":[]}},{"group":{"start":12,"value":"multiple definitions","children":[]}}]},{"stepMatchArguments":[{"group":{"start":12,"value":"multiple definitions","children":[]}}]}]}],"testRunStartedId":"6"}}
99
{"testCaseStarted":{"id":"9","testCaseId":"7","timestamp":{"seconds":0,"nanos":1000000},"attempt":0}}
1010
{"testStepStarted":{"testCaseStartedId":"9","testStepId":"8","timestamp":{"seconds":0,"nanos":2000000}}}
1111
{"testStepFinished":{"testCaseStartedId":"9","testStepId":"8","testStepResult":{"status":"AMBIGUOUS","duration":{"seconds":0,"nanos":0}},"timestamp":{"seconds":0,"nanos":3000000}}}

compatibility/compatibility.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,18 @@ namespace compatibility
6565
auto& key = jsonIter.key();
6666
auto& value = jsonIter.value();
6767

68-
if (key == "parameterTypeName" && value.get<std::string>().empty())
69-
jsonIter = json.erase(jsonIter);
70-
else if (key == "exception")
68+
if (key == "exception")
7169
jsonIter = json.erase(jsonIter);
7270
else if (key == "message")
7371
jsonIter = json.erase(jsonIter);
7472
else if (key == "line")
7573
jsonIter = json.erase(jsonIter);
76-
else if (key == "start")
77-
jsonIter = json.erase(jsonIter);
7874
else if (key == "snippets")
7975
jsonIter = json.erase(jsonIter);
8076
else if (value.is_object())
8177
{
8278
SanitizeExpectedJson(value);
83-
if (value.size() == 0)
84-
jsonIter = json.erase(jsonIter);
85-
else
86-
++jsonIter;
79+
++jsonIter;
8780
}
8881
else if (value.is_array())
8982
{
@@ -95,16 +88,10 @@ namespace compatibility
9588
if (item.is_object())
9689
SanitizeExpectedJson(item);
9790

98-
if (item.size() == 0)
99-
valueIter = value.erase(valueIter);
100-
else
101-
++valueIter;
91+
++valueIter;
10292
}
10393

104-
if (value.size() == 0)
105-
jsonIter = json.erase(jsonIter);
106-
else
107-
++jsonIter;
94+
++jsonIter;
10895
}
10996
else if (key == "uri")
11097
{
@@ -124,9 +111,7 @@ namespace compatibility
124111
auto& key = jsonIter.key();
125112
auto& value = jsonIter.value();
126113

127-
if (key == "parameterTypeName" && value.get<std::string>().empty())
128-
jsonIter = json.erase(jsonIter);
129-
else if (key == "exception")
114+
if (key == "exception")
130115
jsonIter = json.erase(jsonIter);
131116
else if (key == "message")
132117
jsonIter = json.erase(jsonIter);
@@ -137,10 +122,7 @@ namespace compatibility
137122
else if (value.is_object())
138123
{
139124
SanitizeActualJson(value);
140-
if (value.size() == 0)
141-
jsonIter = json.erase(jsonIter);
142-
else
143-
++jsonIter;
125+
++jsonIter;
144126
}
145127
else if (value.is_array())
146128
{
@@ -152,16 +134,10 @@ namespace compatibility
152134
if (item.is_object())
153135
SanitizeActualJson(item);
154136

155-
if (item.size() == 0)
156-
valueIter = value.erase(valueIter);
157-
else
158-
++valueIter;
137+
++valueIter;
159138
}
160139

161-
if (value.size() == 0)
162-
jsonIter = json.erase(jsonIter);
163-
else
164-
++jsonIter;
140+
++jsonIter;
165141
}
166142
else
167143
++jsonIter;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "cucumber_cpp/CucumberCpp.hpp"
2+
3+
GIVEN(R"(an implemented step)")
4+
{
5+
// no-op
6+
}
7+
8+
GIVEN(R"(a step that will be skipped)")
9+
{
10+
// no-op
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "cucumber_cpp/CucumberCpp.hpp"
2+
#include <gtest/gtest.h>
3+
4+
struct Airport
5+
{};
6+
7+
GIVEN(R"({airport} is closed because of a strike)", (const Airport& airport))
8+
{
9+
FAIL() << "Should not be called because airport parameter type has not been defined";
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "cucumber_cpp/CucumberCpp.hpp"
2+
#include <gtest/gtest.h>
3+
4+
GIVEN(R"(a step that is used)")
5+
{
6+
}
7+
8+
GIVEN(R"(a step that is not used)")
9+
{
10+
}

0 commit comments

Comments
 (0)