From 7bfaac5cafc9cd592139227b53241093379d2bdd Mon Sep 17 00:00:00 2001 From: mpkorstanje Date: Thu, 10 Dec 2020 15:49:48 +0100 Subject: [PATCH] [Core] Add space between scenario url and name The summary printer concatenated the url and scenario name without an additional space. This made it impossible to click the urls. Fixes: https://github.com/cucumber/cucumber-jvm/issues/2184 --- CHANGELOG.md | 1 + .../java/io/cucumber/core/plugin/Stats.java | 33 ++++---- .../io/cucumber/core/plugin/StatsTest.java | 76 ++++++++++++++++--- 3 files changed, 81 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f121985d6..4a35dd903f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/core/src/main/java/io/cucumber/core/plugin/Stats.java b/core/src/main/java/io/cucumber/core/plugin/Stats.java index 4fe80625f7..6cecc731b3 100755 --- a/core/src/main/java/io/cucumber/core/plugin/Stats.java +++ b/core/src/main/java/io/cucumber/core/plugin/Stats.java @@ -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 failedScenarios = new ArrayList<>(); - private final List ambiguousScenarios = new ArrayList<>(); - private final List pendingScenarios = new ArrayList<>(); - private final List undefinedScenarios = new ArrayList<>(); + private final List failedScenarios = new ArrayList<>(); + private final List ambiguousScenarios = new ArrayList<>(); + private final List pendingScenarios = new ArrayList<>(); + private final List undefinedScenarios = new ArrayList<>(); private final List errors = new ArrayList<>(); private Instant startTime = Instant.EPOCH; private Duration totalDuration = Duration.ZERO; @@ -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) { @@ -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 @@ -207,17 +205,14 @@ private void printNonZeroResultScenarios(PrintStream out) { printScenarios(out, undefinedScenarios, Status.UNDEFINED); } - private void printScenarios(PrintStream out, List scenarios, Status type) { + private void printScenarios(PrintStream out, List 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(); diff --git a/core/src/test/java/io/cucumber/core/plugin/StatsTest.java b/core/src/test/java/io/cucumber/core/plugin/StatsTest.java index e9571138c5..3d5cc65cf9 100755 --- a/core/src/test/java/io/cucumber/core/plugin/StatsTest.java +++ b/core/src/test/java/io/cucumber/core/plugin/StatsTest.java @@ -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; @@ -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( @@ -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 @@ -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("" + @@ -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("" + @@ -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 getTags() { + return Collections.emptyList(); + } + + @Override + public List getTestSteps() { + return Collections.emptyList(); + } + + @Override + public URI getUri() { + return URI.create(uri); + } + + @Override + public UUID getId() { + return UUID.randomUUID(); + } + }; + } + }