@@ -406,56 +406,63 @@ trait ParallelTesting {
406
406
407
407
private final class RunTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )
408
408
extends Test (testSources, times, threadLimit, suppressAllOutput) {
409
- private def verifyOutput (checkFile : JFile , dir : JFile , testSource : TestSource , warnings : Int ) = try {
409
+
410
+ private def runMain (dir : JFile , testSource : TestSource ): Array [String ] = {
411
+ import java .io .ByteArrayOutputStream
412
+ import java .net .{ URL , URLClassLoader }
413
+
414
+ val printStream = new ByteArrayOutputStream
415
+ try {
410
416
// Do classloading magic and running here:
411
- import java .net .{ URL , URLClassLoader }
412
- import java .io .ByteArrayOutputStream
413
417
val ucl = new URLClassLoader (Array (dir.toURI.toURL))
414
418
val cls = ucl.loadClass(" Test" )
415
419
val meth = cls.getMethod(" main" , classOf [Array [String ]])
416
420
417
- val printStream = new ByteArrayOutputStream
418
421
Console .withOut(printStream) {
419
422
meth.invoke(null , Array (" jvm" )) // partest passes at least "jvm" as an arg
420
423
}
424
+ }
425
+ catch {
426
+ case ex : NoSuchMethodException =>
427
+ echo(s " test in ' $dir' did not contain method: ${ex.getMessage} " )
428
+ failTestSource(testSource)
421
429
422
- val outputLines = printStream.toString(" utf-8" ).lines.toArray
423
- val checkLines = Source .fromFile(checkFile).getLines.toArray
424
-
425
- def linesMatch =
426
- outputLines
427
- .zip(checkLines)
428
- .forall { case (x, y) => x == y }
429
-
430
- if (outputLines.length != checkLines.length || ! linesMatch) {
431
- // Print diff to files and summary:
432
- val diff = outputLines.zip(checkLines).map { case (act, exp) =>
433
- DiffUtil .mkColoredCodeDiff(exp, act, true )
434
- }.mkString(" \n " )
435
- val msg = s " \n Output from run test ' $checkFile' did not match expected, output: \n $diff\n "
436
- echo(msg)
437
- addFailureInstruction(msg)
438
-
439
- // Print build instructions to file and summary:
440
- val buildInstr = testSource.buildInstructions(0 , warnings)
441
- addFailureInstruction(buildInstr)
430
+ case ex : ClassNotFoundException =>
431
+ echo(s " test in ' $dir' did not contain class: ${ex.getMessage} " )
432
+ failTestSource(testSource)
442
433
443
- // Fail target:
434
+ case ex : InvocationTargetException =>
435
+ echo(s " An exception ocurred when running main: ${ex.getCause} " )
444
436
failTestSource(testSource)
445
- }
437
+ }
438
+ printStream.toString(" utf-8" ).lines.toArray
446
439
}
447
- catch {
448
- case ex : NoSuchMethodException =>
449
- echo(s " \n test in ' $dir' did not contain method: ${ex.getMessage}" )
450
- fail()
451
-
452
- case ex : ClassNotFoundException =>
453
- echo(s " \n test in ' $dir' did not contain class: ${ex.getMessage}" )
454
- fail()
455
-
456
- case ex : InvocationTargetException =>
457
- echo(s " \n InvocationTargetException ocurred. Test in ' $dir' might be using args(X) where X > 0 " )
458
- fail()
440
+
441
+ private def verifyOutput (checkFile : JFile , dir : JFile , testSource : TestSource , warnings : Int ) = {
442
+ val outputLines = runMain(dir, testSource)
443
+ val checkLines = Source .fromFile(checkFile).getLines.toArray
444
+
445
+ def linesMatch =
446
+ outputLines
447
+ .zip(checkLines)
448
+ .forall { case (x, y) => x == y }
449
+
450
+ if (outputLines.length != checkLines.length || ! linesMatch) {
451
+ // Print diff to files and summary:
452
+ val diff = outputLines.zip(checkLines).map { case (act, exp) =>
453
+ DiffUtil .mkColoredCodeDiff(exp, act, true )
454
+ }.mkString(" \n " )
455
+ val msg = s " \n Output from run test ' $checkFile' did not match expected, output: \n $diff\n "
456
+ echo(msg)
457
+ addFailureInstruction(msg)
458
+
459
+ // Print build instructions to file and summary:
460
+ val buildInstr = testSource.buildInstructions(0 , warnings)
461
+ addFailureInstruction(buildInstr)
462
+
463
+ // Fail target:
464
+ failTestSource(testSource)
465
+ }
459
466
}
460
467
461
468
protected def compilationRunnable (testSource : TestSource ): Runnable = new Runnable {
@@ -501,6 +508,7 @@ trait ParallelTesting {
501
508
}
502
509
503
510
if (errorCount == 0 && hasCheckFile) verifier()
511
+ else if (errorCount == 0 ) runMain(testSource.outDir, testSource)
504
512
else if (errorCount > 0 ) {
505
513
echo(s " \n Compilation failed for: ' $testSource' " )
506
514
val buildInstr = testSource.buildInstructions(errorCount, warningCount)
0 commit comments