-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
182 lines (159 loc) · 6.06 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* This is a build file for a downstream project for the EISOP Checker Framework
* that runs the JSpecify conformance tests.
*/
plugins {
id 'java-library'
// Code formatting; defines targets "spotlessApply" and "spotlessCheck"
// Requires JDK 11 or higher; the plugin crashes under JDK 8.
id 'com.diffplug.spotless' version '6.25.0'
// Checker Framework pluggable type-checking
id 'org.checkerframework' version '0.6.45'
}
repositories {
// Snapshot repository for JSpecify conformance test framework
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots'}
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/'}
mavenCentral()
}
java {
sourceCompatibility = 1.9
targetCompatibility = 1.9
}
configurations {
jSpecifyConformanceTests
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation libs.junit
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation libs.jspecify.conformance.framework
jSpecifyConformanceTests libs.jspecify.conformance.tests
}
// To use a locally-built Checker Framework, run gradle with "-PcfLocal".
if (hasProperty('cfLocal')) {
def cfHome = String.valueOf(System.getenv('CHECKERFRAMEWORK'))
dependencies {
testImplementation files(cfHome + '/checker/dist/checker.jar')
testImplementation files(cfHome + '/checker/dist/checker-qual.jar')
def frameworkTestTree = fileTree(dir: cfHome + '/framework-test/build/libs',
include: '*.jar',
exclude: [
'*-sources.jar',
'*-javadoc.jar'
])
if (frameworkTestTree.files.size() != 1) {
logger.warn("Expected exactly one framework-test jar, but found " + frameworkTestTree.files.size() + " jars.")
}
testImplementation frameworkTestTree
testImplementation libs.plume.utils
}
} else {
dependencies {
testImplementation libs.checkerframework.checker
testImplementation libs.checkerframework.framework.test
testImplementation libs.checkerframework.qual
}
}
spotless {
format 'misc', {
// define the files to apply `misc` to
target '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
java {
googleJavaFormat()
formatAnnotations()
}
groovyGradle {
target '**/*.gradle'
greclipse() // which formatter Spotless should use to format .gradle files.
indentWithSpaces(2)
trimTrailingWhitespace()
// endWithNewline() // Don't want to end empty files with a newline
}
}
// Unzip JSpecify conformance tests using the artifact
task unzipJSpecifyConformanceTestSuite(type: Copy) {
description 'Unzips the JSpecify conformance test suite into the build directory.'
dependsOn(configurations.jSpecifyConformanceTests)
from zipTree(configurations.jSpecifyConformanceTests.singleFile)
into "${buildDir}/jspecify-conformance-tests"
}
// Run JSpecify conformance tests
test {
useJUnitPlatform()
jvmArgs(
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED'
)
// Conformance tests
inputs.files(unzipJSpecifyConformanceTestSuite)
inputs.files("${projectDir}/src/test/resources/jspecify-conformance-test-report.txt")
doFirst {
systemProperties([
"ConformanceTest.inputs": "${buildDir}/jspecify-conformance-tests/assertions/org/jspecify/conformance/tests",
"ConformanceTest.report": "${projectDir}/src/test/resources/jspecify-conformance-test-report.txt",
"ConformanceTest.deps" : fileTree("${buildDir}/jspecify-conformance-tests/deps").join(":")
])
}
// Conformance tests on samples
inputs.files("${projectDir}/src/test/resources/jspecify-conformance-test-on-samples-report.txt")
doFirst {
systemProperties([
"ConformanceTest.samples.inputs": "${buildDir}/jspecify-conformance-tests/samples",
"ConformanceTest.samples.report": "${projectDir}/src/test/resources/jspecify-conformance-test-on-samples-report.txt",
])
}
testLogging {
showStackTraces = true
showStandardStreams = true
events "failed"
exceptionFormat "full"
}
afterTest { desc, result ->
if (result.resultType == TestResult.ResultType.FAILURE) {
println "Oh no! There are failed conformance tests!"
result.failures.each { failure ->
def rawFailure = failure.rawFailure
def matcher = rawFailure =~ /\+FAIL: (\S+):(\d+):/
matcher.each { match ->
def fileName = match[1]
def lineNumber = match[2].toInteger()
println "Test failed in file: ${fileName}"
println "Test failed at line number: ${lineNumber}"
def conformanceInputs = System.getProperty('ConformanceTest.inputs')
if (conformanceInputs == null) {
conformanceInputs = "${buildDir}/jspecify-conformance-tests/assertions/org/jspecify/conformance/tests"
}
def filePath = "${conformanceInputs}/${fileName}"
println "Test failed directory: ${filePath}"
def file = new File(filePath)
if (file.exists()) {
def lines = file.readLines()
def start = Math.max(0, lineNumber - 3)
def end = Math.min(lines.size(), lineNumber + 2)
println "Code around the failure:"
for (int i = start; i < end; i++) {
println "${i + 1}: ${lines[i]}"
}
println ""
} else {
println "File not found: ${filePath}"
}
}
}
}
}
}