I have this convenience method in my tests:
def assertFormat[T: SexpFormat](start: T, expect: Sexp): Unit = { val sexp = start.toSexp assert(sexp === expect, s"${sexp.compactPrint} was not ${expect.compactPrint}") expect.convertTo[T] should be(start) }
which is basically convenient for running an approval template, which I do a lot.
It is not possible to rewrite this as a Matcher due to the implicit requirement for SexpFormat[T] (although I would be interested to know how to do this, which does not require me to write the MyFormat type in foo should roundTrip[MyFormat](...) )
If any tests are not performed inside this utility method, scalatest will mark the internal assertFormat elements as the cause of the test failure. But I really want the scaler to detect the calling method in order to be the cause of the test. How can i do this?
i.e. current output
[info] - should support custom missing value rules *** FAILED *** [info] SexpNil did not equal SexpCons(SexpSymbol(:duck),SexpCons(SexpNil,SexpNil)) nil was not (:duck nil) (FormatSpec.scala:11) [info] org.scalatest.exceptions.TestFailedException: [info] at org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:529) [info] at org.scalatest.FlatSpec.newAssertionFailedException(FlatSpec.scala:1691) [info] at org.scalatest.Assertions$AssertionsHelper.macroAssert(Assertions.scala:502) [info] at org.ensime.sexp.formats.FormatSpec$class.assertFormat(FormatSpec.scala:11) [info] at org.ensime.sexp.formats.test.FamilyFormatsSpec.assertFormat(FamilyFormatsSpec.scala:151) [info] at org.ensime.sexp.formats.test.FamilyFormatsSpec.roundtrip(FamilyFormatsSpec.scala:156) [info] at org.ensime.sexp.formats.test.FamilyFormatsSpec$$anonfun$12.apply(FamilyFormatsSpec.scala:222) [info] at org.ensime.sexp.formats.test.FamilyFormatsSpec$$anonfun$12.apply(FamilyFormatsSpec.scala:221)
FormatSpec.scala:11 is where my assertFormat . The real failure is in FamilyFormatsSpec.scala:222 (which calls another convenience method FamilyFormatsSpec.scala:156 )
source share