Skip to content

Commit

Permalink
[Core] Print warning when using --non-strict (#1835)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mpkorstanje authored Dec 6, 2019
1 parent 6a5573e commit 79e7c9d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/io/cucumber/core/cli/Main.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion junit/src/main/java/io/cucumber/junit/Cucumber.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -78,6 +81,9 @@
*/
@API(status = API.Status.STABLE)
public final class Cucumber extends ParentRunner<ParentRunner<?>> {

private static final Logger log = LoggerFactory.getLogger(Cucumber.class);

private final List<ParentRunner<?>> children;
private final EventBus bus;
private final List<CucumberFeature> features;
Expand All @@ -91,7 +97,7 @@ public final class Cucumber extends ParentRunner<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);

Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
<item>.* io.cucumber.java8.DefaultParameterTransformerBody.*</item>
<item>.* io.cucumber.java8.LambdaGlue::DefaultParameterTransformer.*</item>
<item>.* io.cucumber.java8.LambdaGlue::DefaultDataTableEntryTransformer.*</item>
<item>.* io.cucumber.testng.TestNGCucumberRunner.*</item>
</exclude>
</elements>
</revapi.filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CucumberPickle> filters;
private final ThreadLocalRunnerSupplier runnerSupplier;
Expand All @@ -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())
Expand All @@ -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> classLoader = ClassLoaders::getDefaultClassLoader;
featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions);

Expand Down

0 comments on commit 79e7c9d

Please sign in to comment.