The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
Showing stacktraces for test results

3 replies on 1 page. Most recent reply: Mar 14, 2009 10:42 PM by Rich Dougherty

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Rich Dougherty

Posts: 21
Nickname: richd
Registered: Aug, 2003

Showing stacktraces for test results Posted: Jan 19, 2009 7:34 PM
Reply to this message Reply
Advertisement
Here's a patch that gives the full stack trace when a property or generator throws an exception. I find this makes it much easier to work out what's going wrong with the code I'm testing.

The patch is against the 0.9.4 tag.

Cheers
Rich

--

Index: app/src/org/scalatest/prop/Checkers.scala
===================================== ==============================
--- app/src/org/scalatest/prop/Checkers.scala (revision 815)
+++ app/src/org/scalatest/prop/Checkers.scala (working copy)
@@ -227,9 +227,11 @@
result.discarded + " tests were discarded."
case Test.PropException(args, e, labels) =>
"Exception \"" + e + "\" raised on property evaluation:\n" +
- prettyArgs(args)
+ prettyArgs(args) + ";\n" +
+ prettyThrowable(e)
case Test.GenException(e) =>
- "Exception \"" + e + "\" raised on argument generation."
+ "Exception \"" + e + "\" raised on argument generation: \n" +
+ prettyThrowable(e)
}

private def prettyArgs(args: List[Arg]) = {
@@ -241,4 +243,13 @@
)
strs.mkString("\n")
}
+
+ private def prettyThrowable(t: Throwable) = {
+ import java.io._
+ val baos = new ByteArrayOutputStream
+ val pos = new PrintStream(baos)
+ t.printStackTrace(pos)
+ pos.flush
+ baos.toString("UTF8")
+ }
}


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Showing stacktraces for test results Posted: Jan 22, 2009 11:30 PM
Reply to this message Reply
Hi Rich,

That's a nice enhancement. I'd like to include it in 0.9.5, which will be out soon, but I'll need a contributors agreement from you. I'll follow up via email.

Bill

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Showing stacktraces for test results Posted: Mar 1, 2009 9:31 AM
Reply to this message Reply
Hi Rich,

OK. I just checked something in for this. I didn't use your patch, because it would have really elongated the failure message. Where the info belongs is in the stack trace, so what I did was add the thrown exception as the cause of the TestFailedException (and I put a note to that effect in the failure message). So you can look in the regular stack trace and you'll find the stack trace for the exception that originally caused the problem, in 0.9.5.

Thanks for reporting the issue.

Bill

Rich Dougherty

Posts: 21
Nickname: richd
Registered: Aug, 2003

Re: Showing stacktraces for test results Posted: Mar 14, 2009 10:42 PM
Reply to this message Reply
That sounds great - thanks Bill

Flat View: This topic has 3 replies on 1 page
Topic: Problem with 0.9.5 Previous Topic   Next Topic Topic: Property labels in Checkers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use