Skip to content

Commit bccea39

Browse files
authored
[Core] Add space between scenario url and name (#2185)
The summary printer concatenated the url and scenario name without an additional space. This made it impossible to click the urls. Fixes: #2184
1 parent 0eee709 commit bccea39

File tree

3 files changed

+81
-29
lines changed

3 files changed

+81
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717
### Removed
1818

1919
### Fixed
20+
* [Core] SummaryPrinter outputs clickable links ([#2184](https://github.com/cucumber/cucumber-jvm/issues/2184) M.P. Korstanje)
2021

2122
## [6.9.0] (2020-11-12)
2223

core/src/main/java/io/cucumber/core/plugin/Stats.java

+14-19
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Stats implements ConcurrentEventListener, ColorAware {
3333
private final SubCounts scenarioSubCounts = new SubCounts();
3434
private final SubCounts stepSubCounts = new SubCounts();
3535
private final Locale locale;
36-
private final List<String> failedScenarios = new ArrayList<>();
37-
private final List<String> ambiguousScenarios = new ArrayList<>();
38-
private final List<String> pendingScenarios = new ArrayList<>();
39-
private final List<String> undefinedScenarios = new ArrayList<>();
36+
private final List<TestCase> failedScenarios = new ArrayList<>();
37+
private final List<TestCase> ambiguousScenarios = new ArrayList<>();
38+
private final List<TestCase> pendingScenarios = new ArrayList<>();
39+
private final List<TestCase> undefinedScenarios = new ArrayList<>();
4040
private final List<Throwable> errors = new ArrayList<>();
4141
private Instant startTime = Instant.EPOCH;
4242
private Duration totalDuration = Duration.ZERO;
@@ -75,9 +75,7 @@ private void addStepResult(TestStepFinished event) {
7575

7676
private void addScenario(TestCaseFinished event) {
7777
TestCase testCase = event.getTestCase();
78-
String location = testCase.getUri() + ":" + testCase.getLocation().getLine();
79-
String scenarioDesignation = location + "# " + testCase.getName();
80-
addScenario(event.getResult().getStatus(), scenarioDesignation);
78+
addScenario(event.getResult().getStatus(), testCase);
8179
}
8280

8381
private void setFinishTime(TestRunFinished event) {
@@ -96,20 +94,20 @@ void addStep(Status resultStatus) {
9694
addResultToSubCount(stepSubCounts, resultStatus);
9795
}
9896

99-
void addScenario(Status resultStatus, String scenarioDesignation) {
97+
void addScenario(Status resultStatus, TestCase testCase) {
10098
addResultToSubCount(scenarioSubCounts, resultStatus);
10199
switch (resultStatus) {
102100
case FAILED:
103-
failedScenarios.add(scenarioDesignation);
101+
failedScenarios.add(testCase);
104102
break;
105103
case AMBIGUOUS:
106-
ambiguousScenarios.add(scenarioDesignation);
104+
ambiguousScenarios.add(testCase);
107105
break;
108106
case PENDING:
109-
pendingScenarios.add(scenarioDesignation);
107+
pendingScenarios.add(testCase);
110108
break;
111109
case UNDEFINED:
112-
undefinedScenarios.add(scenarioDesignation);
110+
undefinedScenarios.add(testCase);
113111
break;
114112
default:
115113
// intentionally left blank
@@ -207,17 +205,14 @@ private void printNonZeroResultScenarios(PrintStream out) {
207205
printScenarios(out, undefinedScenarios, Status.UNDEFINED);
208206
}
209207

210-
private void printScenarios(PrintStream out, List<String> scenarios, Status type) {
208+
private void printScenarios(PrintStream out, List<TestCase> scenarios, Status type) {
211209
Format format = formats.get(type.name().toLowerCase(ROOT));
212210
if (!scenarios.isEmpty()) {
213211
out.println(format.text(firstLetterCapitalizedName(type) + " scenarios:"));
214212
}
215-
for (String scenario : scenarios) {
216-
String[] parts = scenario.split("#");
217-
out.print(format.text(parts[0]));
218-
for (int i = 1; i < parts.length; ++i) {
219-
out.println("#" + parts[i]);
220-
}
213+
for (TestCase scenario : scenarios) {
214+
String location = scenario.getUri() + ":" + scenario.getLocation().getLine();
215+
out.println(location + " # " + scenario.getName());
221216
}
222217
if (!scenarios.isEmpty()) {
223218
out.println();

core/src/test/java/io/cucumber/core/plugin/StatsTest.java

+66-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package io.cucumber.core.plugin;
22

3+
import io.cucumber.plugin.event.Location;
34
import io.cucumber.plugin.event.Status;
5+
import io.cucumber.plugin.event.TestCase;
6+
import io.cucumber.plugin.event.TestStep;
47
import org.junit.jupiter.api.Test;
58

69
import java.io.ByteArrayOutputStream;
710
import java.io.PrintStream;
11+
import java.net.URI;
812
import java.time.Instant;
13+
import java.util.Collections;
14+
import java.util.List;
915
import java.util.Locale;
16+
import java.util.UUID;
1017

1118
import static java.time.Duration.ofHours;
1219
import static java.time.Duration.ofMillis;
@@ -46,7 +53,7 @@ void should_only_print_sub_counts_if_not_zero() {
4653
counter.addStep(Status.PASSED);
4754
counter.addStep(Status.PASSED);
4855
counter.addStep(Status.PASSED);
49-
counter.addScenario(Status.PASSED, "scenario designation");
56+
counter.addScenario(Status.PASSED, createTestCase("classpath:com/example", 42, "scenario designation"));
5057
counter.printStats(new PrintStream(baos));
5158

5259
assertThat(baos.toString(), startsWith(String.format(
@@ -74,7 +81,7 @@ void should_print_sub_counts_in_order_failed_ambiguous_skipped_pending_undefined
7481

7582
private void addOneStepScenario(Stats counter, Status status) {
7683
counter.addStep(status);
77-
counter.addScenario(status, "scenario designation");
84+
counter.addScenario(status, createTestCase("classpath:com/example", 14, "scenario designation"));
7885
}
7986

8087
@Test
@@ -174,13 +181,13 @@ void should_print_failed_ambiguous_scenarios() {
174181
ByteArrayOutputStream baos = new ByteArrayOutputStream();
175182

176183
counter.addStep(Status.FAILED);
177-
counter.addScenario(Status.FAILED, "path/file.feature:3 # Scenario: scenario_name");
184+
counter.addScenario(Status.FAILED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
178185
counter.addStep(Status.AMBIGUOUS);
179-
counter.addScenario(Status.AMBIGUOUS, "path/file.feature:3 # Scenario: scenario_name");
186+
counter.addScenario(Status.AMBIGUOUS, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
180187
counter.addStep(Status.UNDEFINED);
181-
counter.addScenario(Status.UNDEFINED, "path/file.feature:3 # Scenario: scenario_name");
188+
counter.addScenario(Status.UNDEFINED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
182189
counter.addStep(Status.PENDING);
183-
counter.addScenario(Status.PENDING, "path/file.feature:3 # Scenario: scenario_name");
190+
counter.addScenario(Status.PENDING, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
184191
counter.printStats(new PrintStream(baos));
185192

186193
assertThat(baos.toString(), startsWith(String.format("" +
@@ -205,13 +212,13 @@ void should_print_failed_ambiguous_pending_undefined_scenarios_if_strict() {
205212
ByteArrayOutputStream baos = new ByteArrayOutputStream();
206213

207214
counter.addStep(Status.FAILED);
208-
counter.addScenario(Status.FAILED, "path/file.feature:3 # Scenario: scenario_name");
215+
counter.addScenario(Status.FAILED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
209216
counter.addStep(Status.AMBIGUOUS);
210-
counter.addScenario(Status.AMBIGUOUS, "path/file.feature:3 # Scenario: scenario_name");
217+
counter.addScenario(Status.AMBIGUOUS, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
211218
counter.addStep(Status.UNDEFINED);
212-
counter.addScenario(Status.UNDEFINED, "path/file.feature:3 # Scenario: scenario_name");
219+
counter.addScenario(Status.UNDEFINED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
213220
counter.addStep(Status.PENDING);
214-
counter.addScenario(Status.PENDING, "path/file.feature:3 # Scenario: scenario_name");
221+
counter.addScenario(Status.PENDING, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
215222
counter.printStats(new PrintStream(baos));
216223

217224
assertThat(baos.toString(), startsWith(String.format("" +
@@ -230,4 +237,53 @@ void should_print_failed_ambiguous_pending_undefined_scenarios_if_strict() {
230237
"4 Scenarios")));
231238
}
232239

240+
private static TestCase createTestCase(String uri, int line, String name) {
241+
return new TestCase() {
242+
@Override
243+
public Integer getLine() {
244+
return getLocation().getLine();
245+
}
246+
247+
@Override
248+
public Location getLocation() {
249+
return new Location(line, -1);
250+
}
251+
252+
@Override
253+
public String getKeyword() {
254+
return "Scenario";
255+
}
256+
257+
@Override
258+
public String getName() {
259+
return name;
260+
}
261+
262+
@Override
263+
public String getScenarioDesignation() {
264+
return null;
265+
}
266+
267+
@Override
268+
public List<String> getTags() {
269+
return Collections.emptyList();
270+
}
271+
272+
@Override
273+
public List<TestStep> getTestSteps() {
274+
return Collections.emptyList();
275+
}
276+
277+
@Override
278+
public URI getUri() {
279+
return URI.create(uri);
280+
}
281+
282+
@Override
283+
public UUID getId() {
284+
return UUID.randomUUID();
285+
}
286+
};
287+
}
288+
233289
}

0 commit comments

Comments
 (0)