mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 03:00:30 +00:00
Measure code coverage from in-game tests
More importantly, `./gradlew check' actually runs the in-game tests, which makes the CI steps look a little more sensible again. Somewhat depressing that one of the longest files (15th) in CC:T is the build script.
This commit is contained in:
parent
9ae0f4a993
commit
e1e7ef59c6
9
.github/workflows/main-ci.yml
vendored
9
.github/workflows/main-ci.yml
vendored
@ -24,13 +24,10 @@ jobs:
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build --no-daemon || ./gradlew build --no-daemon
|
||||
|
||||
- name: Run in-game tests
|
||||
run: |
|
||||
./gradlew setupServer --no-daemon
|
||||
./gradlew prepareRunTestServerRun --no-daemon || ./gradlew prepareRunTestServerRun --no-daemon
|
||||
./gradlew runTestServerRun --no-daemon
|
||||
./gradlew assemble --no-daemon || ./gradlew assemble --no-daemon
|
||||
./gradlew downloadAssets --no-daemon || ./gradlew downloadAssets --no-daemon
|
||||
./gradlew build
|
||||
|
||||
- name: Upload Jar
|
||||
uses: actions/upload-artifact@v1
|
||||
|
60
build.gradle
60
build.gradle
@ -86,13 +86,6 @@ minecraft {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testServerRun {
|
||||
parent runs.testServer
|
||||
property 'forge.logging.console.level', 'info'
|
||||
property 'cctest.run', 'true'
|
||||
forceExit false
|
||||
}
|
||||
}
|
||||
|
||||
mappings channel: 'official', version: project.mc_version
|
||||
@ -392,6 +385,7 @@ test {
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
dependsOn('test')
|
||||
reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
@ -440,6 +434,9 @@ task licenseFormatAPI(type: LicenseFormat);
|
||||
}
|
||||
|
||||
task setupServer(type: Copy) {
|
||||
group "test server"
|
||||
description "Sets up the environment for the test server."
|
||||
|
||||
from("src/test/server-files") {
|
||||
include "eula.txt"
|
||||
include "server.properties"
|
||||
@ -447,6 +444,55 @@ task setupServer(type: Copy) {
|
||||
into "test-files/server"
|
||||
}
|
||||
|
||||
tasks.register('testInGame', JavaExec.class).configure {
|
||||
it.group('test server')
|
||||
it.description("Runs tests on a temporary Minecraft server.")
|
||||
it.dependsOn(setupServer, 'prepareRunTestServer')
|
||||
|
||||
// Copy from runTestServer. We do it in this slightly odd way as runTestServer
|
||||
// isn't created until the task is configured (which is no good for us).
|
||||
JavaExec exec = tasks.getByName('runTestServer')
|
||||
it.setWorkingDir(exec.getWorkingDir())
|
||||
it.setSystemProperties(exec.getSystemProperties())
|
||||
it.setBootstrapClasspath(exec.getBootstrapClasspath())
|
||||
it.setClasspath(exec.getClasspath())
|
||||
it.setMain(exec.getMain())
|
||||
it.setEnvironment(exec.getEnvironment())
|
||||
it.setArgs(exec.getArgs())
|
||||
it.setJvmArgs(exec.getJvmArgs())
|
||||
|
||||
it.systemProperty('forge.logging.console.level', 'info')
|
||||
it.systemProperty('cctest.run', 'true')
|
||||
|
||||
// Jacoco and modlauncher don't play well together as the classes loaded in-game don't
|
||||
// match up with those written to disk. We get Jacoco to dump all classes to disk, and
|
||||
// use that when generating the report.
|
||||
def coverageOut = new File(buildDir, 'jacocoClassDump/testInGame')
|
||||
jacoco.applyTo(it)
|
||||
it.jacoco.setIncludes(["dan200.computercraft.*"])
|
||||
it.jacoco.setClassDumpDir(coverageOut)
|
||||
// Older versions of modlauncher don't include a protection domain (and thus no code
|
||||
// source). Jacoco skips such classes by default, so we need to explicitly include them.
|
||||
it.jacoco.setIncludeNoLocationClasses(true)
|
||||
}
|
||||
|
||||
tasks.register('jacocoTestInGameReport', JacocoReport.class).configure {
|
||||
it.group('test server')
|
||||
it.description('Generate coverage reports for in-game tests (testInGame)')
|
||||
it.dependsOn('testInGame')
|
||||
|
||||
it.executionData(new File(buildDir, 'jacoco/testInGame.exec'))
|
||||
it.setSourceDirectories(project.files(sourceSets.main.allJava.srcDirs))
|
||||
it.setClassDirectories(project.files(new File(buildDir, 'jacocoClassDump/testInGame')))
|
||||
|
||||
it.reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
}
|
||||
}
|
||||
check.dependsOn('jacocoTestInGameReport')
|
||||
|
||||
|
||||
// Upload tasks
|
||||
|
||||
task checkRelease {
|
||||
|
@ -21,6 +21,6 @@ Prints each key when the user presses it, and if the key is being held.
|
||||
```lua
|
||||
while true do
|
||||
local event, key, is_held = os.pullEvent("key")
|
||||
print(("%s held=%b"):format(keys.getName(key), is_held))
|
||||
print(("%s held=%s"):format(keys.getName(key), is_held))
|
||||
end
|
||||
```
|
||||
|
@ -1,5 +1,4 @@
|
||||
#Minecraft server properties
|
||||
#Fri Jan 08 18:54:30 GMT 2021
|
||||
# Minecraft server properties
|
||||
allow-flight=false
|
||||
allow-nether=true
|
||||
broadcast-console-to-ops=true
|
||||
|
Loading…
Reference in New Issue
Block a user