Skip to content

Commit

Permalink
Accept multiple values for all --select ConsoleLauncher options
Browse files Browse the repository at this point in the history
Resolves #3485.
  • Loading branch information
juliette-derancourt committed Oct 23, 2024
1 parent f37db92 commit 35e5126
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ JUnit repository on GitHub.
`ReflectionUtils` to allow `String` to `Class` conversion in parameterized tests.
* Add support for passing line and column number to `ConsoleLauncher` via
`--select-file` and `--select-resource`.
* `ConsoleLauncher` now accepts multiple values for all `--select` options.


[[release-notes-5.12.0-M1-junit-jupiter]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,85 +69,84 @@ static class SelectorOptions {
private boolean scanModulepath2;

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

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

@Option(names = { "-f",
"--select-file" }, paramLabel = "FILE", arity = "1", converter = SelectorConverter.File.class, //
"--select-file" }, paramLabel = "FILE", arity = "1..*", converter = SelectorConverter.File.class, //
description = "Select a file for test discovery. "
+ "The line and column numbers can be provided as URI query parameters (e.g. foo.txt?line=12&column=34). "
+ "This option can be repeated.")
private final List<FileSelector> selectedFiles = new ArrayList<>();

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

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

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

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

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

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

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

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

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

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

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

@Option(names = { "-r",
"--select-resource" }, paramLabel = "RESOURCE", arity = "1", converter = SelectorConverter.ClasspathResource.class, //
description = "Select a classpath resource for test discovery. "
+ "The line and column numbers can be provided as URI query parameters (e.g. foo.csv?line=12&column=34). "
+ "This option can be repeated.")
"--select-resource" }, paramLabel = "RESOURCE", arity = "1..*", converter = SelectorConverter.ClasspathResource.class, description = "Select a classpath resource for test discovery. This option can be repeated.")
private final List<ClasspathResourceSelector> selectedClasspathResources = new ArrayList<>();

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

@Option(names = { "-i",
"--select-iteration" }, paramLabel = "PREFIX:VALUE[INDEX(..INDEX)?(,INDEX(..INDEX)?)*]", arity = "1", converter = SelectorConverter.Iteration.class, //
"--select-iteration" }, paramLabel = "PREFIX:VALUE[INDEX(..INDEX)?(,INDEX(..INDEX)?)*]", arity = "1..*", converter = SelectorConverter.Iteration.class, //
description = "Select iterations for test discovery via a prefixed identifier and a list of indexes or index ranges "
+ "(e.g. method:com.acme.Foo#m()[1..2] selects the first and second iteration of the m() method in the com.acme.Foo class). "
+ "This option can be repeated.")
private final List<IterationSelector> selectedIterations = new ArrayList<>();

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

@Option(names = "--select", paramLabel = "PREFIX:VALUE", arity = "1", converter = SelectorConverter.Identifier.class, //
@Option(names = "--select", paramLabel = "PREFIX:VALUE", arity = "1..*", converter = SelectorConverter.Identifier.class, //
description = "Select via a prefixed identifier (e.g. method:com.acme.Foo#m selects the m() method in the com.acme.Foo class). "
+ "This option can be repeated.")
private final List<DiscoverySelectorIdentifier> selectorIdentifiers = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ void parseValidUriSelectors(ArgsType type) {
() -> assertEquals(List.of(selectUri("file:///foo.txt")), type.parseArgLine("-select-uri=file:///foo.txt").discovery.getSelectedUris()),
() -> assertEquals(List.of(selectUri("file:///foo.txt")), type.parseArgLine("--select-uri file:///foo.txt").discovery.getSelectedUris()),
() -> assertEquals(List.of(selectUri("file:///foo.txt")), type.parseArgLine("--select-uri=file:///foo.txt").discovery.getSelectedUris()),
() -> assertEquals(List.of(selectUri("file:///foo.txt"), selectUri("https://example")), type.parseArgLine("-u file:///foo.txt -u https://example").discovery.getSelectedUris())
() -> assertEquals(List.of(selectUri("file:///foo.txt"), selectUri("https://example")), type.parseArgLine("-u file:///foo.txt -u https://example").discovery.getSelectedUris()),
() -> assertEquals(List.of(selectUri("file:///foo.txt"), selectUri("https://example")), type.parseArgLine("-u file:///foo.txt https://example").discovery.getSelectedUris())
);
// @formatter:on
}
Expand All @@ -384,6 +385,7 @@ void parseValidFileSelectors(ArgsType type) {
() -> assertEquals(List.of(selectFile("foo.txt")), type.parseArgLine("--select-file foo.txt").discovery.getSelectedFiles()),
() -> assertEquals(List.of(selectFile("foo.txt")), type.parseArgLine("--select-file=foo.txt").discovery.getSelectedFiles()),
() -> assertEquals(List.of(selectFile("foo.txt"), selectFile("bar.csv")), type.parseArgLine("-f foo.txt -f bar.csv").discovery.getSelectedFiles()),
() -> assertEquals(List.of(selectFile("foo.txt"), selectFile("bar.csv")), type.parseArgLine("-f foo.txt bar.csv").discovery.getSelectedFiles()),
() -> assertEquals(List.of(selectFile("foo.txt", FilePosition.from(5))), type.parseArgLine("-f foo.txt?line=5").discovery.getSelectedFiles()),
() -> assertEquals(List.of(selectFile("foo.txt", FilePosition.from(12, 34))), type.parseArgLine("-f foo.txt?line=12&column=34").discovery.getSelectedFiles())
);
Expand All @@ -406,7 +408,8 @@ void parseValidDirectorySelectors(ArgsType type) {
() -> assertEquals(List.of(selectDirectory("foo/bar")), type.parseArgLine("-select-directory=foo/bar").discovery.getSelectedDirectories()),
() -> assertEquals(List.of(selectDirectory("foo/bar")), type.parseArgLine("--select-directory foo/bar").discovery.getSelectedDirectories()),
() -> assertEquals(List.of(selectDirectory("foo/bar")), type.parseArgLine("--select-directory=foo/bar").discovery.getSelectedDirectories()),
() -> assertEquals(List.of(selectDirectory("foo/bar"), selectDirectory("bar/qux")), type.parseArgLine("-d foo/bar -d bar/qux").discovery.getSelectedDirectories())
() -> assertEquals(List.of(selectDirectory("foo/bar"), selectDirectory("bar/qux")), type.parseArgLine("-d foo/bar -d bar/qux").discovery.getSelectedDirectories()),
() -> assertEquals(List.of(selectDirectory("foo/bar"), selectDirectory("bar/qux")), type.parseArgLine("-d foo/bar bar/qux").discovery.getSelectedDirectories())
);
// @formatter:on
}
Expand All @@ -427,7 +430,8 @@ void parseValidModuleSelectors(ArgsType type) {
() -> assertEquals(List.of(selectModule("com.acme.foo")), type.parseArgLine("-select-module=com.acme.foo").discovery.getSelectedModules()),
() -> assertEquals(List.of(selectModule("com.acme.foo")), type.parseArgLine("--select-module com.acme.foo").discovery.getSelectedModules()),
() -> assertEquals(List.of(selectModule("com.acme.foo")), type.parseArgLine("--select-module=com.acme.foo").discovery.getSelectedModules()),
() -> assertEquals(List.of(selectModule("com.acme.foo"), selectModule("com.example.bar")), type.parseArgLine("-o com.acme.foo -o com.example.bar").discovery.getSelectedModules())
() -> assertEquals(List.of(selectModule("com.acme.foo"), selectModule("com.example.bar")), type.parseArgLine("-o com.acme.foo -o com.example.bar").discovery.getSelectedModules()),
() -> assertEquals(List.of(selectModule("com.acme.foo"), selectModule("com.example.bar")), type.parseArgLine("-o com.acme.foo com.example.bar").discovery.getSelectedModules())
);
// @formatter:on
}
Expand All @@ -448,7 +452,8 @@ void parseValidPackageSelectors(ArgsType type) {
() -> assertEquals(List.of(selectPackage("com.acme.foo")), type.parseArgLine("-select-package=com.acme.foo").discovery.getSelectedPackages()),
() -> assertEquals(List.of(selectPackage("com.acme.foo")), type.parseArgLine("--select-package com.acme.foo").discovery.getSelectedPackages()),
() -> assertEquals(List.of(selectPackage("com.acme.foo")), type.parseArgLine("--select-package=com.acme.foo").discovery.getSelectedPackages()),
() -> assertEquals(List.of(selectPackage("com.acme.foo"), selectPackage("com.example.bar")), type.parseArgLine("-p com.acme.foo -p com.example.bar").discovery.getSelectedPackages())
() -> assertEquals(List.of(selectPackage("com.acme.foo"), selectPackage("com.example.bar")), type.parseArgLine("-p com.acme.foo -p com.example.bar").discovery.getSelectedPackages()),
() -> assertEquals(List.of(selectPackage("com.acme.foo"), selectPackage("com.example.bar")), type.parseArgLine("-p com.acme.foo com.example.bar").discovery.getSelectedPackages())
);
// @formatter:on
}
Expand All @@ -469,7 +474,8 @@ void parseValidClassSelectors(ArgsType type) {
() -> assertEquals(List.of(selectClass("com.acme.Foo")), type.parseArgLine("-select-class=com.acme.Foo").discovery.getSelectedClasses()),
() -> assertEquals(List.of(selectClass("com.acme.Foo")), type.parseArgLine("--select-class com.acme.Foo").discovery.getSelectedClasses()),
() -> assertEquals(List.of(selectClass("com.acme.Foo")), type.parseArgLine("--select-class=com.acme.Foo").discovery.getSelectedClasses()),
() -> assertEquals(List.of(selectClass("com.acme.Foo"), selectClass("com.example.Bar")), type.parseArgLine("-c com.acme.Foo -c com.example.Bar").discovery.getSelectedClasses())
() -> assertEquals(List.of(selectClass("com.acme.Foo"), selectClass("com.example.Bar")), type.parseArgLine("-c com.acme.Foo -c com.example.Bar").discovery.getSelectedClasses()),
() -> assertEquals(List.of(selectClass("com.acme.Foo"), selectClass("com.example.Bar")), type.parseArgLine("-c com.acme.Foo com.example.Bar").discovery.getSelectedClasses())
);
// @formatter:on
}
Expand All @@ -491,7 +497,9 @@ void parseValidMethodSelectors(ArgsType type) {
() -> assertEquals(List.of(selectMethod("com.acme.Foo#m()")), type.parseArgLine("--select-method com.acme.Foo#m()").discovery.getSelectedMethods()),
() -> assertEquals(List.of(selectMethod("com.acme.Foo#m()")), type.parseArgLine("--select-method=com.acme.Foo#m()").discovery.getSelectedMethods()),
() -> assertEquals(List.of(selectMethod("com.acme.Foo#m()"), selectMethod("com.example.Bar#method(java.lang.Object)")),
type.parseArgLine("-m com.acme.Foo#m() -m com.example.Bar#method(java.lang.Object)").discovery.getSelectedMethods())
type.parseArgLine("-m com.acme.Foo#m() -m com.example.Bar#method(java.lang.Object)").discovery.getSelectedMethods()),
() -> assertEquals(List.of(selectMethod("com.acme.Foo#m()"), selectMethod("com.example.Bar#method(java.lang.Object)")),
type.parseArgLine("-m com.acme.Foo#m() com.example.Bar#method(java.lang.Object)").discovery.getSelectedMethods())
);
// @formatter:on
}
Expand All @@ -513,6 +521,7 @@ void parseValidClasspathResourceSelectors(ArgsType type) {
() -> assertEquals(List.of(selectClasspathResource("/foo.csv")), type.parseArgLine("--select-resource /foo.csv").discovery.getSelectedClasspathResources()),
() -> assertEquals(List.of(selectClasspathResource("/foo.csv")), type.parseArgLine("--select-resource=/foo.csv").discovery.getSelectedClasspathResources()),
() -> assertEquals(List.of(selectClasspathResource("/foo.csv"), selectClasspathResource("bar.json")), type.parseArgLine("-r /foo.csv -r bar.json").discovery.getSelectedClasspathResources()),
() -> assertEquals(List.of(selectClasspathResource("/foo.csv"), selectClasspathResource("bar.json")), type.parseArgLine("-r /foo.csv bar.json").discovery.getSelectedClasspathResources()),
() -> assertEquals(List.of(selectClasspathResource("/foo.csv", FilePosition.from(5))), type.parseArgLine("-r /foo.csv?line=5").discovery.getSelectedClasspathResources()),
() -> assertEquals(List.of(selectClasspathResource("/foo.csv", FilePosition.from(12, 34))), type.parseArgLine("-r /foo.csv?line=12&column=34").discovery.getSelectedClasspathResources())
);
Expand All @@ -535,7 +544,8 @@ void parseValidIterationSelectors(ArgsType type) {
() -> assertEquals(List.of(selectIteration(selectPackage("com.acme.foo"), 3)), type.parseArgLine("-select-iteration=package:com.acme.foo[3]").discovery.getSelectedIterations()),
() -> assertEquals(List.of(selectIteration(selectModule("com.acme.foo"), 0, 1, 2, 4, 5, 6)), type.parseArgLine("--select-iteration module:com.acme.foo[0..2,4..6]").discovery.getSelectedIterations()),
() -> assertEquals(List.of(selectIteration(selectDirectory("foo/bar"), 1, 5)), type.parseArgLine("--select-iteration=directory:foo/bar[1,5]").discovery.getSelectedIterations()),
() -> assertEquals(List.of(selectIteration(selectFile("foo.txt"), 6), selectIteration(selectUri("file:///foo.txt"), 7)), type.parseArgLine("-i file:foo.txt[6] -i uri:file:///foo.txt[7]").discovery.getSelectedIterations())
() -> assertEquals(List.of(selectIteration(selectFile("foo.txt"), 6), selectIteration(selectUri("file:///foo.txt"), 7)), type.parseArgLine("-i file:foo.txt[6] -i uri:file:///foo.txt[7]").discovery.getSelectedIterations()),
() -> assertEquals(List.of(selectIteration(selectFile("foo.txt"), 6), selectIteration(selectUri("file:///foo.txt"), 7)), type.parseArgLine("-i file:foo.txt[6] uri:file:///foo.txt[7]").discovery.getSelectedIterations())
);
// @formatter:on
}
Expand Down

0 comments on commit 35e5126

Please sign in to comment.