Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
47d345c
[JUnit Platform] Use EngineDiscoveryRequestResolver
mpkorstanje Dec 16, 2023
4ea85b3
WIP
mpkorstanje Jan 4, 2024
bd9ac67
WIP
mpkorstanje Jan 4, 2024
b39764c
WIP
mpkorstanje Feb 15, 2024
9440631
Merge branch 'main' into junit-platform-refactor
mpkorstanje Feb 20, 2024
b6ab3cb
Fix formating
mpkorstanje Feb 20, 2024
b78dac7
WIP
mpkorstanje Feb 20, 2024
15c7221
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Jun 13, 2024
c5be199
Fix
mpkorstanje Jun 13, 2024
4596d74
Fix sorting
mpkorstanje Jun 13, 2024
294d880
Clean up
mpkorstanje Jun 13, 2024
17a2881
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Sep 5, 2024
5f2ca2f
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Oct 31, 2024
9002a1f
WIP
mpkorstanje Oct 31, 2024
a68cc19
Extract FeaturesPropertyResolver
mpkorstanje Nov 1, 2024
ac85314
Refactor tests
mpkorstanje Nov 2, 2024
ff5c6d7
Notes
mpkorstanje Nov 2, 2024
300b405
Simplify
mpkorstanje Nov 6, 2024
1a9e1a7
Move tests for tags to CucumberTestEngineTest
mpkorstanje Nov 6, 2024
26b42ca
Move more tests to CucumberTestEngineTest
mpkorstanje Nov 7, 2024
c090dad
Make it look more like Junit
mpkorstanje Nov 8, 2024
4315b80
Instantiate Configuration exactly once
mpkorstanje Nov 8, 2024
daa5eb4
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Nov 21, 2024
a0f84f1
Warn when selectClasspathResource is incorrectly used
mpkorstanje Nov 21, 2024
5c6b17e
Clean up
mpkorstanje Nov 21, 2024
117e1de
Update CHANGELOG
mpkorstanje Nov 24, 2024
514040e
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Jan 16, 2025
abb234c
Remove unused code
mpkorstanje Jan 16, 2025
a54ab73
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Jan 30, 2025
9e42cae
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Feb 9, 2025
cc1c3f5
Use JUnit 5.12.0-RC1
mpkorstanje Feb 9, 2025
4213749
WIP
mpkorstanje Feb 14, 2025
a724633
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Feb 25, 2025
71fb5c7
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Mar 7, 2025
ca78ceb
More WIP
mpkorstanje Mar 7, 2025
f84cf0c
More WIP
mpkorstanje Mar 7, 2025
22b713f
More WIP
mpkorstanje Mar 7, 2025
9c317a0
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Apr 11, 2025
a63162a
Polishing
mpkorstanje Apr 11, 2025
142fb29
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Apr 24, 2025
543d83e
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Jun 10, 2025
931805f
Report problems with using cucumber.features through JUnit
mpkorstanje Jun 10, 2025
036ea47
Report problems with classpath resource selectors for packages
mpkorstanje Jun 10, 2025
fd9b1b7
Spotless
mpkorstanje Jun 10, 2025
2ffc088
Update versions
mpkorstanje Jun 10, 2025
ae15134
Update documentation and tests
mpkorstanje Jun 10, 2025
88c0703
Warn about use of @Cucumber annotation
mpkorstanje Jun 10, 2025
bb03388
Clean up more
mpkorstanje Jun 10, 2025
cdc6654
Clean up more
mpkorstanje Jun 10, 2025
0fc4a83
Clean up more
mpkorstanje Jun 10, 2025
177c699
Log generated seed, problems only show up if there were problems
mpkorstanje Jun 12, 2025
91e98ba
Report parse errors as problems
mpkorstanje Jun 12, 2025
b4927ce
Update CHANGELOG
mpkorstanje Jun 12, 2025
2c9cbd4
Polish
mpkorstanje Jun 15, 2025
0e4b9b3
Polish
mpkorstanje Jun 15, 2025
5fc80d8
Drop publish token
mpkorstanje Jun 15, 2025
29218ee
Merge remote-tracking branch 'origin/main' into junit-platform-refactor
mpkorstanje Jun 15, 2025
ffb9a24
Polish
mpkorstanje Jun 15, 2025
cce75ab
Remove unnecessary prune
mpkorstanje Jun 16, 2025
734d45e
Extract File container resolver
mpkorstanje Jun 16, 2025
55eb2e5
Extract File container resolver
mpkorstanje Jun 16, 2025
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
Warn when selectClasspathResource is incorrectly used
  • Loading branch information
mpkorstanje committed Nov 21, 2024
commit a0f84f13dcde2cb52791082861700378202137dd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DiscoverySelectorResolver {
private static final EngineDiscoveryRequestResolver<CucumberEngineDescriptor> resolver = EngineDiscoveryRequestResolver
.<CucumberEngineDescriptor>builder()
.addResourceContainerSelectorResolver(new IsFeature())
.addSelectorResolver(context -> new FeatureResolver(context.getEngineDescriptor().getConfiguration()))
.addSelectorResolver(context -> new FeatureResolver(context.getEngineDescriptor().getConfiguration(), context.getPackageFilter()))
.addTestDescriptorVisitor(context -> new FeatureOrderingVisitor())
.addTestDescriptorVisitor(context -> new FeatureElementOrderingVisitor())
.addTestDescriptorVisitor(context -> TestDescriptor::prune)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.cucumber.core.feature.FeatureParser;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.Pickle;
import io.cucumber.core.logging.Logger;
import io.cucumber.core.logging.LoggerFactory;
import io.cucumber.core.resource.ClassLoaders;
import io.cucumber.core.resource.ResourceScanner;
import io.cucumber.core.runtime.UuidGeneratorServiceLoader;
Expand Down Expand Up @@ -33,6 +35,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;

Expand All @@ -51,14 +54,17 @@
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;

final class FeatureResolver implements SelectorResolver {
private static final Logger log = LoggerFactory.getLogger(FeatureResolver.class);

private final ResourceScanner<Feature> featureScanner;

private final CucumberConfiguration configuration;
private final CachingFeatureParser featureParser;
private final Predicate<String> packageFilter;

FeatureResolver(CucumberConfiguration configuration) {
FeatureResolver(CucumberConfiguration configuration, Predicate<String> packageFilter) {
this.configuration = configuration;
this.packageFilter = packageFilter;
this.featureParser = createFeatureParser(configuration);
this.featureScanner = new ResourceScanner<>(
ClassLoaders::getDefaultClassLoader,
Expand Down Expand Up @@ -133,11 +139,23 @@ public Resolution resolve(FileSelector selector, Context context) {
public Resolution resolve(ClasspathResourceSelector selector, Context context) {
Set<Resource> resources = selector.getClasspathResources();
if (!resources.stream().allMatch(isFeature)) {
return Resolution.unresolved();
Set<DiscoverySelector> selectors = featureScanner
.scanForClasspathResource(selector.getClasspathResourceName(), packageFilter)
.stream()
.map(feature -> selector.getPosition()
.map(position -> selectElementAt(feature, position))
.orElseGet(() -> Optional.of(selectFeature(feature))))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(toSet());

warnClasspathResourceSelectorUsedForPackage(selector);

return toResolution(selectors);
}
if (resources.size() > 1) {
throw new IllegalArgumentException(String.format(
"Found %s resources named %s classpath %s. Using the first.",
"Found %s resources named %s on the classpath %s.",
resources.size(), selector.getClasspathResourceName(),
resources.stream().map(Resource::getUri).collect(toList())));
}
Expand All @@ -154,6 +172,17 @@ public Resolution resolve(ClasspathResourceSelector selector, Context context) {
.orElseGet(Resolution::unresolved);
}

private static void warnClasspathResourceSelectorUsedForPackage(ClasspathResourceSelector selector) {
log.warn(() -> {
String classpathResourceName = selector.getClasspathResourceName();
String packageName = classpathResourceName.replaceAll("/", ".");
return String.format(
"The classpath resource selector '%s' should not be used to select features in a package. Use the package selector with '%s' instead",
classpathResourceName,
packageName);
});
}

@Override
public Resolution resolve(UriSelector selector, Context context) {
URI uri = selector.getUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,34 @@ void supportsClasspathResourceSelector() {
}

@Test
void supportsClasspathResourceSelectorThrowIfDuplicateResources() {
void warnWhenResourceSelectorIsUsedToSelectAPackage(LogRecordListener logRecordListener) {
EngineTestKit.engine(ENGINE_ID)
.selectors(selectClasspathResource("io/cucumber/junit/platform/engine"))
.execute()
.allEvents()
.assertEventsMatchLooselyInOrder(
feature("disabled.feature"),
feature("empty-scenario.feature"),
feature("scenario-outline.feature"),
feature("rule.feature"),
feature("single.feature"),
feature("with%20space.feature"));

LogRecord warning = logRecordListener.getLogRecords()
.stream()
.filter(logRecord -> FeatureResolver.class.getName().equals(logRecord.getLoggerName()))
.filter(logRecord -> Level.WARNING.equals(logRecord.getLevel()))
.findFirst().get();

assertThat(warning.getMessage())
.isEqualTo(
"The classpath resource selector 'io/cucumber/junit/platform/engine' should not be " +
"used to select features in a package. Use the package selector with " +
"'io.cucumber.junit.platform.engine' instead");
}

@Test
void classpathResourceSelectorThrowIfDuplicateResources() {
class TestResource implements Resource {

private final String name;
Expand Down Expand Up @@ -190,7 +217,7 @@ public URI getUri() {
assertThat(exception) //
.hasRootCauseInstanceOf(IllegalArgumentException.class) //
.hasRootCauseMessage( //
"Found %s resources named %s classpath %s. Using the first.", //
"Found %s resources named %s on the classpath %s.", //
resources.size(), //
"io/cucumber/junit/platform/engine/single.feature", //
resources.stream().map(Resource::getUri).collect(toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class FeatureResolverTest {
private TestDescriptor getFeature() {
EngineDiscoveryRequestResolver<CucumberEngineDescriptor> resolver = EngineDiscoveryRequestResolver
.<CucumberEngineDescriptor> builder()
.addSelectorResolver(context -> new FeatureResolver(new CucumberConfiguration(configurationParameters)))
.addSelectorResolver(context -> new FeatureResolver(new CucumberConfiguration(configurationParameters),
context.getPackageFilter()))
.addTestDescriptorVisitor(context -> new FeatureElementOrderingVisitor())
.build();
resolver.resolve(new SelectorRequest(selectClasspathResource(featurePath)), engineDescriptor);
Expand Down