Skip to content

Commit 507f1ec

Browse files
committed
[Core] Print warning when using --non-strict
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
1 parent 6a5573e commit 507f1ec

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

core/src/main/java/io/cucumber/core/cli/Main.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.cucumber.core.cli;
22

3+
import io.cucumber.core.logging.Logger;
4+
import io.cucumber.core.logging.LoggerFactory;
35
import io.cucumber.core.options.CommandlineOptionsParser;
46
import io.cucumber.core.options.Constants;
57
import io.cucumber.core.options.CucumberProperties;
@@ -23,6 +25,8 @@
2325
@API(status = API.Status.STABLE)
2426
public class Main {
2527

28+
private static final Logger log = LoggerFactory.getLogger(Main.class);
29+
2630
public static void main(String... argv) {
2731
byte exitStatus = run(argv, Thread.currentThread().getContextClassLoader());
2832
System.exit(exitStatus);
@@ -54,6 +58,12 @@ public static byte run(String[] argv, ClassLoader classLoader) {
5458
.addDefaultSummaryPrinterIfAbsent()
5559
.build(systemOptions);
5660

61+
if (!runtimeOptions.isStrict()) {
62+
log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" +
63+
"This default will change to --strict and --non-strict will be removed.\n" +
64+
"You can use --strict to suppress this warning"
65+
);
66+
}
5767

5868
final Runtime runtime = Runtime.builder()
5969
.withRuntimeOptions(runtimeOptions)

junit/src/main/java/io/cucumber/junit/Cucumber.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package io.cucumber.junit;
22

3+
import io.cucumber.core.cli.Main;
34
import io.cucumber.core.eventbus.EventBus;
45
import io.cucumber.core.feature.CucumberFeature;
56
import io.cucumber.core.feature.CucumberPickle;
67
import io.cucumber.core.filter.Filters;
8+
import io.cucumber.core.logging.Logger;
9+
import io.cucumber.core.logging.LoggerFactory;
710
import io.cucumber.core.options.Constants;
811
import io.cucumber.core.options.CucumberOptionsAnnotationParser;
912
import io.cucumber.core.options.CucumberProperties;
@@ -78,6 +81,9 @@
7881
*/
7982
@API(status = API.Status.STABLE)
8083
public final class Cucumber extends ParentRunner<ParentRunner<?>> {
84+
85+
private static final Logger log = LoggerFactory.getLogger(Cucumber.class);
86+
8187
private final List<ParentRunner<?>> children;
8288
private final EventBus bus;
8389
private final List<CucumberFeature> features;
@@ -91,7 +97,7 @@ public final class Cucumber extends ParentRunner<ParentRunner<?>> {
9197
* @param clazz the class with the @RunWith annotation.
9298
* @throws org.junit.runners.model.InitializationError if there is another problem
9399
*/
94-
public Cucumber(Class clazz) throws InitializationError {
100+
public Cucumber(Class<?> clazz) throws InitializationError {
95101
super(clazz);
96102
Assertions.assertNoCucumberAnnotatedMethods(clazz);
97103

@@ -114,6 +120,14 @@ public Cucumber(Class clazz) throws InitializationError {
114120
.addDefaultSummaryPrinterIfAbsent()
115121
.build(environmentOptions);
116122

123+
124+
if (!runtimeOptions.isStrict()) {
125+
log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" +
126+
"This default will change to --strict and --non-strict will be removed.\n" +
127+
"You can use --strict or @CucumberOptions(strict = true) to suppress this warning"
128+
);
129+
}
130+
117131
// Next parse the junit options
118132
JUnitOptions junitPropertiesFileOptions = new JUnitOptionsParser()
119133
.parse(CucumberProperties.fromPropertiesFile())

testng/src/main/java/io/cucumber/testng/TestNGCucumberRunner.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import io.cucumber.core.feature.CucumberFeature;
66
import io.cucumber.core.feature.CucumberPickle;
77
import io.cucumber.core.filter.Filters;
8+
import io.cucumber.core.logging.Logger;
9+
import io.cucumber.core.logging.LoggerFactory;
810
import io.cucumber.core.options.Constants;
911
import io.cucumber.core.options.CucumberOptionsAnnotationParser;
1012
import io.cucumber.core.options.CucumberProperties;
@@ -50,6 +52,8 @@
5052
@API(status = API.Status.STABLE)
5153
public final class TestNGCucumberRunner {
5254

55+
private static final Logger log = LoggerFactory.getLogger(TestNGCucumberRunner.class);
56+
5357
private final EventBus bus;
5458
private final Predicate<CucumberPickle> filters;
5559
private final ThreadLocalRunnerSupplier runnerSupplier;
@@ -63,7 +67,7 @@ public final class TestNGCucumberRunner {
6367
* @param clazz Which has the {@link CucumberOptions}
6468
* and {@link org.testng.annotations.Test} annotations
6569
*/
66-
public TestNGCucumberRunner(Class clazz) {
70+
public TestNGCucumberRunner(Class<?> clazz) {
6771
// Parse the options early to provide fast feedback about invalid options
6872
RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser()
6973
.parse(CucumberProperties.fromPropertiesFile())
@@ -83,6 +87,14 @@ public TestNGCucumberRunner(Class clazz) {
8387
.addDefaultSummaryPrinterIfAbsent()
8488
.build(environmentOptions);
8589

90+
91+
if (!runtimeOptions.isStrict()) {
92+
log.warn(() -> "By default Cucumber is running in --non-strict mode.\n" +
93+
"This default will change to --strict and --non-strict will be removed.\n" +
94+
"You can use --strict or @CucumberOptions(strict = true) to suppress this warning"
95+
);
96+
}
97+
8698
Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
8799
featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions);
88100

0 commit comments

Comments
 (0)