Skip to content

Commit 97fc839

Browse files
committed
print failing test cases on console using Github's annotations
1 parent b61e430 commit 97fc839

File tree

5 files changed

+61
-38
lines changed

5 files changed

+61
-38
lines changed

.github/junit2annotations.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
import xml.etree.ElementTree as ET
5+
from pathlib import Path
6+
7+
8+
def main():
9+
path = Path(r".") # path to the root dir from where you want to start searching
10+
11+
for t in path.glob("**/TEST-*xml"):
12+
print(t)
13+
tree = ET.parse(t)
14+
root = tree.getroot()
15+
16+
for c in root:
17+
failure = c.find("failure") # failure in test case
18+
if failure is not None:
19+
# ::error file={name},line={line},endLine={endLine},title={title}::{message}
20+
case_name = c.attrib['name']
21+
classname = c.attrib['classname']
22+
message = failure.attrib['message'][0:80]
23+
print(f"::error title=Testcase-missed,file={classname}::Error in test case '{case_name}' and {message}")
24+
25+
if __name__=='__main__': main()

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ jobs:
100100
**/build/test-results/*/*.xml
101101
key.core/build/reports/runallproofs/*
102102
**/build/reports/
103+
- run: "python .github/junit2annotations.py"

build.gradle

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ subprojects {
7474
apply plugin: "com.diffplug.spotless"
7575
apply plugin: "checkstyle"
7676
apply plugin: "pmd"
77+
apply plugin: 'jacoco'
7778
apply plugin: "org.checkerframework"
7879

7980
group = rootProject.group
8081
version = rootProject.version
8182

83+
//conditionally enable jacoco coverage when `-DjacocoEnabled=true` is given on CLI.
84+
def jacocoEnabled = System.properties.getProperty("jacocoEnabled") ?: "false"
85+
8286
java {
8387
sourceCompatibility = 21
8488
targetCompatibility = 21
@@ -136,7 +140,7 @@ subprojects {
136140
systemProperty "testcases", "src/test/resources/testcase"
137141
systemProperty "TACLET_PROOFS", "tacletProofs"
138142
systemProperty "EXAMPLES_DIR", file("$rootProject/key.ui/examples")
139-
systemProperty "RUNALLPROOFS_DIR", layout.buildDirectory.dir("report/runallproves")
143+
systemProperty "RUNALLPROOFS_DIR", layout.buildDirectory.dir("report/runallproves").get().toString()
140144

141145
systemProperty "key.disregardSettings", "true"
142146
maxHeapSize = "4g"
@@ -171,6 +175,10 @@ subprojects {
171175
outputs.upToDateWhen { false }
172176
showStandardStreams = true
173177
}
178+
179+
jacoco {
180+
enabled = jacocoEnabled
181+
}
174182
}
175183

176184
tasks.register('testFast', Test) {
@@ -194,6 +202,10 @@ subprojects {
194202
// by assigning only 'failed' and 'skipped' events
195203
info.events = ["failed", "skipped"]
196204
}
205+
206+
jacoco {
207+
enabled = jacocoEnabled
208+
}
197209
}
198210

199211
// The following two tasks can be used to execute main methods from the project
@@ -285,6 +297,23 @@ subprojects {
285297
}
286298
}
287299

300+
jacoco {
301+
toolVersion = '0.8.12'
302+
}
303+
304+
jacocoTestReport {
305+
reports {
306+
html.required = true
307+
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
308+
xml.required = true
309+
csv.required = false
310+
}
311+
}
312+
313+
test.finalizedBy jacocoTestReport
314+
testFast.finalizedBy jacocoTestReport
315+
316+
288317
spotless {
289318
// see https://github.com/diffplug/spotless/tree/main/plugin-gradle
290319

@@ -543,13 +572,6 @@ tasks.register('alldocJar', Zip){
543572
destinationDirectory = layout.buildDirectory.dir("distribution")
544573
}
545574

546-
//conditionally enable jacoco coverage when `-DjacocoEnabled=true` is given on CLI.
547-
def jacocoEnabled = System.properties.getProperty("jacocoEnabled") ?: "false"
548-
if (jacocoEnabled.toBoolean()) {
549-
project.logger.lifecycle("Jacoco enabled. Test performance will be slower.")
550-
apply from: rootProject.file("scripts/jacocokey.gradle")
551-
}
552-
553575

554576
@Memoized
555577
def getChangedFiles() {

key.core/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ tasks.register('testProveRules', Test) {
133133
description 'Proves KeY taclet rules tagged as lemma'
134134
group "verification"
135135
filter { includeTestsMatching "ProveRulesTest" }
136-
//useJUnitPlatform() {includeTags "testProveRules" }
136+
jacoco { enabled = false }
137137
}
138138

139139
tasks.register('testRunAllFunProofs', Test) {
@@ -142,6 +142,7 @@ tasks.register('testRunAllFunProofs', Test) {
142142
filter {
143143
includeTestsMatching "RunAllProofsFunctional"
144144
}
145+
jacoco { enabled = false }
145146
}
146147

147148
tasks.register('testRunAllInfProofs', Test) {
@@ -150,6 +151,7 @@ tasks.register('testRunAllInfProofs', Test) {
150151
filter {
151152
includeTestsMatching "RunAllProofsInfFlow"
152153
}
154+
jacoco { enabled = false }
153155
}
154156

155157

@@ -159,6 +161,7 @@ tasks.register('testProveSMTLemmas', Test) {
159161
filter {
160162
includeTestsMatching "ProveSMTLemmasTest"
161163
}
164+
jacoco { enabled = false }
162165
}
163166

164167
// Run the tests for the new smt translation in strict mode
@@ -170,6 +173,7 @@ tasks.register('testStrictSMT', Test) {
170173
filter {
171174
includeTestsMatching "MasterHandlerTest"
172175
}
176+
jacoco { enabled = false }
173177
}
174178

175179
//Generation of the three version files within the resources by executing `git'.

scripts/jacocokey.gradle

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)