From 4af97e33e7f60e61df1483af3605050a3af5dfb6 Mon Sep 17 00:00:00 2001 From: Aleksandar Pokopec Date: Fri, 8 Oct 2010 14:42:45 +0000 Subject: Added more complete output if tests fail. Log file is printed now right away if: - test fails due to an exception thrown in the a test - test fails due to a ScalaCheck test fail - test fails due to compiler errors in ScalaCheck tests Review by extempore. --- src/partest/scala/tools/partest/nest/Worker.scala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/partest') diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala index 6631d476a8..637e5160ee 100644 --- a/src/partest/scala/tools/partest/nest/Worker.scala +++ b/src/partest/scala/tools/partest/nest/Worker.scala @@ -310,6 +310,13 @@ class Worker(val fileManager: FileManager, scalaCheckParentClassLoader: ScalaCla def isScala(f: File) = SFile(f) hasExtension "scala" def isJavaOrScala(f: File) = isJava(f) || isScala(f) + def outputLogFile(logFile: File) { + NestUI.normal("Log file '" + logFile + "': \n") + val lines = SFile(logFile).lines + for (lin <- lines) NestUI.normal(lin + "\n") + } + + /** Runs a list of tests. * * @param kind The test kind (pos, neg, run, etc.) @@ -375,6 +382,7 @@ class Worker(val fileManager: FileManager, scalaCheckParentClassLoader: ScalaCla val writer = new PrintWriter(new FileWriter(logFile), true) e.printStackTrace(writer) writer.close() + outputLogFile(logFile) // if running the test threw an exception, output log file succeeded = false } @@ -421,7 +429,7 @@ class Worker(val fileManager: FileManager, scalaCheckParentClassLoader: ScalaCla } } - def runTestCommon(file: File, kind: String, expectFailure: Boolean)(onSuccess: (File, File) => Unit): LogContext = + def runTestCommon(file: File, kind: String, expectFailure: Boolean)(onSuccess: (File, File) => Unit, onFail: (File, File) => Unit = (logf, outd) => ()): LogContext = runInContext(file, kind, (logFile: File, outDir: File) => { if (file.isDirectory) { @@ -439,6 +447,8 @@ class Worker(val fileManager: FileManager, scalaCheckParentClassLoader: ScalaCla if (succeeded) // run test onSuccess(logFile, outDir) + else + onFail(logFile, outDir) }) def runJvmTest(file: File, kind: String): LogContext = @@ -477,14 +487,18 @@ class Worker(val fileManager: FileManager, scalaCheckParentClassLoader: ScalaCla NestUI.verbose(SFile(logFile).slurp()) // obviously this must be improved upon + val lines = SFile(logFile).lines.filter(_.trim != "").toBuffer succeeded = { - val lines = SFile(logFile).lines.filter(_.trim != "").toBuffer val failures = lines filter (_ startsWith "!") val passedok = lines filter (_ startsWith "+") forall (_ contains "OK") failures.isEmpty && passedok } + if (!succeeded) { + NestUI.normal("ScalaCheck test failed. Output:\n") + for (lin <- lines) NestUI.normal(lin + "\n") + } NestUI.verbose("test for '" + file + "' success: " + succeeded) - }) + }, (logFile, outDir) => outputLogFile(logFile)) case "pos" => runTestCommon(file, kind, expectFailure = false)((_, _) => ()) -- cgit v1.2.3