Skip to content

Commit e0af6f8

Browse files
committed
[Core] Indent write events in PrettyFormatter (#1809)
Closes: #1809 Squashed commit of the following: commit d77448dd64e8432b70b3a0c44b7e46c7b61f1b36 Merge: be92824 cb57d8c Author: M.P. Korstanje <[email protected]> Date: Thu Oct 17 18:24:08 2019 +0200 Merge branch 'indent' of https://github.com/alexandreonterroso/cucumber-jvm into alexandreonterroso-indent commit cb57d8c Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 17:46:57 2019 +0200 Indent with spaces commit 819ec9b Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 15:48:55 2019 +0200 indentation commit 4dfb464 Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 15:16:06 2019 +0200 Correct indentation commit 0d4abbe Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 15:11:10 2019 +0200 Avoid repetition commit 0687c9a Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 15:01:27 2019 +0200 Auto-closeable buffer commit beb16b2 Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 14:54:48 2019 +0200 Add some indentation commit 00c01db Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 14:54:20 2019 +0200 Add some indentation commit 8d35ec4 Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 14:53:13 2019 +0200 Multi-lines Strings commit 530265b Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 14:12:31 2019 +0200 Add some indentation commit f59ee85 Author: alexandre.monterroso <[email protected]> Date: Thu Oct 17 14:09:58 2019 +0200 Add some indentation
1 parent be92824 commit e0af6f8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import gherkin.ast.ScenarioOutline;
88
import gherkin.ast.Step;
99
import gherkin.ast.Tag;
10+
import io.cucumber.core.exception.CucumberException;
1011
import io.cucumber.plugin.ColorAware;
1112
import io.cucumber.plugin.EventListener;
1213
import io.cucumber.plugin.event.Argument;
@@ -22,7 +23,10 @@
2223
import io.cucumber.plugin.event.TestStepStarted;
2324
import io.cucumber.plugin.event.WriteEvent;
2425

26+
import java.io.BufferedReader;
27+
import java.io.IOException;
2528
import java.io.PrintWriter;
29+
import java.io.StringReader;
2630
import java.io.StringWriter;
2731
import java.net.URI;
2832
import java.util.List;
@@ -34,6 +38,7 @@ public final class PrettyFormatter implements EventListener, ColorAware {
3438
private static final String SCENARIO_INDENT = " ";
3539
private static final String STEP_INDENT = " ";
3640
private static final String EXAMPLES_INDENT = " ";
41+
private static final String STEP_SCENARIO_INDENT = " ";
3742
private final TestSourcesModel testSources = new TestSourcesModel();
3843
private final NiceAppendable out;
3944
private Formats formats;
@@ -100,7 +105,17 @@ private void handleTestStepFinished(TestStepFinished event) {
100105
}
101106

102107
private void handleWrite(WriteEvent event) {
103-
out.println(event.getText());
108+
out.println();
109+
try(BufferedReader lines = new BufferedReader(new StringReader(event.getText()))) {
110+
String line;
111+
while ((line = lines.readLine()) != null) {
112+
out.println(STEP_SCENARIO_INDENT + line);
113+
}
114+
} catch (IOException e) {
115+
throw new CucumberException(e);
116+
}
117+
out.println();
118+
104119
}
105120

106121
private void finishReport() {

examples/java-calculator/src/test/java/io/cucumber/examples/java/RpnCalculatorSteps.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void before(Scenario scenario) {
4343

4444
@After
4545
public void after(Scenario scenario) {
46-
// result.write("HELLLLOO");
46+
// scenario.write("HELLLLOO");
4747
}
4848

4949
@Given("the previous entries:")

examples/java-calculator/src/test/java/io/cucumber/examples/java/RunCucumberTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.junit.runner.RunWith;
66

77
@RunWith(Cucumber.class)
8-
@CucumberOptions(plugin = {"json:target/cucumber-report.json"})
8+
@CucumberOptions(plugin = {"json:target/cucumber-report.json", "pretty"})
99
public class RunCucumberTest {
1010

1111
}

0 commit comments

Comments
 (0)