summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-10-02 15:40:17 +0000
committermichelou <michelou@epfl.ch>2007-10-02 15:40:17 +0000
commit3e458ce8dde26e13db39f84b1ef50574eb04a9ee (patch)
tree1d920ecae88f81029fe076aa4c2a8ca6a96c53f7 /src
parenta15a2bed93fbd6b534dd3f31f49d25c45303320b (diff)
downloadscala-3e458ce8dde26e13db39f84b1ef50574eb04a9ee.tar.gz
scala-3e458ce8dde26e13db39f84b1ef50574eb04a9ee.tar.bz2
scala-3e458ce8dde26e13db39f84b1ef50574eb04a9ee.zip
fixed ticket #141
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/testing/SUnit.scala25
1 files 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 <code>main</code> method, for convenience.
* </p>
*
- * @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 <code>assert</code> methods */
+ /** this class defines useful <code>assert</code> 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 <code>AssertFailed</code> with given message <code>msg</code>.
*/
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)
}
}
}