Warn when src/main or src/test is used in a glue or feature path #2543
Labels
good first issue
Good for newcomers
🙏 help wanted
Help wanted - not prioritized by core team
⚡ enhancement
Request for new functionality
👓 What did you see?
Novice users often do not understand the difference between the classpath and the filesystem path.
For example this mistake often shows up on stack overflow:
This should be
Here
scr/main/java/com/example
is a filesystem path whileclasspath:com/example
a classpath path.Due to misunderstanding the difference between these paths novice users often specify paths that are positively not glue paths.
Feature paths often just happen to work because unlike glue features don't have to be on the classpath.
Additionally while classpath uris are supported for glue paths the package name format is preferred to avoid confusion.
✅ What did you expect to see?
When passing any feature path starting with
src/{test,main}/resources
emit a warning that suggests replacing it withclasspath:
prefix.Whe passing a glue path starts with
src/{test,main}/{java,kotlin,scala,groovy}
emit a warning that advices the use of the package name.The warning should include the original path used and the suggested replacement.
For the feature path it should also include an explanation that mentions the possible ambiguity and advice the user to avoid it. Either by using the suggested replacement or moving the feature files away from well known filesystem paths that are put on the classpath.
For glue paths it should inform users that files in these paths are typically compiled by their build tool before the compiled files are put on the classpath when executing. As such they probably meant to use the package name.
🛠️ Implementation hints
Feature path parsing is implemented in
FeaturePath
. Checking for the prefix inparseAssumeFileScheme
seems like the right place.Glue paths are parsed in
GluePath
. TheparseAssumeClasspathScheme
seems like the right place.Logging warnings should be done using Cucumbers logging utility. For example see:
cucumber-jvm/core/src/main/java/cucumber/api/cli/Main.java
Line 29 in 549fe86
🧪 Testing hints
You can test log messages by adding a
LogRecordListener
to theLoggerFactory
. See the surrounding code for more context:cucumber-jvm/core/src/test/java/io/cucumber/core/runtime/FeaturePathFeatureSupplierTest.java
Lines 30 to 39 in 78adb8f
The text was updated successfully, but these errors were encountered: