[2.x] test: Migrate ProgressStateSpec.scala to verify.BasicTestSuite (#8549)

Migrate ProgressStateSpec.scala from ScalaTest's AnyFlatSpec with
BeforeAndAfterAll to verify.BasicTestSuite, following the pattern
established by other test files in the sbt codebase.

Changes:
- Replace AnyFlatSpec class with BasicTestSuite object
- Remove BeforeAndAfterAll trait and convert afterAll to try-finally
- Use scala.util.Using.resource for proper resource management
- Convert 'should ... in' syntax to 'test(...)' syntax
- Use Scala 3 syntax with colon indentation
- Change === to == for assertions
- Add 'end ProgressStateSpec' marker

Related to the ongoing test migration effort.

Co-authored-by: GlobalStar117 <GlobalStar117@users.noreply.github.com>
This commit is contained in:
E.G 2026-01-16 06:04:38 +11:00 committed by GitHub
parent dce915e794
commit 0760f77881
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 24 deletions

View File

@ -10,34 +10,30 @@ package sbt.internal.util
import java.io.{ File, PrintStream }
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.BeforeAndAfterAll
import verify.BasicTestSuite
import sbt.internal.util.Terminal.SimpleTerminal
import scala.io.Source
import scala.util.Using
class ProgressStateSpec extends AnyFlatSpec with BeforeAndAfterAll {
object ProgressStateSpec extends BasicTestSuite:
private lazy val fileIn = new File("/tmp/tmp.txt")
private lazy val fileOut = Source.fromFile("/tmp/tmp.txt")
test("test should not clear after carriage return (\\r)"):
val fileIn = new File("/tmp/tmp.txt")
try
val ps = new ProgressState(1, 8)
val in = "Hello\r\nWorld".getBytes()
override def afterAll(): Unit = {
fileIn.delete()
fileOut.close()
super.afterAll()
}
ps.write(SimpleTerminal, in, new PrintStream(fileIn), hasProgress = true)
"test" should "not clear after carriage return (\\r) " in {
val ps = new ProgressState(1, 8)
val in = "Hello\r\nWorld".getBytes()
ps.write(SimpleTerminal, in, new PrintStream(fileIn), hasProgress = true)
val clearScreenBytes = ConsoleAppender.ClearScreenAfterCursor.getBytes("UTF-8")
val check = fileOut.getLines().toList.map { line =>
line.getBytes("UTF-8").endsWith(clearScreenBytes)
}
assert(check === List(false, true))
}
}
Using.resource(Source.fromFile("/tmp/tmp.txt")) { fileOut =>
val clearScreenBytes = ConsoleAppender.ClearScreenAfterCursor.getBytes("UTF-8")
val check = fileOut.getLines().toList.map { line =>
line.getBytes("UTF-8").endsWith(clearScreenBytes)
}
assert(check == List(false, true))
}
finally
fileIn.delete()
()
end ProgressStateSpec