[2.x] test: Stabilize runner/client tests in CI (sbt#8717)

**Problem**
Runner/client integration tests had CI-only instability from duplicated assertions and a destructive three-command test path.

**Solution**
Refactored version assertions in RunnerScriptTest and replaced the destructive `clean` sequence in ClientTest with a stable non-destructive three-command success path.
This commit is contained in:
it-education-md 2026-02-13 05:41:42 -05:00
parent 03351d6c56
commit 3f95842fd8
2 changed files with 19 additions and 19 deletions

View File

@ -4,6 +4,20 @@ package example.test
* RunnerScriptTest is used to test the sbt shell script, for both macOS/Linux and Windows.
*/
object RunnerScriptTest extends verify.BasicTestSuite with ShellScriptUtil:
private val versionPattern = "\\d(\\.\\d+){2}(-\\w+)?"
private def assertScriptVersion(out: List[String]): Unit =
assert(out.mkString(System.lineSeparator()).trim.matches("^" + versionPattern + "$"))
private def assertVersionOutput(out: List[String]): Unit =
val lines =
out.mkString(System.lineSeparator()).linesIterator.map(_.stripPrefix("[0J").trim).toList
assert(
lines.exists(_.matches("^sbt version in this project: " + versionPattern + "\\r?$")) ||
lines.contains("sbtVersion")
)
assert(lines.exists(_.matches("^sbt runner version: " + versionPattern + "\\r?$")))
assert(!lines.exists(_.contains("failed to connect to server")))
testOutput("sbt -no-colors")("compile", "-no-colors", "-v"): (out: List[String]) =>
assert(out.contains[String]("-Dsbt.log.noformat=true"))
@ -117,42 +131,28 @@ object RunnerScriptTest extends verify.BasicTestSuite with ShellScriptUtil:
"sbt --script-version should print sbtVersion (sbt 1.x project)",
citestVariant = "citest",
)("--script-version"): (out: List[String]) =>
val expectedVersion = "^" + ExtendedRunnerTest.versionRegEx + "$"
assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion))
assertScriptVersion(out)
()
testOutput(
"sbt --script-version should print sbtVersion (sbt 2.x project)",
citestVariant = "citest2",
)("--script-version"): (out: List[String]) =>
val expectedVersion = "^" + ExtendedRunnerTest.versionRegEx + "$"
assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion))
assertScriptVersion(out)
()
testOutput(
"sbt --version should work (sbt 1.x project)",
citestVariant = "citest",
)("--version"): (out: List[String]) =>
val output = out.mkString(System.lineSeparator())
assert(
output.contains("sbt version in this project:") ||
output.contains("sbtVersion")
)
assert(output.contains("sbt runner version:"))
assert(!output.contains("failed to connect to server"))
assertVersionOutput(out)
()
testOutput(
"sbt --version should work (sbt 2.x project)",
citestVariant = "citest2",
)("--version"): (out: List[String]) =>
val output = out.mkString(System.lineSeparator())
assert(
output.contains("sbt version in this project:") ||
output.contains("sbtVersion")
)
assert(output.contains("sbt runner version:"))
assert(!output.contains("failed to connect to server"))
assertVersionOutput(out)
()
testOutput("--sbt-cache")("--sbt-cache", "./cachePath"): (out: List[String]) =>

View File

@ -117,7 +117,7 @@ class ClientTest extends AbstractServerTest {
assert(client("willFail;willSucceed") == 1)
}
test("three commands") {
assert(client("compile;clean;willSucceed") == 0)
assert(client("compile;willSucceed;willSucceed") == 0)
}
test("three commands with middle failure") {
assert(client("compile;willFail;willSucceed") == 1)