-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Introduce org.junit.start module
#5042
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
Open
sormuras
wants to merge
22
commits into
main
Choose a base branch
from
experiments/junit-onramp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3afdf0a
Introduce experimental junit-onramp module
marcphilipp 2fdb122
Reduce API surface
sormuras e59b227
Consider `*.java` source files as classes in source mode
sormuras 8cdf2f5
Overload `run()` API and reuse console printing listener
sormuras 4d1f062
Use tree printer by default
sormuras f4ba4fc
Skip module declaration files
sormuras ea1e686
Add tests using the `org.junit.onramp` module
sormuras 0eb6fa0
Fix copyright headers
sormuras 64d6554
Merge remote-tracking branch 'origin/main' into experiments/junit-onramp
sormuras a3c4b61
Minor cleanup
sormuras f542616
Fix configuration
sormuras 2308620
Rename to `org.junit.start`
sormuras 4dd14d6
More renaming
sormuras 61c678d
Assert test method names are printed
sormuras a170306
Merge branch 'main' into experiments/junit-onramp
sormuras 1e060d0
Check for `NO_COLOR` environment variable
sormuras efb6cd8
Move more common logic into `SearchPathUtils`
marcphilipp bb31561
Update junit-start/junit-start.gradle.kts
sormuras 8199ca7
Remove workaround for bug fixed in JDK 9 and later
marcphilipp dea7a32
Merge branch 'main' into experiments/junit-onramp
sormuras 13cabb8
Use Markdown syntax in API documentation
sormuras 6c5ca16
Update User Guide, API documentation overview, and Release Notes
sormuras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathFilters.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
junit-platform-commons/src/main/java/org/junit/platform/commons/util/SearchPathUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Copyright 2015-2025 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| package org.junit.platform.commons.util; | ||
|
|
||
| import static java.util.stream.Collectors.joining; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import org.junit.platform.commons.JUnitException; | ||
|
|
||
| /** | ||
| * @since 1.11 | ||
| */ | ||
| class SearchPathUtils { | ||
|
|
||
| static final char PACKAGE_SEPARATOR_CHAR = '.'; | ||
| static final String PACKAGE_SEPARATOR_STRING = String.valueOf(PACKAGE_SEPARATOR_CHAR); | ||
| private static final char FILE_NAME_EXTENSION_SEPARATOR_CHAR = '.'; | ||
|
|
||
| private static final String CLASS_FILE_SUFFIX = ".class"; | ||
| private static final String SOURCE_FILE_SUFFIX = ".java"; | ||
|
|
||
| private static final String PACKAGE_INFO_FILE_NAME = "package-info"; | ||
| private static final String MODULE_INFO_FILE_NAME = "module-info"; | ||
|
|
||
| // System property defined since Java 12: https://bugs.java/bugdatabase/JDK-8210877 | ||
| private static final boolean SOURCE_MODE = System.getProperty("jdk.launcher.sourcefile") != null; | ||
|
|
||
| static boolean isResourceFile(Path file) { | ||
| return !isClassFile(file); | ||
| } | ||
|
|
||
| static boolean isClassOrSourceFile(Path file) { | ||
| var fileName = file.getFileName().toString(); | ||
| return isClassOrSourceFile(fileName) && !isModuleInfoOrPackageInfo(fileName); | ||
| } | ||
|
|
||
| private static boolean isModuleInfoOrPackageInfo(String fileName) { | ||
| var fileNameWithoutExtension = removeExtension(fileName); | ||
| return PACKAGE_INFO_FILE_NAME.equals(fileNameWithoutExtension) // | ||
| || MODULE_INFO_FILE_NAME.equals(fileNameWithoutExtension); | ||
| } | ||
|
|
||
| static String determineFullyQualifiedClassName(Path path) { | ||
| var simpleClassName = determineSimpleClassName(path); | ||
| var parent = path.getParent(); | ||
| return parent == null ? simpleClassName : joinPathNamesWithPackageSeparator(parent.resolve(simpleClassName)); | ||
| } | ||
|
|
||
| private static String joinPathNamesWithPackageSeparator(Path path) { | ||
| return IntStream.range(0, path.getNameCount()) // | ||
| .mapToObj(i -> path.getName(i).toString()) // | ||
| .collect(joining(PACKAGE_SEPARATOR_STRING)); | ||
| } | ||
|
|
||
| static String determineSimpleClassName(Path file) { | ||
| return removeExtension(file.getFileName().toString()); | ||
| } | ||
|
|
||
| private static String removeExtension(String fileName) { | ||
| int lastDot = fileName.lastIndexOf(FILE_NAME_EXTENSION_SEPARATOR_CHAR); | ||
| if (lastDot < 0) { | ||
| throw new JUnitException("Expected file name with file extension, but got: " + fileName); | ||
| } | ||
| return fileName.substring(0, lastDot); | ||
| } | ||
|
|
||
| private static boolean isClassOrSourceFile(String name) { | ||
| return name.endsWith(CLASS_FILE_SUFFIX) || (SOURCE_MODE && name.endsWith(SOURCE_FILE_SUFFIX)); | ||
| } | ||
|
|
||
| private static boolean isClassFile(Path file) { | ||
| return file.getFileName().toString().endsWith(CLASS_FILE_SUFFIX); | ||
| } | ||
|
|
||
| private SearchPathUtils() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| plugins { | ||
| id("junitbuild.java-library-conventions") | ||
| } | ||
|
|
||
| description = "JUnit Start Module" | ||
|
|
||
| dependencies { | ||
| api(platform(projects.junitBom)) | ||
| api(projects.junitJupiter) | ||
|
|
||
| compileOnlyApi(libs.apiguardian) | ||
| compileOnlyApi(libs.jspecify) | ||
| compileOnlyApi(projects.junitJupiterEngine) | ||
|
|
||
| implementation(projects.junitPlatformLauncher) | ||
| implementation(projects.junitPlatformConsole) | ||
| } | ||
|
|
||
| backwardCompatibilityChecks { | ||
| enabled = false // already checked by individual projects | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2015-2025 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| /** | ||
| * Defines the API of the JUnit Start module for writing and running tests. | ||
| * <p> | ||
| * Usage example: | ||
| * <pre>{@code | ||
| * import module org.junit.start; | ||
| * | ||
| * void main() { | ||
| * JUnit.run(); | ||
| * } | ||
| * | ||
| * @Test | ||
| * void addition() { | ||
| * Assertions.assertEquals(2, 1 + 1, "Addition error detected!"); | ||
| * } | ||
| * }</pre> | ||
| */ | ||
| module org.junit.start { | ||
| requires static transitive org.apiguardian.api; | ||
| requires static transitive org.jspecify; | ||
|
|
||
| requires transitive org.junit.jupiter; | ||
| requires org.junit.platform.launcher; | ||
| requires org.junit.platform.console; | ||
|
|
||
| exports org.junit.start; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.