Skip to content

Commit

Permalink
display the exception class when displaying an Error. fixes #402
Browse files Browse the repository at this point in the history
  • Loading branch information
etorreborre committed Jul 29, 2015
1 parent 20c679e commit 9173100
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common/src/main/scala/org/specs2/execute/Result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ case object FromJUnitAssertionError extends Details
/**
* This class represents an exception occurring during an execution.
*/
case class Error(m: String, t: Throwable) extends Result(m) with ResultStackTrace { outer =>
case class Error(m: String, t: Throwable) extends Result(s"${t.getClass.getName}: $m") with ResultStackTrace { outer =>
type SelfType = Error

/** @return an exception created from the message and the stackTraceElements */
Expand Down
14 changes: 10 additions & 4 deletions core/src/test/scala/org/specs2/reporter/TextPrinterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class TextPrinterSpec extends Specification { def is = s2"""
with detailed failure $d3

Error messages must be shown
with the exception message $e1
with the stacktrace $e2
with the exception class $e1
with the exception message $e2
with the stacktrace $e3

Expected values must be shown
when they are non empty $f1
Expand Down Expand Up @@ -150,9 +151,14 @@ s2"""e1 ${"abcdeabcdeabcdeabcdeabcde" must_== "adcdeadcdeadcdeadcdeadcde"}""" co
def e1 = Arguments("fullstacktrace") ^
s2"""e1 $error1""" contains
"""|[error] ! e1
|[error] boom"""
|[error] java.lang.RuntimeException: boom"""

def e2 = s2"""e1 $error1""" contains """|[error] org.specs2.report"""
def e2 = Arguments("fullstacktrace") ^
s2"""e1 $error1""" contains
"""|[error] ! e1
|[error] java.lang.RuntimeException: boom"""

def e3 = s2"""e1 $error1""" contains """|[error] org.specs2.report"""

def f1 = s2"""e1 ${Success("ok", "expected")}""" contains
"""|[info] + e1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ContextSpec extends script.Spec with ResultMatchers with Groups { def is =
e1 := executing(ex1Before).prints("before", "e1")
e2 := executing(ex1_2Before).prints("before", "e1", "before", "e2")
e3 := executing(ex1_beforeFail).prints()
e4 := executeBodies(ex1_beforeFail).map(_.message) must_== List("error")
e4 := executeBodies(ex1_beforeFail).map(_.message) must_== List("java.lang.RuntimeException: error")
e5 := executing(ex1_beforeSkipped).prints()
e6 := executeBodies(ex1_beforeSkipped).map(_.message) must_== List("skipped")
e7 := executing(ex1_beforeSkippedThrown).prints()
Expand All @@ -110,7 +110,7 @@ class ContextSpec extends script.Spec with ResultMatchers with Groups { def is =
e2 := executing(ex1_2After).prints("e1", "after", "e2", "after")
e3 := executeBodies(ex1FailAfter).head must beFailing
e4 := executing(ex1_afterFail).prints("e1")
e5 := executeBodies(ex1_beforeFail).map(_.message) must_== List("error")
e5 := executeBodies(ex1_beforeFail).map(_.message) must_== List("java.lang.RuntimeException: error")
e6 := executing(ex1Around).prints("around", "e1")
}

Expand All @@ -129,7 +129,7 @@ class ContextSpec extends script.Spec with ResultMatchers with Groups { def is =
"other context" - new g4 with FragmentsExecution {
e1 := executing(firstThenEx1).prints("first", "e1")
e2 := executeBodies(silentFirstThenEx1).map(_.message) must_== List("", "success")
e3 := executeBodies(failingFirstThenEx1).map(_.message) must_== List("error", "success")
e3 := executeBodies(failingFirstThenEx1).map(_.message) must_== List("java.lang.RuntimeException: error", "success")
}

"mutable contexts" - new g6 with FragmentsExecution with MustThrownExpectations {
Expand Down Expand Up @@ -250,4 +250,4 @@ trait ContextsForFragments extends StringOutput {
AsResult(f(1))
}
}
}
}
4 changes: 2 additions & 2 deletions form/src/test/scala/org/specs2/form/PropSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ Execution
e3 := expectedOnly.execute === Pending("No actual value")
e4 := nameProp("eric").execute === Success("'eric' is equal to 'eric'")
e5 := nameProp("eric2").execute.message === "'eric' is not equal to 'eric2'"
e6 := nameProp.apply(error("bad")).execute.message === "bad"
e6 := nameProp.apply(error("bad")).execute.message === "java.lang.RuntimeException: bad"
e7 := constrained("e").execute.isSuccess === true
e8 := constrained("a").execute.message === "'eric' doesn't contain 'a'"
e9 := withMatcher("e").execute.isSuccess === true
e10 := withMatcher("a").execute.message === "'eric' doesn't contain 'a'"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ is formatted for JUnit reporting tools.
}

object message {
def e1 = { (env: Env) => print(env)("t1" ^ br ^ "e2" ! anError) must \\("error", "message" -> anError.message) }
def e1 = { (env: Env) => print(env)("t1" ^ br ^ "e2" ! anError) must \\("error", "message" -> anError.exception.getMessage) }
def e2 = { (env: Env) => print(env)("t1" ^ br ^ "e2" ! anError) must \\("error", "type" -> anError.exception.getClass.getName) }
def e3 = { (env: Env) => print(env)("t1" ^ br ^ "e2" ! anError).toString must contain("JUnitXmlPrinterSpec.scala") }
def e4 = { (env: Env) => print(env)("t1" ^ br ^ "e3" ! failure) must \\("failure", "message" -> failure.message) }
Expand Down

0 comments on commit 9173100

Please sign in to comment.