1
0
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:
Jonathan Coates 2021-01-15 09:54:38 +00:00
parent 9ae0f4a993
commit e1e7ef59c6
4 changed files with 58 additions and 16 deletions

View File

@ -24,13 +24,10 @@ jobs:
${{ runner.os }}-gradle- ${{ runner.os }}-gradle-
- name: Build with Gradle - name: Build with Gradle
run: ./gradlew build --no-daemon || ./gradlew build --no-daemon
- name: Run in-game tests
run: | run: |
./gradlew setupServer --no-daemon ./gradlew assemble --no-daemon || ./gradlew assemble --no-daemon
./gradlew prepareRunTestServerRun --no-daemon || ./gradlew prepareRunTestServerRun --no-daemon ./gradlew downloadAssets --no-daemon || ./gradlew downloadAssets --no-daemon
./gradlew runTestServerRun --no-daemon ./gradlew build
- name: Upload Jar - name: Upload Jar
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1

View File

@ -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 mappings channel: 'official', version: project.mc_version
@ -392,6 +385,7 @@ test {
} }
jacocoTestReport { jacocoTestReport {
dependsOn('test')
reports { reports {
xml.enabled true xml.enabled true
html.enabled true html.enabled true
@ -440,6 +434,9 @@ task licenseFormatAPI(type: LicenseFormat);
} }
task setupServer(type: Copy) { task setupServer(type: Copy) {
group "test server"
description "Sets up the environment for the test server."
from("src/test/server-files") { from("src/test/server-files") {
include "eula.txt" include "eula.txt"
include "server.properties" include "server.properties"
@ -447,6 +444,55 @@ task setupServer(type: Copy) {
into "test-files/server" 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 // Upload tasks
task checkRelease { task checkRelease {

View File

@ -21,6 +21,6 @@ Prints each key when the user presses it, and if the key is being held.
```lua ```lua
while true do while true do
local event, key, is_held = os.pullEvent("key") 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 end
``` ```

View File

@ -1,5 +1,4 @@
#Minecraft server properties # Minecraft server properties
#Fri Jan 08 18:54:30 GMT 2021
allow-flight=false allow-flight=false
allow-nether=true allow-nether=true
broadcast-console-to-ops=true broadcast-console-to-ops=true