Skip to content

Commit

Permalink
Add --select-iteration option to ConsoleLauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 31, 2021
1 parent f0cbbcf commit 88918cd
Show file tree
Hide file tree
Showing 6 changed files with 432 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.junit.platform.console.options;

import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -19,6 +18,15 @@
import java.util.Map;

import org.junit.platform.engine.discovery.ClassNameFilter;
import org.junit.platform.engine.discovery.ClassSelector;
import org.junit.platform.engine.discovery.ClasspathResourceSelector;
import org.junit.platform.engine.discovery.DirectorySelector;
import org.junit.platform.engine.discovery.FileSelector;
import org.junit.platform.engine.discovery.IterationSelector;
import org.junit.platform.engine.discovery.MethodSelector;
import org.junit.platform.engine.discovery.ModuleSelector;
import org.junit.platform.engine.discovery.PackageSelector;
import org.junit.platform.engine.discovery.UriSelector;

import picocli.CommandLine;
import picocli.CommandLine.Command;
Expand Down Expand Up @@ -99,11 +107,11 @@ class AvailableOptions {
private boolean scanModulepath2;

@Option(names = { "-o",
"--select-module" }, paramLabel = "NAME", arity = "1", description = "EXPERIMENTAL: Select single module for test discovery. This option can be repeated.")
private List<String> selectedModules = new ArrayList<>();
"--select-module" }, paramLabel = "NAME", arity = "1", converter = SelectorConverter.Module.class, description = "EXPERIMENTAL: Select single module for test discovery. This option can be repeated.")
private List<ModuleSelector> selectedModules = new ArrayList<>();

@Option(names = { "--o", "-select-module" }, arity = "1", hidden = true)
private List<String> selectedModules2 = new ArrayList<>();
@Option(names = { "--o", "-select-module" }, arity = "1", converter = SelectorConverter.Module.class, hidden = true)
private List<ModuleSelector> selectedModules2 = new ArrayList<>();

// --- Selectors -------------------------------------------------------

Expand All @@ -119,53 +127,64 @@ class AvailableOptions {
private List<Path> selectedClasspathEntries2 = new ArrayList<>();

@Option(names = { "-u",
"--select-uri" }, paramLabel = "URI", arity = "1", description = "Select a URI for test discovery. This option can be repeated.")
private List<URI> selectedUris = new ArrayList<>();
"--select-uri" }, paramLabel = "URI", arity = "1", converter = SelectorConverter.Uri.class, description = "Select a URI for test discovery. This option can be repeated.")
private List<UriSelector> selectedUris = new ArrayList<>();

@Option(names = { "--u", "-select-uri" }, arity = "1", hidden = true)
private List<URI> selectedUris2 = new ArrayList<>();
@Option(names = { "--u", "-select-uri" }, arity = "1", hidden = true, converter = SelectorConverter.Uri.class)
private List<UriSelector> selectedUris2 = new ArrayList<>();

@Option(names = { "-f",
"--select-file" }, paramLabel = "FILE", arity = "1", description = "Select a file for test discovery. This option can be repeated.")
private List<String> selectedFiles = new ArrayList<>();
"--select-file" }, paramLabel = "FILE", arity = "1", converter = SelectorConverter.File.class, description = "Select a file for test discovery. This option can be repeated.")
private List<FileSelector> selectedFiles = new ArrayList<>();

@Option(names = { "--f", "-select-file" }, arity = "1", hidden = true)
private List<String> selectedFiles2 = new ArrayList<>();
@Option(names = { "--f", "-select-file" }, arity = "1", hidden = true, converter = SelectorConverter.File.class)
private List<FileSelector> selectedFiles2 = new ArrayList<>();

@Option(names = { "-d",
"--select-directory" }, paramLabel = "DIR", arity = "1", description = "Select a directory for test discovery. This option can be repeated.")
private List<String> selectedDirectories = new ArrayList<>();
"--select-directory" }, paramLabel = "DIR", arity = "1", converter = SelectorConverter.Directory.class, description = "Select a directory for test discovery. This option can be repeated.")
private List<DirectorySelector> selectedDirectories = new ArrayList<>();

@Option(names = { "--d", "-select-directory" }, arity = "1", hidden = true)
private List<String> selectedDirectories2 = new ArrayList<>();
@Option(names = { "--d",
"-select-directory" }, arity = "1", hidden = true, converter = SelectorConverter.Directory.class)
private List<DirectorySelector> selectedDirectories2 = new ArrayList<>();

@Option(names = { "-p",
"--select-package" }, paramLabel = "PKG", arity = "1", description = "Select a package for test discovery. This option can be repeated.")
private List<String> selectedPackages = new ArrayList<>();
"--select-package" }, paramLabel = "PKG", arity = "1", converter = SelectorConverter.Package.class, description = "Select a package for test discovery. This option can be repeated.")
private List<PackageSelector> selectedPackages = new ArrayList<>();

@Option(names = { "--p", "-select-package" }, arity = "1", hidden = true)
private List<String> selectedPackages2 = new ArrayList<>();
@Option(names = { "--p",
"-select-package" }, arity = "1", hidden = true, converter = SelectorConverter.Package.class)
private List<PackageSelector> selectedPackages2 = new ArrayList<>();

@Option(names = { "-c",
"--select-class" }, paramLabel = "CLASS", arity = "1", description = "Select a class for test discovery. This option can be repeated.")
private List<String> selectedClasses = new ArrayList<>();
"--select-class" }, paramLabel = "CLASS", arity = "1", converter = SelectorConverter.Class.class, description = "Select a class for test discovery. This option can be repeated.")
private List<ClassSelector> selectedClasses = new ArrayList<>();

@Option(names = { "--c", "-select-class" }, arity = "1", hidden = true)
private List<String> selectedClasses2 = new ArrayList<>();
@Option(names = { "--c", "-select-class" }, arity = "1", hidden = true, converter = SelectorConverter.Class.class)
private List<ClassSelector> selectedClasses2 = new ArrayList<>();

@Option(names = { "-m",
"--select-method" }, paramLabel = "NAME", arity = "1", description = "Select a method for test discovery. This option can be repeated.")
private List<String> selectedMethods = new ArrayList<>();
"--select-method" }, paramLabel = "NAME", arity = "1", converter = SelectorConverter.Method.class, description = "Select a method for test discovery. This option can be repeated.")
private List<MethodSelector> selectedMethods = new ArrayList<>();

@Option(names = { "--m", "-select-method" }, arity = "1", hidden = true)
private List<String> selectedMethods2 = new ArrayList<>();
@Option(names = { "--m", "-select-method" }, arity = "1", hidden = true, converter = SelectorConverter.Method.class)
private List<MethodSelector> selectedMethods2 = new ArrayList<>();

@Option(names = { "-r",
"--select-resource" }, paramLabel = "RESOURCE", arity = "1", description = "Select a classpath resource for test discovery. This option can be repeated.")
private List<String> selectedClasspathResources = new ArrayList<>();
"--select-resource" }, paramLabel = "RESOURCE", arity = "1", converter = SelectorConverter.ClasspathResource.class, description = "Select a classpath resource for test discovery. This option can be repeated.")
private List<ClasspathResourceSelector> selectedClasspathResources = new ArrayList<>();

@Option(names = { "--r", "-select-resource" }, arity = "1", hidden = true)
private List<String> selectedClasspathResources2 = new ArrayList<>();
@Option(names = { "--r",
"-select-resource" }, arity = "1", hidden = true, converter = SelectorConverter.ClasspathResource.class)
private List<ClasspathResourceSelector> selectedClasspathResources2 = new ArrayList<>();

@Option(names = { "-i",
"--select-iteration" }, paramLabel = "TYPE:VALUE[INDEX(..INDEX)?(,INDEX(..INDEX)?)*]", arity = "1", converter = SelectorConverter.Iteration.class, description = "Select iterations for test discovery (e.g. method:com.acme.Foo#m()[1..2]). This option can be repeated.")
private List<IterationSelector> selectedIterations = new ArrayList<>();

@Option(names = { "--i",
"-select-iteration" }, arity = "1", hidden = true, converter = SelectorConverter.Iteration.class)
private List<IterationSelector> selectedIterations2 = new ArrayList<>();

// --- Filters ---------------------------------------------------------

Expand Down Expand Up @@ -315,6 +334,7 @@ CommandLineOptions toCommandLineOptions(ParseResult parseResult) {
result.setSelectedClasses(merge(this.selectedClasses, this.selectedClasses2));
result.setSelectedMethods(merge(this.selectedMethods, this.selectedMethods2));
result.setSelectedClasspathResources(merge(this.selectedClasspathResources, this.selectedClasspathResources2));
result.setSelectedIterations(merge(this.selectedIterations, this.selectedIterations2));

// Filters
result.setIncludedClassNamePatterns(merge(this.includeClassNamePatterns, this.includeClassNamePatterns2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
import static org.apiguardian.api.API.Status.INTERNAL;
import static org.junit.platform.engine.discovery.ClassNameFilter.STANDARD_INCLUDE_PATTERN;

import java.net.URI;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

import org.apiguardian.api.API;
import org.junit.platform.engine.DiscoverySelector;
import org.junit.platform.engine.discovery.ClassSelector;
import org.junit.platform.engine.discovery.ClasspathResourceSelector;
import org.junit.platform.engine.discovery.DirectorySelector;
import org.junit.platform.engine.discovery.FileSelector;
import org.junit.platform.engine.discovery.IterationSelector;
import org.junit.platform.engine.discovery.MethodSelector;
import org.junit.platform.engine.discovery.ModuleSelector;
import org.junit.platform.engine.discovery.PackageSelector;
import org.junit.platform.engine.discovery.UriSelector;

/**
* @since 1.0
Expand All @@ -49,15 +58,16 @@ public class CommandLineOptions {
private List<Path> selectedClasspathEntries = emptyList();

private boolean scanModulepath;
private List<String> selectedModules = emptyList();

private List<URI> selectedUris = emptyList();
private List<String> selectedFiles = emptyList();
private List<String> selectedDirectories = emptyList();
private List<String> selectedPackages = emptyList();
private List<String> selectedClasses = emptyList();
private List<String> selectedMethods = emptyList();
private List<String> selectedClasspathResources = emptyList();
private List<ModuleSelector> selectedModules = emptyList();
private List<UriSelector> selectedUris = emptyList();
private List<FileSelector> selectedFiles = emptyList();
private List<DirectorySelector> selectedDirectories = emptyList();
private List<PackageSelector> selectedPackages = emptyList();
private List<ClassSelector> selectedClasses = emptyList();
private List<MethodSelector> selectedMethods = emptyList();
private List<ClasspathResourceSelector> selectedClasspathResources = emptyList();
private List<IterationSelector> selectedIterations = emptyList();

private List<String> includedClassNamePatterns = singletonList(STANDARD_INCLUDE_PATTERN);
private List<String> excludedClassNamePatterns = emptyList();
Expand Down Expand Up @@ -156,73 +166,90 @@ public void setSelectedClasspathEntries(List<Path> selectedClasspathEntries) {
this.selectedClasspathEntries = selectedClasspathEntries;
}

public List<URI> getSelectedUris() {
return this.selectedUris;
public List<UriSelector> getSelectedUris() {
return selectedUris;
}

public void setSelectedUris(List<URI> selectedUris) {
public void setSelectedUris(List<UriSelector> selectedUris) {
this.selectedUris = selectedUris;
}

public List<String> getSelectedFiles() {
return this.selectedFiles;
public List<FileSelector> getSelectedFiles() {
return selectedFiles;
}

public void setSelectedFiles(List<String> selectedFiles) {
public void setSelectedFiles(List<FileSelector> selectedFiles) {
this.selectedFiles = selectedFiles;
}

public List<String> getSelectedDirectories() {
return this.selectedDirectories;
public List<DirectorySelector> getSelectedDirectories() {
return selectedDirectories;
}

public void setSelectedDirectories(List<String> selectedDirectories) {
public void setSelectedDirectories(List<DirectorySelector> selectedDirectories) {
this.selectedDirectories = selectedDirectories;
}

public List<String> getSelectedModules() {
return this.selectedModules;
public List<ModuleSelector> getSelectedModules() {
return selectedModules;
}

public void setSelectedModules(List<String> selectedModules) {
public void setSelectedModules(List<ModuleSelector> selectedModules) {
this.selectedModules = selectedModules;
}

public List<String> getSelectedPackages() {
return this.selectedPackages;
public List<PackageSelector> getSelectedPackages() {
return selectedPackages;
}

public void setSelectedPackages(List<String> selectedPackages) {
public void setSelectedPackages(List<PackageSelector> selectedPackages) {
this.selectedPackages = selectedPackages;
}

public List<String> getSelectedClasses() {
return this.selectedClasses;
public List<ClassSelector> getSelectedClasses() {
return selectedClasses;
}

public void setSelectedClasses(List<String> selectedClasses) {
public void setSelectedClasses(List<ClassSelector> selectedClasses) {
this.selectedClasses = selectedClasses;
}

public List<String> getSelectedMethods() {
return this.selectedMethods;
public List<MethodSelector> getSelectedMethods() {
return selectedMethods;
}

public void setSelectedMethods(List<String> selectedMethods) {
public void setSelectedMethods(List<MethodSelector> selectedMethods) {
this.selectedMethods = selectedMethods;
}

public List<String> getSelectedClasspathResources() {
return this.selectedClasspathResources;
public List<ClasspathResourceSelector> getSelectedClasspathResources() {
return selectedClasspathResources;
}

public void setSelectedClasspathResources(List<String> selectedClasspathResources) {
public void setSelectedClasspathResources(List<ClasspathResourceSelector> selectedClasspathResources) {
this.selectedClasspathResources = selectedClasspathResources;
}

public boolean hasExplicitSelectors() {
return Stream.of(selectedUris, selectedFiles, selectedDirectories, selectedPackages, selectedClasses,
selectedMethods, selectedClasspathResources).anyMatch(selectors -> !selectors.isEmpty());
public List<IterationSelector> getSelectedIterations() {
return selectedIterations;
}

public void setSelectedIterations(List<IterationSelector> selectedIterations) {
this.selectedIterations = selectedIterations;
}

public List<DiscoverySelector> getExplicitSelectors() {
List<DiscoverySelector> selectors = new ArrayList<>();
selectors.addAll(getSelectedUris());
selectors.addAll(getSelectedFiles());
selectors.addAll(getSelectedDirectories());
selectors.addAll(getSelectedModules());
selectors.addAll(getSelectedPackages());
selectors.addAll(getSelectedClasses());
selectors.addAll(getSelectedMethods());
selectors.addAll(getSelectedClasspathResources());
selectors.addAll(getSelectedIterations());
return selectors;
}

public List<String> getIncludedClassNamePatterns() {
Expand Down
Loading

0 comments on commit 88918cd

Please sign in to comment.