diff --git a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts index cb2a80ecaba8..8a27b7b936b0 100644 --- a/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts +++ b/platform-tooling-support-tests/platform-tooling-support-tests.gradle.kts @@ -109,6 +109,9 @@ tasks.test { distribution { requirements.add("jdk=8") + localOnly { + includeClasses.add("platform.tooling.support.tests.GraalVmStarterTests") // GraalVM is not installed on Test Distribution agents + } } jvmArgumentProviders += JavaHomeDir(project, 8) } diff --git a/platform-tooling-support-tests/projects/graalvm-starter/build.gradle.kts b/platform-tooling-support-tests/projects/graalvm-starter/build.gradle.kts new file mode 100644 index 000000000000..edd8bd7b7474 --- /dev/null +++ b/platform-tooling-support-tests/projects/graalvm-starter/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + java + id("org.graalvm.buildtools.native") +} + +val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION") +val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION") + +repositories { + maven { url = uri(file(System.getProperty("maven.repo"))) } + mavenCentral() +} + +dependencies { + testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion") + testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion") +} + +tasks.test { + useJUnitPlatform() + + val outputDir = reports.junitXml.outputLocation + jvmArgumentProviders += CommandLineArgumentProvider { + listOf( + "-Djunit.platform.reporting.open.xml.enabled=true", + "-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}" + ) + } +} diff --git a/platform-tooling-support-tests/projects/graalvm-starter/settings.gradle.kts b/platform-tooling-support-tests/projects/graalvm-starter/settings.gradle.kts new file mode 100644 index 000000000000..c928064e495a --- /dev/null +++ b/platform-tooling-support-tests/projects/graalvm-starter/settings.gradle.kts @@ -0,0 +1,11 @@ +pluginManagement { + plugins { + id("org.graalvm.buildtools.native") version "0.9.13" + } + repositories { + mavenCentral() + gradlePluginPortal() + } +} + +rootProject.name = "graalvm-starter" diff --git a/platform-tooling-support-tests/projects/graalvm-starter/src/main/java/com/example/project/Calculator.java b/platform-tooling-support-tests/projects/graalvm-starter/src/main/java/com/example/project/Calculator.java new file mode 100644 index 000000000000..b90710f2c68d --- /dev/null +++ b/platform-tooling-support-tests/projects/graalvm-starter/src/main/java/com/example/project/Calculator.java @@ -0,0 +1,19 @@ +/* + * Copyright 2015-2022 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 com.example.project; + +public class Calculator { + + public int add(int a, int b) { + return a + b; + } + +} diff --git a/platform-tooling-support-tests/projects/graalvm-starter/src/test/java/com/example/project/CalculatorTests.java b/platform-tooling-support-tests/projects/graalvm-starter/src/test/java/com/example/project/CalculatorTests.java new file mode 100644 index 000000000000..7f043f0dd3ea --- /dev/null +++ b/platform-tooling-support-tests/projects/graalvm-starter/src/test/java/com/example/project/CalculatorTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2015-2022 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 com.example.project; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class CalculatorTests { + + @Test + @DisplayName("1 + 1 = 2") + void addsTwoNumbers() { + Calculator calculator = new Calculator(); + assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2"); + } + + @ParameterizedTest(name = "{0} + {1} = {2}") + @CsvSource({ + "0, 1, 1", + "1, 2, 3", + "49, 51, 100", + "1, 100, 101" + }) + void add(int first, int second, int expectedResult) { + Calculator calculator = new Calculator(); + assertEquals(expectedResult, calculator.add(first, second), + () -> first + " + " + second + " should equal " + expectedResult); + } +} diff --git a/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts b/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts index 33068798beb2..dfc4a31ad87e 100644 --- a/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts +++ b/platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts @@ -7,14 +7,6 @@ val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION") val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION") val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION") -// emit default file encoding to a file -file("file.encoding.txt").writeText(System.getProperty("file.encoding")) -file("junit.versions.txt").writeText(""" -jupiterVersion=$jupiterVersion -vintageVersion=$vintageVersion -platformVersion=$platformVersion -""") - repositories { maven { url = uri(file(System.getProperty("maven.repo"))) } mavenCentral() diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GraalVmStarterTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GraalVmStarterTests.java new file mode 100644 index 000000000000..0d3c8dd5bced --- /dev/null +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/GraalVmStarterTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2015-2022 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 platform.tooling.support.tests; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static platform.tooling.support.Helper.TOOL_TIMEOUT; +import static platform.tooling.support.tests.XmlAssertions.verifyContainsExpectedStartedOpenTestReport; + +import java.nio.file.Paths; + +import de.sormuras.bartholdy.tool.GradleWrapper; + +import org.junit.jupiter.api.Test; + +import platform.tooling.support.MavenRepo; +import platform.tooling.support.Request; + +/** + * @since 1.9.1 + */ +class GraalVmStarterTests { + + @Test + void runsTestsInNativeImage() { + var request = Request.builder() // + .setTool(new GradleWrapper(Paths.get(".."))) // + .setProject("graalvm-starter") // + .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // + .addArguments("javaToolchains", "nativeTest", "--no-daemon", "--stacktrace") // + .setTimeout(TOOL_TIMEOUT) // + .build(); + + var result = request.run(); + + assertFalse(result.isTimedOut(), () -> "tool timed out: " + result); + + assumeFalse( + result.getOutputLines("err").stream().anyMatch(line -> line.contains("No compatible toolchains found")), + "Abort test if GraalVM is not installed"); + + assertEquals(0, result.getExitCode()); + assertTrue(result.getOutputLines("out").stream().anyMatch(line -> line.contains("BUILD SUCCESSFUL"))); + + var testResultsDir = Request.WORKSPACE.resolve(request.getWorkspace()).resolve("build/test-results/test"); + verifyContainsExpectedStartedOpenTestReport(testResultsDir); + } +}