From 3e458ce8dde26e13db39f84b1ef50574eb04a9ee Mon Sep 17 00:00:00 2001 From: michelou Date: Tue, 2 Oct 2007 15:40:17 +0000 Subject: fixed ticket #141 --- src/library/scala/testing/SUnit.scala | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/library/scala/testing/SUnit.scala b/src/library/scala/testing/SUnit.scala index 7ab963a3be..c586c0d1bd 100644 --- a/src/library/scala/testing/SUnit.scala +++ b/src/library/scala/testing/SUnit.scala @@ -44,7 +44,7 @@ import scala.collection.mutable.ArrayBuffer * a main method, for convenience. *

* - * @author Burak Emir + * @author Burak Emir, Stephane Micheloud */ object SUnit { @@ -147,13 +147,22 @@ object SUnit { } /** an AssertFailed is thrown for a failed assertion */ - case class AssertFailed(msg: String) extends RuntimeException { - override def toString() = "failed assertion: " + msg + case class AssertFailed(msg: String, stackTrace: Boolean) extends RuntimeException { + private val msg0 = if (stackTrace) { + import java.io._ + val wrt = new StringWriter + printStackTrace(new PrintWriter(wrt)) + wrt.toString + } else msg + override def toString() = + if (msg0 eq null) "failed assertion: " + msg else msg0 } - /** this class defined useful assert methods */ + /** this class defines useful assert methods */ trait Assert { + def enableStackTrace: Boolean = true + /** fails if expected != actual */ def assertEquals[A](msg: String, expected: A, actual: => A) { if (expected != actual) fail(msg, expected, actual) @@ -258,13 +267,13 @@ object SUnit { /** throws AssertFailed with given message msg. */ def fail(msg: String) { - throw new AssertFailed(msg) + throw AssertFailed(msg, enableStackTrace) } def fail[A](msg: String, expected: A, actual: => A) { - throw new AssertFailed(msg + - ", expected: " + expected + - ", actual: " + actual) + throw AssertFailed(msg + + ", expected: " + expected + + ", actual: " + actual, enableStackTrace) } } } -- cgit v1.2.3