1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.its;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.maven.surefire.its.fixture.MavenLauncher;
25 import org.apache.maven.surefire.its.fixture.OutputValidator;
26 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27 import org.junit.jupiter.params.ParameterizedTest;
28 import org.junit.jupiter.params.provider.MethodSource;
29
30 import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion;
31 import static org.hamcrest.Matchers.containsString;
32 import static org.hamcrest.Matchers.equalTo;
33
34
35
36
37
38
39
40 public abstract class AbstractFailFastIT extends SurefireJUnit4IntegrationTestCase {
41 private static final String LEGACY_FORK_NODE = "org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory";
42
43 private static final String SUREFIRE_FORK_NODE =
44 "org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory";
45
46 protected abstract String withProvider();
47
48 private OutputValidator prepare(
49 String description,
50 String profile,
51 Map<String, String> properties,
52 boolean useProcessPipes,
53 int failures,
54 int errors) {
55 MavenLauncher launcher = unpack("/fail-fast-" + withProvider(), "_" + description)
56 .maven()
57 .debugLogging();
58
59 if (profile != null) {
60 launcher.activateProfile(profile);
61 }
62
63 if (!useProcessPipes) {
64 launcher.activateProfile("tcp");
65 }
66
67 if (failures != 0 || errors != 0) {
68 launcher.withFailure();
69 }
70
71 return launcher.sysProp(properties).executeTest();
72 }
73
74 static Map<String, String> props(int forkCount, int skipAfterFailureCount, boolean reuseForks) {
75 Map<String, String> props = new HashMap<>(3);
76 props.put("surefire.skipAfterFailureCount", "" + skipAfterFailureCount);
77 props.put("forkCount", "" + forkCount);
78 props.put("reuseForks", "" + reuseForks);
79 return props;
80 }
81
82 @ParameterizedTest(name = "{0}")
83 @MethodSource("data")
84 void test(
85 String description,
86 String profile,
87 Map<String, String> properties,
88 int total,
89 int failures,
90 int errors,
91 int skipped,
92 boolean useProcessPipes)
93 throws Exception {
94
95 assumeJavaVersion(17);
96 String cls = useProcessPipes ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
97 OutputValidator validator = prepare(description, profile, properties, useProcessPipes, failures, errors);
98 validator
99 .assertTestSuiteResults(total, errors, failures, skipped)
100 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
101 performExtraChecks(validator);
102 }
103
104 protected void performExtraChecks(OutputValidator validator) throws Exception {
105
106 }
107 }