Files
app/build.gradle.kts
T
Claude d86e24bbca Tests: each run's logs in its own folder, a file for each test
build/test-runs/<date_time>/<module>-<task>/<class>/<test>.log: what
each test printed, as it printed it, and a failure's stack trace (the
root build's listener on every test task, the JVM's and Kotlin/Native's).
A task's folder goes when nothing in it failed, the run's when empty;
the build names a folder it keeps.

The line tools' logs (peer_host, codec_line's filter, fax_line,
t30_line, sip_fax_line), the class 1 and peer line logs, and the
transfer traces into the test's log (TestLogs) instead of /tmp or one
build/ file each run overwrote; peer_host's speaker recording (read by
nothing) gone. The README says where to look.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
2026-10-17 21:13:21 +00:00

69 lines
3.3 KiB
Kotlin

plugins {
alias(libs.plugins.android.application) apply false
// Kotlin's Gradle plugin on the classpath: AGP's built-in Kotlin compiles with this version
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
}
// Each run's test logs: build/test-runs/<date_time>/<module>-<task>/<class>/<test>.log, what each
// test printed (the line tools' logs among it), as it printed it. A task's folder goes once it ends
// with nothing failed, the run's once it's empty: what's left is the runs to look at.
val testRunStamp: String = java.time.LocalDateTime.now()
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"))
val testRunsDir = layout.buildDirectory.dir("test-runs").get().asFile
val testRunDir = File(testRunsDir, testRunStamp)
subprojects {
tasks.withType<AbstractTestTask>().configureEach {
val dir = File(testRunDir, "${project.name}-$name")
if (this is Test) systemProperty("dmodem.testRunDir", dir.path)
val writers = java.util.concurrent.ConcurrentHashMap<String, java.io.Writer>()
fun fileName(s: String) = s.replace(Regex("[^A-Za-z0-9._-]+"), "_").take(150)
fun writer(d: TestDescriptor): java.io.Writer {
val cls = d.className ?: d.parent?.className ?: "_run"
val key = if (d.className != null && d.name != d.className) "${fileName(cls.substringAfterLast('.'))}/${fileName(d.name)}.log"
else "${fileName(cls.substringAfterLast('.'))}/_class.log"
return writers.computeIfAbsent(key) {
File(dir, it).apply { parentFile.mkdirs() }.bufferedWriter()
}
}
doFirst { dir.deleteRecursively() }
addTestOutputListener(object : TestOutputListener {
override fun onOutput(d: TestDescriptor, e: TestOutputEvent) {
val w = writer(d)
synchronized(w) {
w.write(e.message)
w.flush()
}
}
})
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(d: TestDescriptor) {}
override fun afterTest(d: TestDescriptor, r: TestResult) {
// (a failure's stack trace at the end of its log)
if (r.resultType == TestResult.ResultType.FAILURE) {
val w = writer(d)
synchronized(w) {
w.write("\n---- FAILED ----\n")
r.exceptions.forEach { w.write(it.stackTraceToString()) }
w.flush()
}
}
}
override fun afterSuite(suite: TestDescriptor, r: TestResult) {
if (suite.parent != null) return
writers.values.forEach { runCatching { it.close() } }
writers.clear()
if (r.failedTestCount == 0L && r.resultType != TestResult.ResultType.FAILURE) {
dir.deleteRecursively()
if (testRunDir.list()?.isEmpty() == true) testRunDir.delete()
} else {
logger.warn("test logs: ${dir.path}")
}
}
})
}
}