Skip to content

Commit 300d2b1

Browse files
committed
Include hooks in progress formatter
1 parent abc5d96 commit 300d2b1

File tree

2 files changed

+4
-25
lines changed

2 files changed

+4
-25
lines changed

cucumber-core/src/main/java/io/cucumber/core/plugin/ProgressFormatter.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package io.cucumber.core.plugin;
22

33
import io.cucumber.messages.types.Envelope;
4-
import io.cucumber.messages.types.TestCase;
54
import io.cucumber.messages.types.TestRunFinished;
6-
import io.cucumber.messages.types.TestStep;
75
import io.cucumber.messages.types.TestStepFinished;
86
import io.cucumber.messages.types.TestStepResultStatus;
97
import io.cucumber.plugin.ColorAware;
@@ -15,7 +13,6 @@
1513
import java.io.PrintWriter;
1614
import java.nio.charset.StandardCharsets;
1715
import java.util.EnumMap;
18-
import java.util.HashMap;
1916
import java.util.Map;
2017

2118
import static io.cucumber.messages.types.TestStepResultStatus.AMBIGUOUS;
@@ -28,15 +25,14 @@
2825

2926
public final class ProgressFormatter implements ConcurrentEventListener, ColorAware {
3027

31-
private final Map<String, TestStep> testStepById = new HashMap<>();
3228
private final Map<TestStepResultStatus, String> chars = new EnumMap<>(TestStepResultStatus.class);
3329
private final Map<TestStepResultStatus, AnsiEscapes> escapes = new EnumMap<>(TestStepResultStatus.class);
3430
private final PrintWriter writer;
3531
private boolean monochrome = false;
36-
32+
3733
public ProgressFormatter(OutputStream out) {
3834
this.writer = createPrintWriter(out);
39-
35+
4036
chars.put(PASSED, ".");
4137
chars.put(UNDEFINED, "U");
4238
chars.put(PENDING, "P");
@@ -69,20 +65,12 @@ public void setMonochrome(boolean monochrome) {
6965
@Override
7066
public void setEventPublisher(EventPublisher publisher) {
7167
publisher.registerHandlerFor(Envelope.class, event -> {
72-
event.getTestCase().ifPresent(this::updateTestCase);
7368
event.getTestStepFinished().ifPresent(this::handleTestStepFinished);
7469
event.getTestRunFinished().ifPresent(this::handleTestRunFinished);
7570
});
7671
}
7772

78-
private void updateTestCase(TestCase event) {
79-
event.getTestSteps().forEach(testStep -> testStepById.put(testStep.getId(), testStep));
80-
}
81-
8273
private void handleTestStepFinished(TestStepFinished event) {
83-
if (!includeStep(event)) {
84-
return;
85-
}
8674
TestStepResultStatus status = event.getTestStepResult().getStatus();
8775
// Prevent tearing in output when multiple threads write to System.out
8876
StringBuilder buffer = new StringBuilder();
@@ -97,15 +85,6 @@ private void handleTestStepFinished(TestStepFinished event) {
9785
writer.flush();
9886
}
9987

100-
private boolean includeStep(TestStepFinished testStepFinished) {
101-
TestStepResultStatus status = testStepFinished.getTestStepResult().getStatus();
102-
if (status == FAILED) {
103-
return true;
104-
}
105-
TestStep testStep = testStepById.get(testStepFinished.getTestStepId());
106-
return testStep != null && testStep.getPickleStepId().isPresent();
107-
}
108-
10988
private void handleTestRunFinished(TestRunFinished testRunFinished) {
11089
writer.println();
11190
writer.close();

cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void print_yellow_U_for_undefined_step() {
7272
}
7373

7474
@Test
75-
void print_nothing_for_passed_hook() {
75+
void prints_passed_hook() {
7676
Feature feature = TestFeatureParser.parse("classpath:path/test.feature", "" +
7777
"Feature: feature name\n" +
7878
" Scenario: passed scenario\n" +
@@ -89,7 +89,7 @@ void print_nothing_for_passed_hook() {
8989
.build()
9090
.run();
9191

92-
assertThat(out, bytes(equalCompressingLineSeparators(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n")));
92+
assertThat(out, bytes(equalCompressingLineSeparators(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n")));
9393
}
9494

9595
@Test

0 commit comments

Comments
 (0)