junit-team / junit5

✅ The 5th major version of the programmer-friendly testing framework for Java and the JVM

Home Page:https://junit.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Console launcher should support `--version`

sormuras opened this issue · comments

The junit console launcher should support a --version option and print its version.

Perhaps it should also print the version of each discoverable test engine?

There's support for version options in Picocli: https://picocli.info/#_version_help

Related option already in place: --list-engines

Looks very good to me!

java -jar junit-platform-console-standalone-1.11.0-20240516.144734-223.jar --version

JUnit Platform Console Launcher 1.11.0-SNAPSHOT
JVM: 23-ea (Oracle Corporation OpenJDK 64-Bit Server VM 23-ea+21-1723)
OS: Windows 11 10.0 amd64

However, running junit on the module path does not look so good to me.

org.junit.platform.console/junit@1.11.0-M2 --version

JUnit Platform Console Launcher null
JVM: 22.0.1 (Oracle Corporation OpenJDK 64-Bit Server VM 22.0.1+8-16)
OS: Windows 11 10.0 amd64

This

return ManifestVersionProvider.class.getPackage().getImplementationVersion();

returns null.

We should fist try a ModuleVersionProvider on Java 9+, like we do here:

default Optional<String> getVersion() {
Optional<String> standalone = PackageUtils.getAttribute(getClass(), "Engine-Version-" + getId());
if (standalone.isPresent()) {
return standalone;
}
String fallback = "DEVELOPMENT";
Optional<String> moduleVersion = ModuleUtils.getModuleVersion(getClass());
if (moduleVersion.isPresent()) {
return moduleVersion;
}
return Optional.of(PackageUtils.getAttribute(getClass(), Package::getImplementationVersion).orElse(fallback));
}

And resort to a non-null fallback value.

@sormuras, can you please create a new issue to address that in 5.11 M3?