@@ -208,6 +208,31 @@ object MainModuleTests extends TestSuite {
208208 }
209209
210210 test(" show" ) {
211+ def checkErrStream [T ](errStream : ByteArrayOutputStream )(check : String => T ): T = {
212+ def runCheck (): T =
213+ try {
214+ val strippedErr =
215+ fansi.Str (errStream.toString, errorMode = fansi.ErrorMode .Sanitize ).plainText
216+
217+ check(strippedErr)
218+ } catch {
219+ case ex : utest.AssertionError =>
220+ pprint.err.log(errStream.toString)
221+ throw ex
222+ }
223+
224+ try runCheck()
225+ catch {
226+ case ex : utest.AssertionError if Properties .isWin =>
227+ // On Windows, it seems there can be a delay until the messages land in errStream,
228+ // it's worth retrying
229+ ex.printStackTrace(System .err)
230+ val waitFor = 2 .seconds
231+ System .err.println(s " Caught $ex, trying again in $waitFor" )
232+ Thread .sleep(waitFor.toMillis)
233+ runCheck()
234+ }
235+ }
211236 test(" single" ) {
212237 val outStream = new ByteArrayOutputStream ()
213238 val errStream = new ByteArrayOutputStream ()
@@ -233,15 +258,12 @@ object MainModuleTests extends TestSuite {
233258 assert(value == expected)
234259 assert(shown == expected)
235260
236- // Make sure both stdout and stderr are redirected by `show`
237- // to stderr so that only the JSON file value goes to stdout
238- val strippedErr =
239- fansi.Str (errStream.toString, errorMode = fansi.ErrorMode .Sanitize ).plainText
240-
241- assert(strippedErr.contains(" Hello System Stdout" ))
242- assert(strippedErr.contains(" Hello System Stderr" ))
243- assert(strippedErr.contains(" Hello Console Stdout" ))
244- assert(strippedErr.contains(" Hello Console Stderr" ))
261+ checkErrStream(errStream) { strippedErr =>
262+ assert(strippedErr.contains(" Hello System Stdout" ))
263+ assert(strippedErr.contains(" Hello System Stderr" ))
264+ assert(strippedErr.contains(" Hello Console Stdout" ))
265+ assert(strippedErr.contains(" Hello Console Stderr" ))
266+ }
245267 }
246268 test(" multi" ) {
247269 val outStream = new ByteArrayOutputStream ()
@@ -274,37 +296,15 @@ object MainModuleTests extends TestSuite {
274296 assert(value == expected)
275297 assert(shown == expected)
276298
277- def check (): Unit =
278- try {
279- // Make sure both stdout and stderr are redirected by `show`
280- // to stderr so that only the JSON file value goes to stdout
281- val strippedErr =
282- fansi.Str (errStream.toString, errorMode = fansi.ErrorMode .Sanitize ).plainText
283-
284- assert(strippedErr.contains(" Hello System Stdout" ))
285- assert(strippedErr.contains(" Hello System Stderr" ))
286- assert(strippedErr.contains(" Hello Console Stdout" ))
287- assert(strippedErr.contains(" Hello Console Stderr" ))
288- assert(strippedErr.contains(" Hello2 System Stdout" ))
289- assert(strippedErr.contains(" Hello2 System Stderr" ))
290- assert(strippedErr.contains(" Hello2 Console Stdout" ))
291- assert(strippedErr.contains(" Hello2 Console Stderr" ))
292- } catch {
293- case ex : utest.AssertionError =>
294- pprint.err.log(errStream.toString)
295- throw ex
296- }
297-
298- try check()
299- catch {
300- case ex : utest.AssertionError if Properties .isWin =>
301- // On Windows, it seems there can be a delay until the messages land in errStream,
302- // it's worth retrying
303- ex.printStackTrace(System .err)
304- val waitFor = 2 .seconds
305- System .err.println(s " Caught $ex, trying again in $waitFor" )
306- Thread .sleep(waitFor.toMillis)
307- check()
299+ checkErrStream(errStream) { strippedErr =>
300+ assert(strippedErr.contains(" Hello System Stdout" ))
301+ assert(strippedErr.contains(" Hello System Stderr" ))
302+ assert(strippedErr.contains(" Hello Console Stdout" ))
303+ assert(strippedErr.contains(" Hello Console Stderr" ))
304+ assert(strippedErr.contains(" Hello2 System Stdout" ))
305+ assert(strippedErr.contains(" Hello2 System Stderr" ))
306+ assert(strippedErr.contains(" Hello2 Console Stdout" ))
307+ assert(strippedErr.contains(" Hello2 Console Stderr" ))
308308 }
309309 }
310310
0 commit comments