Skip to content

Commit

Permalink
Adds back the JUnit testing system (#4979)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLimeGlass authored Mar 8, 2023
1 parent e7ea29f commit 2334e0a
Show file tree
Hide file tree
Showing 44 changed files with 1,582 additions and 277 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/junit-17-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: JUnit (MC 1.17+)

on:
push:
branches:
- master
- 'dev/**'
pull_request:

jobs:
build:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Skript and run JUnit
run: ./gradlew clean JUnitJava17
27 changes: 27 additions & 0 deletions .github/workflows/junit-8-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: JUnit (MC 1.13-1.16)

on:
push:
branches:
- master
- 'dev/**'
pull_request:

jobs:
build:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build Skript and run JUnit
run: ./gradlew clean JUnitJava8
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,6 @@ gradle-app.setting

# End of https://www.toptal.com/developers/gitignore/api/intellij+all,gradle,java,eclipse,git

# Skript test runners
# TODO remove this in the future after some time since https://github.com/SkriptLang/Skript/pull/4979
# This ensures developers don't upload their old existing test_runners/ folder.
test_runners/
80 changes: 56 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ plugins {
id 'java'
}

configurations {
testImplementation.extendsFrom testShadow
}

allprojects {
repositories {
mavenCentral()
Expand All @@ -31,7 +35,11 @@ dependencies {
implementation group: 'net.milkbowl.vault', name: 'Vault', version: '1.7.1', {
exclude group: 'org.bstats', module: 'bstats-bukkit'
}

implementation fileTree(dir: 'lib', include: '*.jar')

testShadow group: 'junit', name: 'junit', version: '4.12'
testShadow group: 'org.easymock', name: 'easymock', version: '4.2'
}

compileJava.options.encoding = 'UTF-8'
Expand All @@ -47,6 +55,12 @@ task checkAliases {
}
}

task testJar(type: ShadowJar) {
dependsOn(compileTestJava, licenseTest)
archiveName 'Skript-JUnit.jar'
from sourceSets.test.output, sourceSets.main.output, project.configurations.testShadow
}

task jar(overwrite: true, type: ShadowJar) {
dependsOn checkAliases
archiveName jarName ? 'Skript.jar' : jarName
Expand All @@ -64,7 +78,7 @@ task relocateShadowJar(type: ConfigureShadowRelocation) {

task sourceJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = "sources"
archiveClassifier = 'sources'
}

tasks.withType(ShadowJar) {
Expand Down Expand Up @@ -106,8 +120,8 @@ processResources {
publishing {
publications {
maven(MavenPublication) {
groupId "com.github.SkriptLang"
artifactId "Skript"
groupId 'com.github.SkriptLang'
artifactId 'Skript'
version project.version
artifact sourceJar
artifact tasks.jar
Expand All @@ -116,11 +130,11 @@ publishing {

repositories {
maven {
name = "repo"
url = "https://repo.skriptlang.org/releases"
name = 'repo'
url = 'https://repo.skriptlang.org/releases'
credentials {
username = System.getenv("MAVEN_USERNAME")
password = System.getenv("MAVEN_PASSWORD")
username = System.getenv('MAVEN_USERNAME')
password = System.getenv('MAVEN_PASSWORD')
}
}
}
Expand Down Expand Up @@ -167,9 +181,15 @@ tasks.register('testNaming') {
}

// Create a test task with given name, environments dir/file, dev mode and java version.
void createTestTask(String name, String environments, boolean devMode, int javaVersion, boolean genDocs) {
void createTestTask(String name, String desc, String environment, boolean devMode, int javaVersion, boolean genDocs, boolean junit) {
tasks.register(name, JavaExec) {
dependsOn nightlyRelease, testNaming
description = desc;
dependsOn licenseTest
if (junit) {
dependsOn testJar
} else {
dependsOn nightlyRelease, testNaming
}
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
Expand All @@ -178,18 +198,19 @@ void createTestTask(String name, String environments, boolean devMode, int javaV
}
group = 'execution'
classpath = files([
'build' + File.separator + 'libs' + File.separator + 'Skript-nightly.jar',
'build' + File.separator + 'libs' + File.separator + (junit ? 'Skript-JUnit.jar' : 'Skript-nightly.jar'),
project.configurations.runtimeClasspath.find { it.name.startsWith('gson') },
sourceSets.main.runtimeClasspath
])
main = 'ch.njol.skript.tests.platform.PlatformMain'
main = 'ch.njol.skript.test.platform.PlatformMain'
args = [
'test_runners',
'src/test/skript/tests',
'build/test_runners',
junit ? 'src/test/skript/tests/junit' : 'src/test/skript/tests',
'src/test/resources/runner_data',
environments,
environment,
devMode,
genDocs
genDocs,
junit
]
}
}
Expand All @@ -199,20 +220,31 @@ def latestJava = 17
def oldestJava = 8

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ["-source", "" + oldestJava, "-target", "" + oldestJava]
options.compilerArgs += ['-source', '' + oldestJava, '-target', '' + oldestJava]
}

createTestTask('JUnitQuick', 'Runs JUnit tests on one environment being the latest supported Java and Minecraft.', 'src/test/skript/environments/' + latestEnv, false, latestJava, false, true)
createTestTask('JUnitJava17', 'Runs JUnit tests on all Java 17 environments.', 'src/test/skript/environments/java17', false, latestJava, false, true)
createTestTask('JUnitJava8', 'Runs JUnit tests on all Java 8 environments.', 'src/test/skript/environments/java8', false, oldestJava, false, true)
tasks.register('JUnit') {
description = 'Runs JUnit tests on all environments.'
dependsOn JUnitJava8, JUnitJava17
}

// Register different Skript testing tasks
createTestTask('quickTest', 'src/test/skript/environments/' + latestEnv, false, latestJava, false)
createTestTask('skriptTestJava17', 'src/test/skript/environments/java17', false, latestJava, false)
createTestTask('skriptTestJava8', 'src/test/skript/environments/java8', false, oldestJava, false)
createTestTask('skriptTestDev', 'src/test/skript/environments/' + (project.property('testEnv') == null
createTestTask('quickTest', 'Runs tests on one environment being the latest supported Java and Minecraft.', 'src/test/skript/environments/' + latestEnv, false, latestJava, false, false)
createTestTask('skriptTestJava17', 'Runs tests on all Java 17 environments.', 'src/test/skript/environments/java17', false, latestJava, false, false)
createTestTask('skriptTestJava8', 'Runs tests on all Java 8 environments.', 'src/test/skript/environments/java8', false, oldestJava, false, false)
createTestTask('skriptTestDev', 'Runs testing server and uses \'system.in\' for command input, stop server to finish.', 'src/test/skript/environments/' + (project.property('testEnv') == null
? latestEnv : project.property('testEnv') + '.json'), true, Integer.parseInt(project.property('testEnvJavaVersion') == null
? latestJava : project.property('testEnvJavaVersion')), false)
tasks.register('skriptTest') {dependsOn skriptTestJava8, skriptTestJava17}
createTestTask('genDocs', 'src/test/skript/environments/' + (project.property('testEnv') == null
? latestJava : project.property('testEnvJavaVersion')), false, false)
tasks.register('skriptTest') {
description = 'Runs tests on all environments.'
dependsOn skriptTestJava8, skriptTestJava17
}
createTestTask('genDocs', 'Generates the Skript documentation website html files.', 'src/test/skript/environments/' + (project.property('testEnv') == null
? latestEnv : project.property('testEnv') + '.json'), false, Integer.parseInt(project.property('testEnvJavaVersion') == null
? latestJava : project.property('testEnvJavaVersion')), true)
? latestJava : project.property('testEnvJavaVersion')), true, false)

// Build flavor configurations
task githubResources(type: ProcessResources) {
Expand Down
Loading

0 comments on commit 2334e0a

Please sign in to comment.