Skip to content

Commit 5b8af1f

Browse files
committed
Merge #1187 'Use cucumber-ruby rerun file specification'
Also update History.md.
2 parents 11cd8ea + e52fc4f commit 5b8af1f

File tree

4 files changed

+81
-15
lines changed

4 files changed

+81
-15
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [2.0.0-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.5...master) (In Git)
22

3+
* [Core] Make the parsing of the rerun file more robust ([#1187](https://github.com/cucumber/cucumber-jvm/pull/1187) M.P. Korstanje)
34
* [Android] Update the version of the cucumber-jvm-deps dependency - to a version without Java8 bytecode ([#1170](https://github.com/cucumber/cucumber-jvm/pull/1170), [#893](https://github.com/cucumber/cucumber-jvm/issues/893) Björn Rasmusson)
45
* [Needle] Handle circular dependencies ([#853](https://github.com/cucumber/cucumber-jvm/pull/853) Lars Bilger)
56
* [Core] Use "uri" instead of "path" to reference feature files in externa APIs ([#1179](https://github.com/cucumber/cucumber-jvm/pull/1179) Björn Rasmusson)

core/src/main/java/cucumber/runtime/RuntimeOptions.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ public Map<String, List<Long>> getLineFilters(ResourceLoader resourceLoader) {
444444
private void processRerunFiles(ResourceLoader resourceLoader) {
445445
for (String featurePath : featurePaths) {
446446
if (featurePath.startsWith("@")) {
447-
for (String path : CucumberFeature.loadRerunFile(resourceLoader, featurePath.substring(1))) {
448-
PathWithLines pathWithLines = new PathWithLines(path);
447+
for (PathWithLines pathWithLines : CucumberFeature.loadRerunFile(resourceLoader, featurePath.substring(1))) {
449448
addLineFilters(lineFilters, pathWithLines.path, pathWithLines.lines);
450449
}
451450
}

core/src/main/java/cucumber/runtime/model/CucumberFeature.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
import java.io.PrintStream;
1515
import java.io.Serializable;
1616
import java.util.ArrayList;
17-
import java.util.Arrays;
1817
import java.util.Collections;
1918
import java.util.Comparator;
2019
import java.util.List;
20+
import java.util.regex.Matcher;
21+
import java.util.regex.Pattern;
2122

2223
public class CucumberFeature implements Serializable {
2324
private static final long serialVersionUID = 1L;
2425
private final String uri;
2526
private String language;
2627
private GherkinDocument gherkinDocument;
2728
private String gherkinSource;
29+
public static final Pattern RERUN_PATH_SPECIFICATION = Pattern.compile("(?m:^| |)(.*?\\.feature(?:(?::\\d+)*))");
2830

2931
public static List<CucumberFeature> load(ResourceLoader resourceLoader, List<String> featurePaths, PrintStream out) {
3032
final List<CucumberFeature> cucumberFeatures = load(resourceLoader, featurePaths);
@@ -53,25 +55,21 @@ public static List<CucumberFeature> load(ResourceLoader resourceLoader, List<Str
5355
}
5456

5557
private static void loadFromRerunFile(FeatureBuilder builder, ResourceLoader resourceLoader, String rerunPath) {
56-
Iterable<Resource> resources = resourceLoader.resources(rerunPath, null);
57-
for (Resource resource : resources) {
58-
String source = read(resource);
59-
if (!source.isEmpty()) {
60-
for (String featurePath : source.split("[\r\n]+")) {
61-
PathWithLines pathWithLines = new PathWithLines(featurePath);
62-
loadFromFileSystemOrClasspath(builder, resourceLoader, pathWithLines.path);
63-
}
64-
}
58+
for(PathWithLines pathWithLines : loadRerunFile(resourceLoader, rerunPath)){
59+
loadFromFileSystemOrClasspath(builder, resourceLoader, pathWithLines.path);
6560
}
6661
}
6762

68-
public static List<String> loadRerunFile(ResourceLoader resourceLoader, String rerunPath) {
69-
List<String> featurePaths = new ArrayList<String>();
63+
public static List<PathWithLines> loadRerunFile(ResourceLoader resourceLoader, String rerunPath) {
64+
List<PathWithLines> featurePaths = new ArrayList<PathWithLines>();
7065
Iterable<Resource> resources = resourceLoader.resources(rerunPath, null);
7166
for (Resource resource : resources) {
7267
String source = read(resource);
7368
if (!source.isEmpty()) {
74-
featurePaths.addAll(Arrays.asList(source.split(" ")));
69+
Matcher matcher = RERUN_PATH_SPECIFICATION.matcher(source);
70+
while(matcher.find()){
71+
featurePaths.add(new PathWithLines(matcher.group(1)));
72+
}
7573
}
7674
}
7775
return featurePaths;

core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java

+68
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,74 @@ public void understands_whitespace_in_rerun_filepath() throws Exception {
259259
assertEquals("scenario bar", features.get(0).getGherkinFeature().getFeature().getChildren().get(0).getName());
260260
}
261261

262+
263+
@Test
264+
public void understands_rerun_files_separated_by_with_whitespace() throws Exception {
265+
String featurePath1 = "/home/users/mp/My Documents/tests/bar.feature";
266+
String feature1 = "" +
267+
"Feature: bar\n" +
268+
" Scenario: scenario bar\n" +
269+
" * step\n";
270+
String featurePath2 = "/home/users/mp/My Documents/tests/foo.feature";
271+
String feature2 = "" +
272+
"Feature: foo\n" +
273+
" Scenario: scenario 1\n" +
274+
" * step\n" +
275+
" Scenario: scenario 2\n" +
276+
" * step\n";
277+
String rerunPath = "path/rerun.txt";
278+
String rerunFile = featurePath1 + ":2 " + featurePath2 + ":4";
279+
ResourceLoader resourceLoader = mockFeatureFileResource(featurePath1, feature1);
280+
mockFeatureFileResource(resourceLoader, featurePath2, feature2);
281+
mockFileResource(resourceLoader, rerunPath, null, rerunFile);
282+
283+
List<CucumberFeature> features = CucumberFeature.load(
284+
resourceLoader,
285+
singletonList("@" + rerunPath),
286+
new PrintStream(new ByteArrayOutputStream()));
287+
288+
assertEquals(2, features.size());
289+
assertEquals(1, features.get(0).getGherkinFeature().getFeature().getChildren().size());
290+
assertEquals("scenario bar", features.get(0).getGherkinFeature().getFeature().getChildren().get(0).getName());
291+
assertEquals(2, features.get(1).getGherkinFeature().getFeature().getChildren().size());
292+
assertEquals("scenario 1", features.get(1).getGherkinFeature().getFeature().getChildren().get(0).getName());
293+
assertEquals("scenario 2", features.get(1).getGherkinFeature().getFeature().getChildren().get(1).getName());
294+
}
295+
296+
297+
@Test
298+
public void understands_rerun_files_without_separation_in_rerun_filepath() throws Exception {
299+
String featurePath1 = "/home/users/mp/My Documents/tests/bar.feature";
300+
String feature1 = "" +
301+
"Feature: bar\n" +
302+
" Scenario: scenario bar\n" +
303+
" * step\n";
304+
String featurePath2 = "/home/users/mp/My Documents/tests/foo.feature";
305+
String feature2 = "" +
306+
"Feature: foo\n" +
307+
" Scenario: scenario 1\n" +
308+
" * step\n" +
309+
" Scenario: scenario 2\n" +
310+
" * step\n";
311+
String rerunPath = "path/rerun.txt";
312+
String rerunFile = featurePath1 + ":2" + featurePath2 + ":4";
313+
ResourceLoader resourceLoader = mockFeatureFileResource(featurePath1, feature1);
314+
mockFeatureFileResource(resourceLoader, featurePath2, feature2);
315+
mockFileResource(resourceLoader, rerunPath, null, rerunFile);
316+
317+
List<CucumberFeature> features = CucumberFeature.load(
318+
resourceLoader,
319+
singletonList("@" + rerunPath),
320+
new PrintStream(new ByteArrayOutputStream()));
321+
322+
assertEquals(2, features.size());
323+
assertEquals(1, features.get(0).getGherkinFeature().getFeature().getChildren().size());
324+
assertEquals("scenario bar", features.get(0).getGherkinFeature().getFeature().getChildren().get(0).getName());
325+
assertEquals(2, features.get(1).getGherkinFeature().getFeature().getChildren().size());
326+
assertEquals("scenario 1", features.get(1).getGherkinFeature().getFeature().getChildren().get(0).getName());
327+
assertEquals("scenario 2", features.get(1).getGherkinFeature().getFeature().getChildren().get(1).getName());
328+
}
329+
262330
private ResourceLoader mockFeatureFileResource(String featurePath, String feature)
263331
throws IOException {
264332
ResourceLoader resourceLoader = mock(ResourceLoader.class);

0 commit comments

Comments
 (0)