test: retrieve raw stdout in example tests, rather than lines

This commit is contained in:
Gleb Koval 2025-02-22 23:38:19 +00:00
parent 82230a5f66
commit c59c28ecbd
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -6,6 +6,7 @@ import org.scalatest.Inspectors.forEvery
import java.io.File
import sys.process._
import java.io.PrintStream
import scala.io.Source
class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with ParallelTestExecution {
val files =
@ -47,7 +48,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with Paral
.drop(outputLineIdx + 1)
.takeWhile(_.startsWith("#"))
.map(_.stripPrefix("#").stripLeading)
.mkString("")
.mkString("\n")
val exitLineIdx = contents.indexWhere(_.matches("^# ?[Ee]xit:.*$"))
val expectedExit =
@ -62,11 +63,16 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with Paral
// Run the executable with the provided input
val stdout = new StringBuilder
// val execResult = s"$execFilename".!(ProcessLogger(stdout.append(_)))
val execResult =
s"echo $inputLine" #| s"timeout 5s $execFilename" ! ProcessLogger(stdout.append(_))
val process = s"timeout 5s $execFilename" run ProcessIO(
in = w => {
w.write(inputLine.getBytes)
w.close()
},
out = Source.fromInputStream(_).addString(stdout),
err = _ => ()
)
assert(execResult == expectedExit)
assert(process.exitValue == expectedExit)
assert(stdout.toString == expectedOutput)
}
}