Skip to content
This repository
Browse code

Cleaned up solution

  • Loading branch information...
commit e059071063e262aaae84d56f4b121ab0ec9819ce 1 parent 09e604d
Richard O. Legendi authored
4 src/main/scala/org/scalatest/specs2/Utils.scala
@@ -84,13 +84,11 @@ object Utils {
84 84 * <i>cannot be null</i>
85 85 * @return the Id used during the execution for ScalaTest for the given <code>spec</code>
86 86 */
87   - // TODO Update docs
88   - def suiteIdFor(spec: SpecificationStructure, scope: Seq[ScopeElement] = List()): String = {
  87 + def suiteIdFor(spec: SpecificationStructure): String = {
89 88 require(spec != null)
90 89
91 90 // TODO Ask Eric 2: Should I use fullName (i.e., decoded name) or javaClassName here?
92 91 // fullName seems to have a bit more sense I guess
93   - //scope.foldLeft(spec.identification.fullName)((cum, act) => cum + act)
94 92 spec.identification.fullName
95 93 }
96 94 }
49 src/main/scala/org/scalatest/specs2/notifiers/ScalaTestNotifier.scala
@@ -32,6 +32,8 @@ import org.scalatest.specs2.Utils._
32 32
33 33 object ScalaTestNotifier {
34 34
  35 + val debug = false
  36 +
35 37 // A sample Spec2 Location string looks something like:
36 38 // classname (file name:line number)
37 39 //
@@ -83,6 +85,8 @@ object ScalaTestNotifier {
83 85 */
84 86 case class ScopeElement(val name: String, val location: Option[Location])
85 87
  88 +import ScalaTestNotifier._
  89 +
86 90 /**
87 91 * <b>Note</b> This implementation <b>is not thread-safe</b>! It depends on a scope stack
88 92 * which should not be used concurrently.
@@ -95,7 +99,6 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
95 99 // --------------------------------------------------------------------------
96 100 // --- Members --------------------------------------------------------------
97 101
98   - val debug = true
99 102 val suiteStack: Stack[ScopeElement] = Stack()
100 103
101 104 private var indentLevel: Int = 0
@@ -179,7 +182,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
179 182 message = text,
180 183 nameInfo = Some(NameInfo(
181 184 suiteName = suiteStack.head.name,
182   - suiteID = suiteIdFor(spec, suiteStack),
  185 + suiteID = suiteIdFor(spec),
183 186 suiteClassName = suiteClassNameFor(spec),
184 187 decodedSuiteName = decodedSuiteNameFor(spec),
185 188 testName = getNameInfo())),
@@ -209,8 +212,35 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
209 212 suiteStack.pop
210 213 }
211 214
  215 + /**
  216 + * This is required because two examples might have the same name, e.g.:
  217 + *
  218 + * <code>
  219 + * class SameNamesSpecs extends Specification {
  220 + * "One" should {
  221 + * "a" in {
  222 + * success
  223 + * }
  224 + * }
  225 + *
  226 + * "Other" should {
  227 + * "a" in {
  228 + * success
  229 + * }
  230 + * }
  231 + * }
  232 + * </code>
  233 + *
  234 + * In this case, <code>"a"</code> reported correctly, but the line numbers
  235 + * are messed up (since the latter rewrites the previous object with the
  236 + * same name).
  237 + *
  238 + * @param name the name of the test
  239 + * @return a simple list containing a textual representation of the path
  240 + */
212 241 private def testNameFor(name: String): String = {
213   - suiteStack.foldLeft(name + ": ")((cum, act) => cum + act)
  242 + suiteStack.foldLeft(name + ": ")((cum, act) => cum + ", " +
  243 + act.name + "@" + act.location)
214 244 }
215 245
216 246 def exampleStarted(name: String, location: String): Unit = {
@@ -219,14 +249,15 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
219 249 }
220 250
221 251 testStarted(name, location)
  252 + val testName = testNameFor(name) // Must be evaluated *after* the test started
222 253
223 254 reporter(TestStarting(
224 255 ordinal = tracker.nextOrdinal(),
225 256 suiteName = suiteNameFor(spec),
226   - suiteId = suiteIdFor(spec, suiteStack),
  257 + suiteId = suiteIdFor(spec),
227 258 suiteClassName = suiteClassNameFor(spec),
228 259 decodedSuiteName = decodedSuiteNameFor(spec),
229   - testName = testNameFor(name),
  260 + testName = testName,
230 261 testText = name,
231 262 decodedTestName = getDecodedName(name),
232 263 formatter = Some(MotionToSuppress), // Note suppressed event - this is what we want here! See Scaladoc of Formatter
@@ -246,7 +277,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
246 277 reporter(TestSucceeded(
247 278 ordinal = tracker.nextOrdinal(),
248 279 suiteName = suiteNameFor(spec),
249   - suiteId = suiteIdFor(spec, suiteStack),
  280 + suiteId = suiteIdFor(spec),
250 281 suiteClassName = suiteClassNameFor(spec),
251 282 decodedSuiteName = decodedSuiteNameFor(spec),
252 283 testName = testName,
@@ -289,7 +320,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
289 320 ordinal = tracker.nextOrdinal(),
290 321 message = message,
291 322 suiteName = suiteNameFor(spec),
292   - suiteId = suiteIdFor(spec, suiteStack),
  323 + suiteId = suiteIdFor(spec),
293 324 suiteClassName = suiteClassNameFor(spec),
294 325 decodedSuiteName = decodedSuiteNameFor(spec),
295 326 testName = testName,
@@ -332,7 +363,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
332 363 reporter(TestIgnored(
333 364 ordinal = tracker.nextOrdinal(),
334 365 suiteName = suiteNameFor(spec),
335   - suiteId = suiteIdFor(spec, suiteStack),
  366 + suiteId = suiteIdFor(spec),
336 367 suiteClassName = suiteClassNameFor(spec),
337 368 decodedSuiteName = decodedSuiteNameFor(spec),
338 369 testName = testName,
@@ -354,7 +385,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
354 385 reporter(TestPending(
355 386 ordinal = tracker.nextOrdinal(),
356 387 suiteName = suiteNameFor(spec),
357   - suiteId = suiteIdFor(spec, suiteStack),
  388 + suiteId = suiteIdFor(spec),
358 389 suiteClassName = suiteClassNameFor(spec),
359 390 decodedSuiteName = decodedSuiteNameFor(spec),
360 391 testName = testName,

0 comments on commit e059071

Please sign in to comment.
Something went wrong with that request. Please try again.