Skip to content

[Core] Add space between scenario url and name #2185

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

Merged
merged 1 commit into from
Dec 10, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed

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

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

Expand Down
33 changes: 14 additions & 19 deletions core/src/main/java/io/cucumber/core/plugin/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class Stats implements ConcurrentEventListener, ColorAware {
private final SubCounts scenarioSubCounts = new SubCounts();
private final SubCounts stepSubCounts = new SubCounts();
private final Locale locale;
private final List<String> failedScenarios = new ArrayList<>();
private final List<String> ambiguousScenarios = new ArrayList<>();
private final List<String> pendingScenarios = new ArrayList<>();
private final List<String> undefinedScenarios = new ArrayList<>();
private final List<TestCase> failedScenarios = new ArrayList<>();
private final List<TestCase> ambiguousScenarios = new ArrayList<>();
private final List<TestCase> pendingScenarios = new ArrayList<>();
private final List<TestCase> undefinedScenarios = new ArrayList<>();
private final List<Throwable> errors = new ArrayList<>();
private Instant startTime = Instant.EPOCH;
private Duration totalDuration = Duration.ZERO;
Expand Down Expand Up @@ -75,9 +75,7 @@ private void addStepResult(TestStepFinished event) {

private void addScenario(TestCaseFinished event) {
TestCase testCase = event.getTestCase();
String location = testCase.getUri() + ":" + testCase.getLocation().getLine();
String scenarioDesignation = location + "# " + testCase.getName();
addScenario(event.getResult().getStatus(), scenarioDesignation);
addScenario(event.getResult().getStatus(), testCase);
}

private void setFinishTime(TestRunFinished event) {
Expand All @@ -96,20 +94,20 @@ void addStep(Status resultStatus) {
addResultToSubCount(stepSubCounts, resultStatus);
}

void addScenario(Status resultStatus, String scenarioDesignation) {
void addScenario(Status resultStatus, TestCase testCase) {
addResultToSubCount(scenarioSubCounts, resultStatus);
switch (resultStatus) {
case FAILED:
failedScenarios.add(scenarioDesignation);
failedScenarios.add(testCase);
break;
case AMBIGUOUS:
ambiguousScenarios.add(scenarioDesignation);
ambiguousScenarios.add(testCase);
break;
case PENDING:
pendingScenarios.add(scenarioDesignation);
pendingScenarios.add(testCase);
break;
case UNDEFINED:
undefinedScenarios.add(scenarioDesignation);
undefinedScenarios.add(testCase);
break;
default:
// intentionally left blank
Expand Down Expand Up @@ -207,17 +205,14 @@ private void printNonZeroResultScenarios(PrintStream out) {
printScenarios(out, undefinedScenarios, Status.UNDEFINED);
}

private void printScenarios(PrintStream out, List<String> scenarios, Status type) {
private void printScenarios(PrintStream out, List<TestCase> scenarios, Status type) {
Format format = formats.get(type.name().toLowerCase(ROOT));
if (!scenarios.isEmpty()) {
out.println(format.text(firstLetterCapitalizedName(type) + " scenarios:"));
}
for (String scenario : scenarios) {
String[] parts = scenario.split("#");
out.print(format.text(parts[0]));
for (int i = 1; i < parts.length; ++i) {
out.println("#" + parts[i]);
}
for (TestCase scenario : scenarios) {
String location = scenario.getUri() + ":" + scenario.getLocation().getLine();
out.println(location + " # " + scenario.getName());
}
if (!scenarios.isEmpty()) {
out.println();
Expand Down
76 changes: 66 additions & 10 deletions core/src/test/java/io/cucumber/core/plugin/StatsTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package io.cucumber.core.plugin;

import io.cucumber.plugin.event.Location;
import io.cucumber.plugin.event.Status;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestStep;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

import static java.time.Duration.ofHours;
import static java.time.Duration.ofMillis;
Expand Down Expand Up @@ -46,7 +53,7 @@ void should_only_print_sub_counts_if_not_zero() {
counter.addStep(Status.PASSED);
counter.addStep(Status.PASSED);
counter.addStep(Status.PASSED);
counter.addScenario(Status.PASSED, "scenario designation");
counter.addScenario(Status.PASSED, createTestCase("classpath:com/example", 42, "scenario designation"));
counter.printStats(new PrintStream(baos));

assertThat(baos.toString(), startsWith(String.format(
Expand Down Expand Up @@ -74,7 +81,7 @@ void should_print_sub_counts_in_order_failed_ambiguous_skipped_pending_undefined

private void addOneStepScenario(Stats counter, Status status) {
counter.addStep(status);
counter.addScenario(status, "scenario designation");
counter.addScenario(status, createTestCase("classpath:com/example", 14, "scenario designation"));
}

@Test
Expand Down Expand Up @@ -174,13 +181,13 @@ void should_print_failed_ambiguous_scenarios() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

counter.addStep(Status.FAILED);
counter.addScenario(Status.FAILED, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.FAILED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.AMBIGUOUS);
counter.addScenario(Status.AMBIGUOUS, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.AMBIGUOUS, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.UNDEFINED);
counter.addScenario(Status.UNDEFINED, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.UNDEFINED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.PENDING);
counter.addScenario(Status.PENDING, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.PENDING, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.printStats(new PrintStream(baos));

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

counter.addStep(Status.FAILED);
counter.addScenario(Status.FAILED, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.FAILED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.AMBIGUOUS);
counter.addScenario(Status.AMBIGUOUS, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.AMBIGUOUS, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.UNDEFINED);
counter.addScenario(Status.UNDEFINED, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.UNDEFINED, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.addStep(Status.PENDING);
counter.addScenario(Status.PENDING, "path/file.feature:3 # Scenario: scenario_name");
counter.addScenario(Status.PENDING, createTestCase("path/file.feature", 3, "Scenario: scenario_name"));
counter.printStats(new PrintStream(baos));

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

private static TestCase createTestCase(String uri, int line, String name) {
return new TestCase() {
@Override
public Integer getLine() {
return getLocation().getLine();
}

@Override
public Location getLocation() {
return new Location(line, -1);
}

@Override
public String getKeyword() {
return "Scenario";
}

@Override
public String getName() {
return name;
}

@Override
public String getScenarioDesignation() {
return null;
}

@Override
public List<String> getTags() {
return Collections.emptyList();
}

@Override
public List<TestStep> getTestSteps() {
return Collections.emptyList();
}

@Override
public URI getUri() {
return URI.create(uri);
}

@Override
public UUID getId() {
return UUID.randomUUID();
}
};
}

}