From 79e7c9d15481f685d75284b76e74201a29dd3bde Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Fri, 6 Dec 2019 22:55:31 +0100 Subject: [PATCH] [Core] Print warning when using --non-strict (#1835) Aside from the common `PASSED`, `SKIPPED` and `FAILED` states Cucumber also uses `PENDING`, `UNDEFINED`, `AMBIGUOUS`. This makes mapping a test execution state to a `OK` or `NOK` test run state complicated. By defaulting to `--strict` only `PASSED`, `SKIPPED` are considered `OK`. This makes it easier to integrate tooling with Cucumber. However before we can default to `--strict` all usage should be `--strict`. This PR will print a warning when Cucumber is not ran in `--strict` mode. Part of #1788 --- .../src/main/java/io/cucumber/core/cli/Main.java | 10 ++++++++++ .../main/java/io/cucumber/junit/Cucumber.java | 16 +++++++++++++++- pom.xml | 1 + .../io/cucumber/testng/TestNGCucumberRunner.java | 14 +++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/cucumber/core/cli/Main.java b/core/src/main/java/io/cucumber/core/cli/Main.java index 05476b9313..c7df025492 100644 --- a/core/src/main/java/io/cucumber/core/cli/Main.java +++ b/core/src/main/java/io/cucumber/core/cli/Main.java @@ -1,5 +1,7 @@ package io.cucumber.core.cli; +import io.cucumber.core.logging.Logger; +import io.cucumber.core.logging.LoggerFactory; import io.cucumber.core.options.CommandlineOptionsParser; import io.cucumber.core.options.Constants; import io.cucumber.core.options.CucumberProperties; @@ -23,6 +25,8 @@ @API(status = API.Status.STABLE) public class Main { + private static final Logger log = LoggerFactory.getLogger(Main.class); + public static void main(String... argv) { byte exitStatus = run(argv, Thread.currentThread().getContextClassLoader()); System.exit(exitStatus); @@ -54,6 +58,12 @@ public static byte run(String[] argv, ClassLoader classLoader) { .addDefaultSummaryPrinterIfAbsent() .build(systemOptions); + if (!runtimeOptions.isStrict()) { + log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" + + "This default will change to --strict and --non-strict will be removed.\n" + + "You can use --strict to suppress this warning" + ); + } final Runtime runtime = Runtime.builder() .withRuntimeOptions(runtimeOptions) diff --git a/junit/src/main/java/io/cucumber/junit/Cucumber.java b/junit/src/main/java/io/cucumber/junit/Cucumber.java index bbe67f6f88..606bc4ccff 100644 --- a/junit/src/main/java/io/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/io/cucumber/junit/Cucumber.java @@ -1,9 +1,12 @@ package io.cucumber.junit; +import io.cucumber.core.cli.Main; import io.cucumber.core.eventbus.EventBus; import io.cucumber.core.feature.CucumberFeature; import io.cucumber.core.feature.CucumberPickle; import io.cucumber.core.filter.Filters; +import io.cucumber.core.logging.Logger; +import io.cucumber.core.logging.LoggerFactory; import io.cucumber.core.options.Constants; import io.cucumber.core.options.CucumberOptionsAnnotationParser; import io.cucumber.core.options.CucumberProperties; @@ -78,6 +81,9 @@ */ @API(status = API.Status.STABLE) public final class Cucumber extends ParentRunner> { + + private static final Logger log = LoggerFactory.getLogger(Cucumber.class); + private final List> children; private final EventBus bus; private final List features; @@ -91,7 +97,7 @@ public final class Cucumber extends ParentRunner> { * @param clazz the class with the @RunWith annotation. * @throws org.junit.runners.model.InitializationError if there is another problem */ - public Cucumber(Class clazz) throws InitializationError { + public Cucumber(Class clazz) throws InitializationError { super(clazz); Assertions.assertNoCucumberAnnotatedMethods(clazz); @@ -114,6 +120,14 @@ public Cucumber(Class clazz) throws InitializationError { .addDefaultSummaryPrinterIfAbsent() .build(environmentOptions); + + if (!runtimeOptions.isStrict()) { + log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" + + "This default will change to --strict and --non-strict will be removed.\n" + + "You can use --strict or @CucumberOptions(strict = true) to suppress this warning" + ); + } + // Next parse the junit options JUnitOptions junitPropertiesFileOptions = new JUnitOptionsParser() .parse(CucumberProperties.fromPropertiesFile()) diff --git a/pom.xml b/pom.xml index 5c9478e4f3..8dfb23e260 100644 --- a/pom.xml +++ b/pom.xml @@ -361,6 +361,7 @@ .* io.cucumber.java8.DefaultParameterTransformerBody.* .* io.cucumber.java8.LambdaGlue::DefaultParameterTransformer.* .* io.cucumber.java8.LambdaGlue::DefaultDataTableEntryTransformer.* + .* io.cucumber.testng.TestNGCucumberRunner.* diff --git a/testng/src/main/java/io/cucumber/testng/TestNGCucumberRunner.java b/testng/src/main/java/io/cucumber/testng/TestNGCucumberRunner.java index ff9fa994db..361dc59cd1 100644 --- a/testng/src/main/java/io/cucumber/testng/TestNGCucumberRunner.java +++ b/testng/src/main/java/io/cucumber/testng/TestNGCucumberRunner.java @@ -5,6 +5,8 @@ import io.cucumber.core.feature.CucumberFeature; import io.cucumber.core.feature.CucumberPickle; import io.cucumber.core.filter.Filters; +import io.cucumber.core.logging.Logger; +import io.cucumber.core.logging.LoggerFactory; import io.cucumber.core.options.Constants; import io.cucumber.core.options.CucumberOptionsAnnotationParser; import io.cucumber.core.options.CucumberProperties; @@ -50,6 +52,8 @@ @API(status = API.Status.STABLE) public final class TestNGCucumberRunner { + private static final Logger log = LoggerFactory.getLogger(TestNGCucumberRunner.class); + private final EventBus bus; private final Predicate filters; private final ThreadLocalRunnerSupplier runnerSupplier; @@ -63,7 +67,7 @@ public final class TestNGCucumberRunner { * @param clazz Which has the {@link CucumberOptions} * and {@link org.testng.annotations.Test} annotations */ - public TestNGCucumberRunner(Class clazz) { + public TestNGCucumberRunner(Class clazz) { // Parse the options early to provide fast feedback about invalid options RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser() .parse(CucumberProperties.fromPropertiesFile()) @@ -83,6 +87,14 @@ public TestNGCucumberRunner(Class clazz) { .addDefaultSummaryPrinterIfAbsent() .build(environmentOptions); + + if (!runtimeOptions.isStrict()) { + log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" + + "This default will change to --strict and --non-strict will be removed.\n" + + "You can use --strict or @CucumberOptions(strict = true) to suppress this warning" + ); + } + Supplier classLoader = ClassLoaders::getDefaultClassLoader; featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions);