This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle.kts
131 lines (116 loc) · 4.79 KB
/
build.gradle.kts
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// Kotlin
val ktVersion: String by System.getProperties()
kotlin("jvm") version ktVersion
}
repositories {
jcenter() // or maven(url="https://dl.bintray.com/kotlin/dokka")
mavenCentral()
}
// Allow testResults to be accessed in sub-projects if needed.
val testResults: MutableList<String> by extra { mutableListOf() }
allprojects {
group = "diffkt"
apply(plugin = "java")
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
kotlinOptions.freeCompilerArgs += "-XXLanguage:+ProperCheckAnnotationsTargetInTypeUsePositions"
}
repositories {
jcenter()
maven(url = "https://maven.openrndr.org")
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
}
tasks.withType<Test> {
maxHeapSize = "8g"
// Filter out GPU tests by default
if (!project.hasProperty("gpu"))
systemProperties["kotest.tags.exclude"] = "Gpu"
testLogging {
events = setOf(
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
// set options for log level DEBUG and INFO
debug {
events = this@testLogging.events + org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
info {
events = debug.events
exceptionFormat = debug.exceptionFormat
}
}
addTestListener(object : TestListener {
override fun beforeTest(descriptor: TestDescriptor?) = Unit
override fun afterTest(descriptor: TestDescriptor?, result: TestResult?) = Unit
override fun beforeSuite(descriptor: TestDescriptor?) = Unit
override fun afterSuite(descriptor: TestDescriptor?, result: TestResult?) {
result?.let {
if (descriptor?.parent == null) { // Only summarize for a whole (sub) project
val summary = """
${this@withType.project.name}:${this@withType.name} results: ${it.resultType} (${it.testCount} tests, ${it.successfulTestCount} passed, ${it.failedTestCount} failed, ${it.skippedTestCount} skipped)
Report file: ${this@withType.reports.html.entryPoint}
""".trimIndent()
if (it.resultType == TestResult.ResultType.SUCCESS) {
testResults.add(0, summary)
} else {
testResults += summary
}
}
}
}
})
useJUnitPlatform()
}
}
subprojects {
apply(plugin = "kotlin")
val kotestVersion: String by System.getProperties()
val junitVersion: String by System.getProperties()
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("org.apache.commons:commons-compress:1.2")
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion")
?.because("kotest framework")
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit", junitVersion))
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
?.because("kotest core jvm assertions")
}
}
// Define a pretty printer for test results
fun printResults(results: List<String>) {
val maxLength = results.flatMap { it.lines().map { it.length } }.max() ?: 0
println("┌${"─".repeat(maxLength + 2)}┐")
println(
results.joinToString("\n├${"─".repeat(maxLength + 2)}┤\n") {
it.lines().joinToString("\n") { "│ $it${" ".repeat(maxLength - it.length)} │" }
}
)
println("└${"─".repeat(maxLength + 2)}┘")
}
// Print results when build is finished
gradle.buildFinished {
if (testResults.isNotEmpty()) {
printResults(testResults)
}
}