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