Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Read rerun files from directories #2710

Merged
merged 16 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests and clean up code
mpkorstanje committed Apr 5, 2023
commit e2542c84dd8a78ca5c7adfab84073a9dc6d7b8fc
Original file line number Diff line number Diff line change
@@ -7,12 +7,10 @@
import io.cucumber.core.logging.LoggerFactory;
import io.cucumber.tagexpressions.TagExpressionParser;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
@@ -41,7 +39,6 @@
import static io.cucumber.core.options.Constants.PLUGIN_PUBLISH_TOKEN_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.SNIPPET_TYPE_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.WIP_PROPERTY_NAME;
import static io.cucumber.core.options.OptionsFileParser.parseFeatureWithLinesFile;
import static java.util.Arrays.stream;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
@@ -203,31 +200,33 @@ private static <T> Function<String, Collection<T>> splitAndMap(Function<String,
.collect(toList());
}

private static Set<String> listRerunFiles(String path) {
Set<String> fileList = new HashSet<>();
try {
Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (!Files.isDirectory(file)) {
fileList.add(path + "/" + file.getFileName().toString());
}
return FileVisitResult.CONTINUE;
}
});
return fileList;
} catch (IOException ioe) {
throw new RuntimeException("Runtime exception", ioe);
}
}

private static Stream<Collection<FeatureWithLines>> parseRerunFiles(String property) {
if (property.startsWith("@")) {
String pathStr = property.substring(1);
return listRerunFiles(pathStr).stream()
.map(file -> parseFeatureWithLinesFile(Paths.get(pathStr)));
Path path = Path.of(property.substring(1));
return listRerunFiles(path).stream()
.map(OptionsFileParser::parseFeatureWithLinesFile);
}
return Stream.empty();
}

private static Set<Path> listRerunFiles(Path path) {
class FileCollector extends SimpleFileVisitor<Path> {
final Set<Path> files = new HashSet<>();
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (!Files.isDirectory(file)) {
files.add(file);
}
return FileVisitResult.CONTINUE;
}
}

try {
FileCollector collector = new FileCollector();
Files.walkFileTree(path, collector);
return collector.files;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
}
Original file line number Diff line number Diff line change
@@ -227,6 +227,15 @@ void should_parse_rerun_file() throws IOException {
assertThat(options.getFeaturePaths(), containsInAnyOrder(URI.create("classpath:path/to.feature")));
}

@Test
void should_parse_rerun_files() throws IOException {
mockFileResource("classpath:path/to.feature");
mockFileResource("classpath:path/to/other.feature");
properties.put(Constants.FEATURES_PROPERTY_NAME, "@" + temp.toString());
RuntimeOptions options = cucumberPropertiesParser.parse(properties).build();
assertThat(options.getFeaturePaths(), containsInAnyOrder(URI.create("classpath:path/to.feature"), URI.create("classpath:path/to/other.feature")));
}

@Test
void should_parse_rerun_file_and_remove_existing_tag_filters() throws IOException {
RuntimeOptions existing = RuntimeOptions.defaultOptions();