|
| 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 | +} |
0 commit comments