Skip to content

Commit 7f9f779

Browse files
committed
add functional tests for new maven switches
1 parent fc21824 commit 7f9f779

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
package org.graalvm.buildtools.maven
43+
44+
class MavenTestExecutionFunctionalTests extends AbstractGraalVMMavenFunctionalTest {
45+
def "test if the skipTestExecution flag skips execution of tests"() {
46+
withSample("java-application-with-tests")
47+
48+
when:
49+
mvn '-DquickBuild', '-DskipTestExecution=true', '-Pnative', 'test'
50+
51+
then:
52+
buildSucceeded
53+
outputContains "GraalVM Native Image: Generating 'native-tests' (executable)"
54+
outputDoesNotContain "containers found"
55+
outputDoesNotContain "containers skipped"
56+
outputDoesNotContain "containers started"
57+
outputDoesNotContain "tests found"
58+
outputDoesNotContain "tests skipped"
59+
outputDoesNotContain "tests started"
60+
}
61+
62+
def "test if setting the failNoTests flag allows build to continue if no tests are present"() {
63+
// withSample("non-native")
64+
withSample("java-application")
65+
66+
when:
67+
mvn '-DquickBuild', '-DfailNoTests=false', '-Pnative', 'test'
68+
69+
then:
70+
buildSucceeded
71+
outputContains "No tests found, skipping."
72+
}
73+
}

samples/non-native/pom.xml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
6+
The Universal Permissive License (UPL), Version 1.0
7+
8+
Subject to the condition set forth below, permission is hereby granted to any
9+
person obtaining a copy of this software, associated documentation and/or
10+
data (collectively the "Software"), free of charge and under any and all
11+
copyright rights in the Software, and any and all patent rights owned or
12+
freely licensable by each licensor hereunder covering either (i) the
13+
unmodified Software as contributed to or provided by such licensor, or (ii)
14+
the Larger Works (as defined below), to deal in both
15+
16+
(a) the Software, and
17+
18+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
19+
one is included with the Software each a "Larger Work" to which the Software
20+
is contributed by such licensors),
21+
22+
without restriction, including without limitation the rights to copy, create
23+
derivative works of, display, perform, and distribute the Software and make,
24+
use, sell, offer for sale, import, export, have made, and have sold the
25+
Software and the Larger Work(s), and to sublicense the foregoing rights on
26+
either these or other terms.
27+
28+
This license is subject to the following condition:
29+
30+
The above copyright notice and either this complete permission notice or at a
31+
minimum a reference to the UPL must be included in all copies or substantial
32+
portions of the Software.
33+
34+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40+
SOFTWARE.
41+
-->
42+
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
44+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
45+
<modelVersion>4.0.0</modelVersion>
46+
47+
<groupId>org.graalvm.buildtools.examples</groupId>
48+
<artifactId>maven</artifactId>
49+
<version>1.0.0-SNAPSHOT</version>
50+
51+
<properties>
52+
<java.version>1.8</java.version>
53+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
54+
<native.maven.plugin.version>0.11.1-SNAPSHOT</native.maven.plugin.version>
55+
<junit.platform.native.version>0.11.1-SNAPSHOT</junit.platform.native.version>
56+
<imageName>example-app</imageName>
57+
<mainClass>org.graalvm.demo.Application</mainClass>
58+
</properties>
59+
60+
<dependencies>
61+
<dependency>
62+
<groupId>org.apache.commons</groupId>
63+
<artifactId>commons-lang3</artifactId>
64+
<version>3.8.1</version>
65+
</dependency>
66+
</dependencies>
67+
68+
<profiles>
69+
<profile>
70+
<id>native</id>
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.graalvm.buildtools</groupId>
75+
<artifactId>native-maven-plugin</artifactId>
76+
<version>${native.maven.plugin.version}</version>
77+
<extensions>true</extensions>
78+
<executions>
79+
<execution>
80+
<id>test-native</id>
81+
<goals>
82+
<goal>test</goal>
83+
</goals>
84+
<phase>test</phase>
85+
</execution>
86+
<execution>
87+
<id>build-native</id>
88+
<goals>
89+
<goal>compile-no-fork</goal>
90+
</goals>
91+
<phase>package</phase>
92+
</execution>
93+
</executions>
94+
<configuration>
95+
<skip>false</skip>
96+
<imageName>${imageName}</imageName>
97+
<fallback>false</fallback>
98+
</configuration>
99+
</plugin>
100+
</plugins>
101+
</build>
102+
</profile>
103+
</profiles>
104+
105+
<build>
106+
<finalName>${project.artifactId}</finalName>
107+
<plugins>
108+
<plugin>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-surefire-plugin</artifactId>
111+
<version>3.0.0-M5</version>
112+
</plugin>
113+
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-compiler-plugin</artifactId>
117+
<version>3.8.1</version>
118+
<configuration>
119+
<source>${java.version}</source>
120+
<target>1.8</target>
121+
</configuration>
122+
</plugin>
123+
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-jar-plugin</artifactId>
127+
<version>3.2.2</version>
128+
<configuration>
129+
<archive>
130+
<manifest>
131+
<addClasspath>true</addClasspath>
132+
<mainClass>${mainClass}</mainClass>
133+
</manifest>
134+
</archive>
135+
</configuration>
136+
</plugin>
137+
138+
<plugin>
139+
<groupId>org.codehaus.mojo</groupId>
140+
<artifactId>exec-maven-plugin</artifactId>
141+
<version>3.0.0</version>
142+
<executions>
143+
<execution>
144+
<id>java</id>
145+
<goals>
146+
<goal>java</goal>
147+
</goals>
148+
<configuration>
149+
<mainClass>${mainClass}</mainClass>
150+
</configuration>
151+
</execution>
152+
<execution>
153+
<id>native</id>
154+
<goals>
155+
<goal>exec</goal>
156+
</goals>
157+
<configuration>
158+
<executable>${project.build.directory}/${imageName}</executable>
159+
<workingDirectory>${project.build.directory}</workingDirectory>
160+
</configuration>
161+
</execution>
162+
</executions>
163+
</plugin>
164+
</plugins>
165+
</build>
166+
167+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.graalvm.demo;
2+
3+
public class Application {
4+
private static final String MESSAGE = System.getenv("CUSTOM_MESSAGE");
5+
6+
public static void main(String[] args) {
7+
System.out.println(MESSAGE != null ? MESSAGE : "Hello, native!");
8+
}
9+
}

0 commit comments

Comments
 (0)