Skip to content

Commit f3399ca

Browse files
Add modular compilation test
This commit adds an extra compilation using only `javac` and its multi-module compilation feature in order to detect missing directives in JUnit's module descriptors. --------- Co-authored-by: Marc Philipp <[email protected]>
1 parent eadf066 commit f3399ca

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import com.gradle.develocity.agent.gradle.internal.test.TestDistributionConfigurationInternal
22
import junitbuild.extensions.capitalized
33
import junitbuild.extensions.dependencyProject
4+
import junitbuild.extensions.javaModuleName
45
import net.ltgt.gradle.errorprone.errorprone
56
import org.gradle.api.tasks.PathSensitivity.RELATIVE
6-
import org.gradle.jvm.toolchain.JvmVendorSpec.GRAAL_VM
77
import org.gradle.kotlin.dsl.support.listFilesOrdered
88
import java.time.Duration
99

@@ -45,6 +45,8 @@ val mavenDistributionClasspath = configurations.resolvable("mavenDistributionCla
4545
extendsFrom(mavenDistribution.get())
4646
}
4747

48+
val modularProjects: List<Project> by rootProject
49+
4850
dependencies {
4951
implementation(libs.commons.io) {
5052
because("moving/deleting directory trees")
@@ -63,11 +65,17 @@ dependencies {
6365
}
6466
thirdPartyJars(libs.assertj)
6567
thirdPartyJars(libs.apiguardian)
68+
thirdPartyJars(libs.fastcsv)
6669
thirdPartyJars(libs.hamcrest)
70+
thirdPartyJars(libs.jimfs)
6771
thirdPartyJars(libs.jspecify)
72+
thirdPartyJars(kotlin("stdlib"))
73+
thirdPartyJars(kotlin("reflect"))
74+
thirdPartyJars(libs.kotlinx.coroutines)
6875
thirdPartyJars(libs.opentest4j)
76+
thirdPartyJars(libs.openTestReporting.events)
6977
thirdPartyJars(libs.openTestReporting.tooling.spi)
70-
thirdPartyJars(libs.jimfs)
78+
thirdPartyJars(libs.picocli)
7179

7280
antJars(platform(projects.junitBom))
7381
antJars(libs.bundles.ant)
@@ -130,7 +138,6 @@ val archUnit by testing.suites.registering(JvmTestSuite::class) {
130138
}
131139
implementation(libs.assertj)
132140
runtimeOnly.bundle(libs.bundles.log4j)
133-
val modularProjects: List<Project> by rootProject
134141
modularProjects.forEach {
135142
runtimeOnly(project(it.path))
136143
}
@@ -207,6 +214,12 @@ val test by testing.suites.getting(JvmTestSuite::class) {
207214
jvmArgumentProviders += JarPath(project, antJarsClasspath.get(), "antJars")
208215
jvmArgumentProviders += MavenDistribution(project, unzipMavenDistribution, mavenDistributionDir)
209216

217+
systemProperty("junit.modules", modularProjects.map { it.javaModuleName }.joinToString(","))
218+
219+
jvmArgumentProviders += CommandLineArgumentProvider {
220+
modularProjects.map { "-Djunit.moduleSourcePath.${it.javaModuleName}=${it.sourceSets["main"].allJava.sourceDirectories.filter { it.exists() }.asPath}" }
221+
}
222+
210223
inputs.apply {
211224
dir("projects").withPathSensitivity(RELATIVE)
212225
file("${rootDir}/gradle.properties").withPathSensitivity(RELATIVE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2015-2025 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package platform.tooling.support.tests;
12+
13+
import static java.util.Objects.requireNonNull;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
17+
import java.nio.file.Files;
18+
import java.nio.file.Path;
19+
import java.util.Arrays;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.io.TempDir;
23+
import org.junit.platform.tests.process.OutputFiles;
24+
25+
import platform.tooling.support.ProcessStarters;
26+
import platform.tooling.support.ThirdPartyJars;
27+
28+
class ModularCompilationTests {
29+
30+
@Test
31+
void compileAllJUnitModules(@TempDir Path workspace, @FilePrefix("javac") OutputFiles javacOutputFiles)
32+
throws Exception {
33+
var lib = Files.createDirectories(workspace.resolve("lib"));
34+
ThirdPartyJars.copyAll(lib);
35+
36+
var moduleNames = Arrays.asList(System.getProperty("junit.modules").split(","));
37+
38+
var outputDir = workspace.resolve("classes").toAbsolutePath();
39+
var processStarter = ProcessStarters.javaCommand("javac") //
40+
.workingDir(workspace) //
41+
.addArguments("-d", outputDir.toString()) //
42+
.addArguments("-Xlint:all", "-Werror") //
43+
.addArguments("-Xlint:-requires-automatic,-requires-transitive-automatic") // JUnit 4
44+
// external modules
45+
.addArguments("--module-path", lib.toAbsolutePath().toString());
46+
47+
// source locations in module-specific form
48+
moduleNames.forEach(
49+
moduleName -> processStarter.addArguments("--module-source-path", moduleSourcePath(moduleName)));
50+
51+
var result = processStarter
52+
// un-shadow
53+
.addArguments("--add-modules", "info.picocli") //
54+
.addArguments("--add-reads", "org.junit.platform.console=info.picocli") //
55+
.addArguments("--add-modules", "org.opentest4j.reporting.events") //
56+
.addArguments("--add-reads", "org.junit.platform.reporting=org.opentest4j.reporting.events") //
57+
.addArguments("--add-modules", "de.siegmar.fastcsv") //
58+
.addArguments("--add-reads", "org.junit.jupiter.params=de.siegmar.fastcsv")
59+
// modules to compile
60+
.addArguments("--module", String.join(",", moduleNames)) //
61+
.redirectOutput(javacOutputFiles) //
62+
.startAndWait();
63+
64+
assertEquals(0, result.exitCode());
65+
assertThat(outputDir).isNotEmptyDirectory();
66+
}
67+
68+
static String moduleSourcePath(String moduleName) {
69+
return "%s=%s".formatted(moduleName,
70+
requireNonNull(System.getProperty("junit.moduleSourcePath." + moduleName)));
71+
}
72+
}

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ModularUserGuideTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void runTestsFromUserGuideWithinModularBoundaries(@TempDir Path temp,
156156
assertLinesMatch(List.of( //
157157
"destination", //
158158
">> CLASSES AND JARS >>", //
159-
"lib/opentest4j-.+\\.jar", //
160159
"src", //
161160
"src/documentation", //
162161
"src/documentation/module-info.java" //

0 commit comments

Comments
 (0)