Skip to content

Commit

Permalink
Check java version at runtime for TestOpens
Browse files Browse the repository at this point in the history
Now that TestOpens may be run with a different JVM than the one running
Maven, check JVM version at runtime to see if current version is 16 or
higher
  • Loading branch information
laurentgo committed May 21, 2024
1 parent f2edf49 commit 7799be7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 54 deletions.
71 changes: 18 additions & 53 deletions java/memory/memory-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,64 +57,29 @@
<exclude>**/TestOpens.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<!-- Run tests WITHOUT add-opens to make sure we fail-fast -->
<id>opens-tests</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<!-- Do not inherit the default add-opens flag and excludes -->
<argLine combine.self="override"></argLine>
<excludes combine.self="override"></excludes>
<includes>
<include>**/TestOpens.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jdk11+</id>
<activation>
<jdk>[11,]</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<!-- Test is only useful when NOT running with add-opens -->
<exclude>**/TestOpens.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>opens-tests</id>
<!-- Run tests WITHOUT add-opens to make sure we fail-fast -->
<activation>
<jdk>[16,]</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>opens-tests</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<!-- Do not inherit the default add-opens flag and excludes -->
<argLine combine.self="override"></argLine>
<excludes combine.self="override"></excludes>
<includes>
<include>**/TestOpens.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>checkerframework-jdk11+</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.JRE.JAVA_16;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;

public class TestOpens {
/** Instantiating the RootAllocator should poke MemoryUtil and fail. */
@Test
@EnabledForJreRange(min = JAVA_16)
public void testMemoryUtilFailsLoudly() {
// This test is configured by Maven to run WITHOUT add-opens. So this should fail on JDK16+
// (where JEP396 means that add-opens is required to access JDK internals).
Expand Down

0 comments on commit 7799be7

Please sign in to comment.