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

Include pickle name if parameterized #2890

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void should_handle_scenario_outline() {
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
+ "path/test.feature:5' name = 'examples name']\n" +
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
+ "path/test.feature:7' name = 'Example #1.1']\n" +
+ "path/test.feature:7' name = '#1.1 - name 1']\n" +
"##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" +
"##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
+ "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" +
Expand All @@ -83,9 +83,10 @@ void should_handle_scenario_outline() {
"##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n"
+
"##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" +
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1']\n" +
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.1 - name 1']\n"
+
"##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
+ "path/test.feature:8' name = 'Example #1.2']\n" +
+ "path/test.feature:8' name = '#1.2 - name 2']\n" +
"##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" +
"##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location
+ "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" +
Expand All @@ -96,7 +97,8 @@ void should_handle_scenario_outline() {
"##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n"
+
"##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" +
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2']\n" +
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.2 - name 2']\n"
+
"##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n"
+
"##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'examples name']\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

final class GherkinMessagesExample implements Node.Example {

private final GherkinMessagesFeature feature;
private final TableRow tableRow;
private final int examplesIndex;
private final int rowIndex;
private final Node parent;

GherkinMessagesExample(Node parent, TableRow tableRow, int examplesIndex, int rowIndex) {
GherkinMessagesExample(
GherkinMessagesFeature feature, Node parent, TableRow tableRow, int examplesIndex, int rowIndex
) {
this.feature = feature;
this.parent = parent;
this.tableRow = tableRow;
this.examplesIndex = examplesIndex;
Expand All @@ -32,7 +36,18 @@ public Optional<String> getKeyword() {

@Override
public Optional<String> getName() {
return Optional.of("Example #" + examplesIndex + "." + rowIndex);
String pickleName = feature.getPickleAt(this).getName();
boolean parameterized = !parent.getParent()
.filter(GherkinMessagesScenarioOutline.class::isInstance)
.flatMap(Node::getName)
.map(pickleName::equals)
.orElse(true);

StringBuilder builder = new StringBuilder("#" + examplesIndex + "." + rowIndex);
if (parameterized) {
builder.append(" - ").append(pickleName);
}
return Optional.of(builder.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@

final class GherkinMessagesExamples implements Node.Examples {

private final GherkinMessagesFeature feature;
private final io.cucumber.messages.types.Examples examples;
private final List<Example> children;
private final Location location;
private final Node parent;

GherkinMessagesExamples(Node parent, io.cucumber.messages.types.Examples examples, int examplesIndex) {
GherkinMessagesExamples(
GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Examples examples, int examplesIndex
) {
this.feature = feature;
this.parent = parent;
this.examples = examples;
this.location = GherkinMessagesLocation.from(examples.getLocation());
AtomicInteger row = new AtomicInteger(1);
this.children = examples.getTableBody().stream()
.map(tableRow -> new GherkinMessagesExample(this, tableRow, examplesIndex, row.getAndIncrement()))
.map(tableRow -> new GherkinMessagesExample(feature, this, tableRow, examplesIndex,
row.getAndIncrement()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ final class GherkinMessagesFeature implements Feature {

private Node mapRuleOrScenario(FeatureChild featureChild) {
if (featureChild.getRule().isPresent()) {
return new GherkinMessagesRule(this, featureChild.getRule().get());
return new GherkinMessagesRule(this, this, featureChild.getRule().get());
}

io.cucumber.messages.types.Scenario scenario = featureChild.getScenario().get();
if (!scenario.getExamples().isEmpty()) {
return new GherkinMessagesScenarioOutline(this, scenario);
return new GherkinMessagesScenarioOutline(this, this, scenario);
}
return new GherkinMessagesScenario(this, scenario);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class GherkinMessagesRule implements Node.Rule {
private final io.cucumber.messages.types.Rule rule;
private final List<Node> children;

GherkinMessagesRule(Node parent, io.cucumber.messages.types.Rule rule) {
GherkinMessagesRule(GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Rule rule) {
this.parent = parent;
this.rule = rule;
this.children = rule.getChildren().stream()
Expand All @@ -24,7 +24,7 @@ final class GherkinMessagesRule implements Node.Rule {
.map(Optional::get)
.map(scenario -> {
if (!scenario.getExamples().isEmpty()) {
return new GherkinMessagesScenarioOutline(this, scenario);
return new GherkinMessagesScenarioOutline(feature, this, scenario);
} else {
return new GherkinMessagesScenario(this, scenario);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ final class GherkinMessagesScenarioOutline implements Node.ScenarioOutline {
private final List<Examples> children;
private final Node parent;

GherkinMessagesScenarioOutline(Node parent, io.cucumber.messages.types.Scenario scenario) {
GherkinMessagesScenarioOutline(
GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Scenario scenario
) {
this.parent = parent;
this.scenario = scenario;
AtomicInteger examplesIndex = new AtomicInteger(1);
this.children = scenario.getExamples().stream()
.map(examples -> new GherkinMessagesExamples(this, examples, examplesIndex.getAndIncrement()))
.map(examples -> new GherkinMessagesExamples(feature, this, examples, examplesIndex.getAndIncrement()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void unnamed_elements_return_empty_strings_as_name() throws IOException {
Node.Example example = examples.elements().iterator().next();

// Example is the exception.
assertEquals(Optional.of("Example #1.1"), example.getName());
assertEquals(Optional.of("#1.1"), example.getName());
assertEquals(Optional.empty(), example.getKeyword());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private TestDescriptor getOutline() {
@Test
void example() {
TestDescriptor example = getExample();
assertEquals("Example #1.1", example.getDisplayName());
assertEquals("#1.1", example.getDisplayName());
assertEquals(
asSet(create("FeatureTag"), create("Example1Tag"), create("ScenarioOutlineTag")),
example.getTags());
Expand All @@ -157,7 +157,7 @@ void longNames() {
JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, "long");

TestDescriptor example = getExample();
assertEquals("A feature with scenario outlines - A scenario outline - With some text - Example #1.1",
assertEquals("A feature with scenario outlines - A scenario outline - With some text - #1.1",
example.getDisplayName());
}

Expand All @@ -178,7 +178,7 @@ void shortNamesWithExampleNumbers() {
JUNIT_PLATFORM_SHORT_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME, "number");

TestDescriptor example = getExample();
assertEquals("Example #1.1", example.getDisplayName());
assertEquals("#1.1", example.getDisplayName());
}

@Test
Expand Down