[2.x] fix: Fix scripted test loading build definition twice on first test in batch (#8946)

This commit is contained in:
BitToby 2026-03-20 21:45:36 +02:00 committed by GitHub
parent 132443b16e
commit 1852b4a454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 8 deletions

View File

@ -238,19 +238,21 @@ final class ScriptedTests(
IO.copyDirectory(originalDir, tempTestDir)
val runTest = () => {
// Reload and initialize (to reload contents of .sbtrc files)
def sbtHandlerError = sys error "Missing sbt handler. Scripted is misconfigured."
val sbtHandler = handlers.getOrElse('>', sbtHandlerError)
val statement = Statement("reload;initialize", Nil, successExpected = true, line = -1)
// Run reload inside the hook to reuse error handling for pending tests
val wrapHook = (file: File) => {
preHook(file)
try runner.processStatement(sbtHandler, statement, states)
catch {
case t: Throwable =>
val newMsg = "Reload for scripted batch execution failed."
throw new TestException(statement, newMsg, t)
// Reload only when a previous sbt instance exists; a new instance already loads the project on boot
if (states(sbtHandler) != None) {
val statement =
Statement("reload;initialize", Nil, successExpected = true, line = -1)
try runner.processStatement(sbtHandler, statement, states)
catch {
case t: Throwable =>
val newMsg = "Reload for scripted batch execution failed."
throw new TestException(statement, newMsg, t)
}
}
}