-
-
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
Draft
sormuras
wants to merge
15
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.
Draft
Changes from all commits
Commits
Show all changes
15 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 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
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
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
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; | ||
} |
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,80 @@ | ||
/* | ||
* 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.start; | ||
|
||
import static java.lang.StackWalker.Option.RETAIN_CLASS_REFERENCE; | ||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; | ||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectModule; | ||
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request; | ||
|
||
import java.io.PrintWriter; | ||
import java.nio.charset.Charset; | ||
|
||
import org.apiguardian.api.API; | ||
import org.junit.platform.commons.JUnitException; | ||
import org.junit.platform.console.output.ColorPalette; | ||
import org.junit.platform.console.output.Theme; | ||
import org.junit.platform.console.output.TreePrintingListener; | ||
import org.junit.platform.engine.DiscoverySelector; | ||
import org.junit.platform.launcher.core.LauncherFactory; | ||
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; | ||
|
||
@API(status = EXPERIMENTAL, since = "6.0") | ||
public final class JUnit { | ||
/** | ||
* Run all tests defined in the caller class. | ||
*/ | ||
public static void run() { | ||
var walker = StackWalker.getInstance(RETAIN_CLASS_REFERENCE); | ||
run(selectClass(walker.getCallerClass())); | ||
} | ||
|
||
/** | ||
* Run all tests defined in the given test class. | ||
* @param testClass the class to discover and execute tests in | ||
*/ | ||
public static void run(Class<?> testClass) { | ||
run(selectClass(testClass)); | ||
} | ||
|
||
/** | ||
* Run all tests defined in the given module. | ||
* @param testModule the module to discover and execute tests in | ||
*/ | ||
public static void run(Module testModule) { | ||
run(selectModule(testModule)); | ||
} | ||
|
||
private static void run(DiscoverySelector selector) { | ||
var listener = new SummaryGeneratingListener(); | ||
var charset = Charset.defaultCharset(); | ||
var writer = new PrintWriter(System.out, true, charset); | ||
var printer = new TreePrintingListener(writer, ColorPalette.DEFAULT, Theme.valueOf(charset)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't follow the And will this look good on Windows? (I haven't used it in ages, I have no clue if it supports ANSI yet) |
||
var request = request().selectors(selector).forExecution() // | ||
.listeners(listener, printer) // | ||
.build(); | ||
var launcher = LauncherFactory.create(); | ||
launcher.execute(request); | ||
var summary = listener.getSummary(); | ||
|
||
if (summary.getTotalFailureCount() == 0) | ||
return; | ||
|
||
summary.printFailuresTo(new PrintWriter(System.err, true, charset)); | ||
throw new JUnitException("JUnit run finished with %d failure%s".formatted( // | ||
summary.getTotalFailureCount(), // | ||
summary.getTotalFailureCount() == 1 ? "" : "s")); | ||
} | ||
|
||
private JUnit() { | ||
} | ||
} |
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,8 @@ | ||
/** | ||
* Contains JUnit Start API for writing and running tests. | ||
*/ | ||
|
||
@NullMarked | ||
package org.junit.start; | ||
|
||
import org.jspecify.annotations.NullMarked; |
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
8 changes: 8 additions & 0 deletions
8
platform-tooling-support-tests/projects/jar-describe-module/junit-start.expected.txt
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,8 @@ | ||
org.junit.start@${version} jar:file:.+/junit-start-\d.+\.jar..module-info\.class | ||
exports org.junit.start | ||
requires java.base mandated | ||
requires org.apiguardian.api static transitive | ||
requires org.jspecify static transitive | ||
requires org.junit.jupiter transitive | ||
requires org.junit.platform.console | ||
requires org.junit.platform.launcher |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks similair to
ClasspathFilters.isNotPackageInfo
andisNotModuleInfo
. If you add a string based variant and call those before.map(DefaultClasspathScanner::determineSimpleClassName)
we have that logic in one place.