From 6b34d6a5cac1d770a6e2b5122aafaa543507a03e Mon Sep 17 00:00:00 2001 From: Arty <26905074+artysidorenko@users.noreply.github.com> Date: Sun, 4 Jul 2021 21:43:17 +0100 Subject: [PATCH 1/3] update PrettyFormatter to print table --- .../cucumber/core/plugin/PrettyFormatter.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java b/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java index 1caed6f449..65be9937ba 100644 --- a/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java +++ b/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java @@ -1,6 +1,9 @@ package io.cucumber.core.plugin; import io.cucumber.core.exception.CucumberException; +import io.cucumber.core.gherkin.DataTableArgument; +import io.cucumber.datatable.DataTable; +import io.cucumber.datatable.DataTableFormatter; import io.cucumber.plugin.ColorAware; import io.cucumber.plugin.ConcurrentEventListener; import io.cucumber.plugin.event.Argument; @@ -8,6 +11,7 @@ import io.cucumber.plugin.event.EventPublisher; import io.cucumber.plugin.event.PickleStepTestStep; import io.cucumber.plugin.event.Result; +import io.cucumber.plugin.event.StepArgument; import io.cucumber.plugin.event.TestCase; import io.cucumber.plugin.event.TestCaseStarted; import io.cucumber.plugin.event.TestRunFinished; @@ -128,6 +132,21 @@ private void printStep(TestStepFinished event) { formats.get(status + "_arg"), testStep.getDefinitionArgument()); String locationIndent = calculateLocationIndent(event.getTestCase(), formatPlainStep(keyword, stepText)); out.println(STEP_INDENT + formattedStepText + locationIndent + formatLocation(testStep.getCodeLocation())); + + StepArgument stepArgument = testStep.getStep().getArgument(); + if (DataTableArgument.class.isInstance(stepArgument)) { + DataTableFormatter tableFormatter = DataTableFormatter + .builder() + .prefixRow(STEP_SCENARIO_INDENT) + .escapeDelimiters(false) + .build(); + DataTableArgument dataTableArgument = (DataTableArgument) stepArgument; + try { + tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out); + } catch (IOException e) { + throw new CucumberException(e); + } + } } } From 55eaa327db9879229bd98e39850aa9b5e765e6b5 Mon Sep 17 00:00:00 2001 From: Arty <26905074+artysidorenko@users.noreply.github.com> Date: Sun, 4 Jul 2021 21:43:33 +0100 Subject: [PATCH 2/3] add 2 tests --- .../core/plugin/PrettyFormatterTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java b/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java index c1f032c15f..a76eededa8 100755 --- a/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java +++ b/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java @@ -15,6 +15,7 @@ import io.cucumber.core.stepexpression.StepExpression; import io.cucumber.core.stepexpression.StepExpressionFactory; import io.cucumber.core.stepexpression.StepTypeRegistry; +import io.cucumber.datatable.DataTable; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -174,6 +175,75 @@ void should_print_tags() { " Then second step # path/step_definitions.java:11\n")); } + @Test + void should_print_table() { + Feature feature = TestFeatureParser.parse("path/test.feature", "" + + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " | key1 | key2 |\n" + + " | value1 | value2 |\n" + + " | another1 | another2 |\n"); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Runtime.builder() + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class))) + .build() + .run(); + + assertThat(out, isBytesEqualTo("" + + + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " | key1 | key2 |\n" + + " | value1 | value2 |\n" + + " | another1 | another2 |\n")); + } + + @Test + void should_print_multiple_tables() { + Feature feature = TestFeatureParser.parse("path/test.feature", "" + + "Feature: Test feature\n" + + " Scenario: Test Scenario\n" + + " Given first step\n" + + " | key1 | key2 |\n" + + " | value1 | value2 |\n" + + " | another1 | another2 |\n" + + " Given second step\n" + + " | key3 | key4 |\n" + + " | value3 | value4 |\n" + + " | another3 | another4 |\n"); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Runtime.builder() + .withFeatureSupplier(new StubFeatureSupplier(feature)) + .withAdditionalPlugins(new PrettyFormatter(out)) + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) + .withBackendSupplier(new StubBackendSupplier( + new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class), + new StubStepDefinition("second step", "path/step_definitions.java:15", DataTable.class))) + .build() + .run(); + + assertThat(out, isBytesEqualTo("" + + + "\n" + + "Scenario: Test Scenario # path/test.feature:2\n" + + " Given first step # path/step_definitions.java:7\n" + + " | key1 | key2 |\n" + + " | value1 | value2 |\n" + + " | another1 | another2 |\n" + + " Given second step # path/step_definitions.java:15\n" + + " | key3 | key4 |\n" + + " | value3 | value4 |\n" + + " | another3 | another4 |\n")); + } + @Test void should_print_error_message_for_failed_steps() { Feature feature = TestFeatureParser.parse("path/test.feature", "" + From d7143ce041e2d5421f1e1562350905d3ac369590 Mon Sep 17 00:00:00 2001 From: Arty <26905074+artysidorenko@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:42:27 +0100 Subject: [PATCH 3/3] fix compatiblity test: non-deterministic comparison order --- .../test/java/io/cucumber/compatibility/CompatibilityTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compatibility/src/test/java/io/cucumber/compatibility/CompatibilityTest.java b/compatibility/src/test/java/io/cucumber/compatibility/CompatibilityTest.java index 00aa0cb896..afc087007d 100644 --- a/compatibility/src/test/java/io/cucumber/compatibility/CompatibilityTest.java +++ b/compatibility/src/test/java/io/cucumber/compatibility/CompatibilityTest.java @@ -114,7 +114,8 @@ private static Map> openEnvelopes(List actual) { } private void sortStepDefinitions(Map> envelopes) { - Comparator stepDefinitionPatternComparator = Comparator.comparing(a -> a.get("pattern").asText()); + Comparator stepDefinitionPatternComparator = Comparator + .comparing(a -> a.get("pattern").get("source").asText()); List actualStepDefinitions = envelopes.get("stepDefinition"); if (actualStepDefinitions != null) { actualStepDefinitions.sort(stepDefinitionPatternComparator);