-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing integration test for execution on GraalVM native image
- Loading branch information
1 parent
343170f
commit 7229385
Showing
7 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
platform-tooling-support-tests/projects/graalvm-starter/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
platform-tooling-support-tests/projects/graalvm-starter/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pluginManagement { | ||
plugins { | ||
id("org.graalvm.buildtools.native") version "0.9.13" | ||
} | ||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
rootProject.name = "graalvm-starter" |
19 changes: 19 additions & 0 deletions
19
...-support-tests/projects/graalvm-starter/src/main/java/com/example/project/Calculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ort-tests/projects/graalvm-starter/src/test/java/com/example/project/CalculatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...oling-support-tests/src/test/java/platform/tooling/support/tests/GraalVmStarterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |