Skip to content

Commit b293f9c

Browse files
committed
new egg for JUnit5 and preview/incubating
1 parent 539e6f9 commit b293f9c

File tree

12 files changed

+227
-15
lines changed

12 files changed

+227
-15
lines changed

.github/workflows/gradle_test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
name: Java test with Gradle
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches: [ "main" ]
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test-groovy:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: get code
20+
uses: actions/checkout@v3
21+
22+
- name: Set up JDK 19
23+
uses: actions/setup-java@v3
24+
with:
25+
java-version: '19'
26+
distribution: 'adopt'
27+
28+
- name: run build script
29+
run: ./gradle-groovy-test.sh
30+
working-directory: egg__12_sc_junit
31+
32+
test-kotlin:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: get code
37+
uses: actions/checkout@v3
38+
39+
- name: Set up JDK 19
40+
uses: actions/setup-java@v3
41+
with:
42+
java-version: '19'
43+
distribution: 'adopt'
44+
45+
- name: run build script
46+
run: ./gradle-kotlin-test.sh
47+
working-directory: egg__12_sc_junit

build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,37 @@ subprojects { def project ->
44
apply plugin: 'java'
55
apply plugin: 'application'
66

7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
testImplementation(platform('org.junit:junit-bom:5.9.1'))
13+
testImplementation('org.junit.jupiter:junit-jupiter')
14+
}
15+
16+
717
compileJava {
818
options.compilerArgs.addAll(['--release', '19'])
919
options.compilerArgs.addAll(['--enable-preview'])
1020
options.compilerArgs.addAll(['--add-modules', 'jdk.incubator.concurrent'])
1121
}
1222

23+
compileTestJava {
24+
options.compilerArgs.addAll(['--release', '19'])
25+
options.compilerArgs.addAll(['--enable-preview'])
26+
options.compilerArgs.addAll(['--add-modules', 'jdk.incubator.concurrent'])
27+
}
28+
29+
test {
30+
useJUnitPlatform()
31+
jvmArgs('--enable-preview','--add-modules', 'jdk.incubator.concurrent')
32+
33+
testLogging {
34+
events "passed", "skipped", "failed"
35+
}
36+
}
37+
1338
application {
1439
applicationDefaultJvmArgs = ['--enable-preview',
1540
'--add-modules', 'jdk.incubator.concurrent']

egg__12_sc_junit/.sdkmanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Enable auto-env through the sdkman_auto_env config
2+
# Add key=value pairs of SDKs to use below
3+
java=19-open

egg__12_sc_junit/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Summary:
3+
---------
4+
5+
* address how to run JUnit5 with preview/incubating features
6+
* Gradle Groovy & Gradle Kotlin
7+
8+
Build Notes:
9+
------------
10+
11+
* tested with [this jdk](../JDK.version.md)
12+
* tested with [this version](../Gradle.version.md) of Gradle
13+
* tested with [this version](../Maven.version.md) of Maven
14+
15+
To Run (using Gradle):
16+
---------------------
17+
18+
* with Groovy: `./gradle-groovy-test.sh`
19+
* with Kotlin: `./gradle-kotlin-test.sh`
20+
21+
useful commands:
22+
23+
* `sdk env`
24+
- SDKMan! will set JDK to value in `.sdkmanrc`
25+

egg__12_sc_junit/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
repositories {
3+
mavenCentral()
4+
}
5+
6+
dependencies {
7+
testImplementation(platform('org.junit:junit-bom:5.9.1'))
8+
testImplementation('org.junit.jupiter:junit-jupiter')
9+
}
10+
11+
12+
test {
13+
useJUnitPlatform()
14+
jvmArgs('--enable-preview','--add-modules', 'jdk.incubator.concurrent')
15+
16+
testLogging {
17+
events "passed", "skipped", "failed"
18+
}
19+
}

egg__12_sc_junit/build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
kotlin("jvm") version "1.5.31"
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
testImplementation(platform("org.junit:junit-bom:5.9.1"))
14+
testImplementation("org.junit.jupiter:junit-jupiter")
15+
}
16+
17+
tasks.withType<JavaCompile> {
18+
options.compilerArgs.addAll(listOfNotNull(
19+
"--enable-preview",
20+
"--add-modules", "jdk.incubator.concurrent"
21+
))
22+
}
23+
24+
tasks.withType<Test>().configureEach {
25+
useJUnitPlatform()
26+
27+
jvmArgs("--enable-preview", "--add-modules", "jdk.incubator.concurrent")
28+
29+
testLogging {
30+
events("passed", "skipped", "failed")
31+
}
32+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
../gradlew --build-file build.gradle clean test
6+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# nasty hack for now
6+
# TODO: tell Gradle that we don't want to use ../settings.gradle
7+
8+
mv ../settings.gradle ../tmp.settings.gradle
9+
10+
../gradlew \
11+
--build-file build.gradle.kts \
12+
clean test
13+
14+
mv ../tmp.settings.gradle ../settings.gradle
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
package net.codetojoy;
3+
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class TestCanary {
9+
@Test
10+
void simpleAdd() {
11+
// test
12+
var x = 2 + 2;
13+
14+
assertEquals(4, x);
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
package net.codetojoy;
3+
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import jdk.incubator.concurrent.StructuredTaskScope;
9+
10+
// we want to ensure this compiles, runs
11+
class CustomStructuredTaskScope<T> extends StructuredTaskScope<T> {}
12+
13+
public class TestScope {
14+
@Test
15+
void canaryTestForScope() {
16+
// test
17+
var x = 4 + 4;
18+
19+
assertEquals(8, x);
20+
}
21+
}

0 commit comments

Comments
 (0)