Skip to content

Commit 7229385

Browse files
committed
Add failing integration test for execution on GraalVM native image
1 parent 343170f commit 7229385

File tree

7 files changed

+161
-8
lines changed

7 files changed

+161
-8
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ tasks.test {
109109

110110
distribution {
111111
requirements.add("jdk=8")
112+
localOnly {
113+
includeClasses.add("platform.tooling.support.tests.GraalVmStarterTests") // GraalVM is not installed on Test Distribution agents
114+
}
112115
}
113116
jvmArgumentProviders += JavaHomeDir(project, 8)
114117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
java
3+
id("org.graalvm.buildtools.native")
4+
}
5+
6+
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
7+
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
8+
9+
repositories {
10+
maven { url = uri(file(System.getProperty("maven.repo"))) }
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
16+
testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion")
17+
}
18+
19+
tasks.test {
20+
useJUnitPlatform()
21+
22+
val outputDir = reports.junitXml.outputLocation
23+
jvmArgumentProviders += CommandLineArgumentProvider {
24+
listOf(
25+
"-Djunit.platform.reporting.open.xml.enabled=true",
26+
"-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}"
27+
)
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pluginManagement {
2+
plugins {
3+
id("org.graalvm.buildtools.native") version "0.9.13"
4+
}
5+
repositories {
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
}
10+
11+
rootProject.name = "graalvm-starter"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2015-2022 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 com.example.project;
12+
13+
public class Calculator {
14+
15+
public int add(int a, int b) {
16+
return a + b;
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2015-2022 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 com.example.project;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
import org.junit.jupiter.api.DisplayName;
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.params.ParameterizedTest;
18+
import org.junit.jupiter.params.provider.CsvSource;
19+
20+
class CalculatorTests {
21+
22+
@Test
23+
@DisplayName("1 + 1 = 2")
24+
void addsTwoNumbers() {
25+
Calculator calculator = new Calculator();
26+
assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2");
27+
}
28+
29+
@ParameterizedTest(name = "{0} + {1} = {2}")
30+
@CsvSource({
31+
"0, 1, 1",
32+
"1, 2, 3",
33+
"49, 51, 100",
34+
"1, 100, 101"
35+
})
36+
void add(int first, int second, int expectedResult) {
37+
Calculator calculator = new Calculator();
38+
assertEquals(expectedResult, calculator.add(first, second),
39+
() -> first + " + " + second + " should equal " + expectedResult);
40+
}
41+
}

platform-tooling-support-tests/projects/gradle-starter/build.gradle.kts

-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
77
val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION")
88
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
99

10-
// emit default file encoding to a file
11-
file("file.encoding.txt").writeText(System.getProperty("file.encoding"))
12-
file("junit.versions.txt").writeText("""
13-
jupiterVersion=$jupiterVersion
14-
vintageVersion=$vintageVersion
15-
platformVersion=$platformVersion
16-
""")
17-
1810
repositories {
1911
maven { url = uri(file(System.getProperty("maven.repo"))) }
2012
mavenCentral()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2015-2022 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 org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertFalse;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
16+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
17+
import static platform.tooling.support.Helper.TOOL_TIMEOUT;
18+
import static platform.tooling.support.tests.XmlAssertions.verifyContainsExpectedStartedOpenTestReport;
19+
20+
import java.nio.file.Paths;
21+
22+
import de.sormuras.bartholdy.tool.GradleWrapper;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import platform.tooling.support.MavenRepo;
27+
import platform.tooling.support.Request;
28+
29+
/**
30+
* @since 1.9.1
31+
*/
32+
class GraalVmStarterTests {
33+
34+
@Test
35+
void runsTestsInNativeImage() {
36+
var request = Request.builder() //
37+
.setTool(new GradleWrapper(Paths.get(".."))) //
38+
.setProject("graalvm-starter") //
39+
.addArguments("-Dmaven.repo=" + MavenRepo.dir()) //
40+
.addArguments("javaToolchains", "nativeTest", "--no-daemon", "--stacktrace") //
41+
.setTimeout(TOOL_TIMEOUT) //
42+
.build();
43+
44+
var result = request.run();
45+
46+
assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);
47+
48+
assumeFalse(
49+
result.getOutputLines("err").stream().anyMatch(line -> line.contains("No compatible toolchains found")),
50+
"Abort test if GraalVM is not installed");
51+
52+
assertEquals(0, result.getExitCode());
53+
assertTrue(result.getOutputLines("out").stream().anyMatch(line -> line.contains("BUILD SUCCESSFUL")));
54+
55+
var testResultsDir = Request.WORKSPACE.resolve(request.getWorkspace()).resolve("build/test-results/test");
56+
verifyContainsExpectedStartedOpenTestReport(testResultsDir);
57+
}
58+
}

0 commit comments

Comments
 (0)