Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue with duplicated test names

  • Loading branch information...
commit 09e604d9a01ad8b0ff40b510c1b79aa1d8d5cb9f 1 parent 35fdeed
@rlegendi authored
View
1  src/main/scala/org/scalatest/specs2/Spec2Runner.scala
@@ -132,6 +132,7 @@ class Spec2Runner(specs2Class: Class[_ <: SpecificationStructure]) extends Suite
require(reporter != null)
require(filter != null)
+ // TODO Here we get where the whole thing starts, needs checking
new NotifierReporter {
val notifier = new ScalaTestNotifier(spec2, args, tracker, reporter)
}.report(spec2)(args)
View
7 src/main/scala/org/scalatest/specs2/Utils.scala
@@ -2,6 +2,9 @@ package org.scalatest.specs2
import org.specs2.Specification
import org.specs2.specification.SpecificationStructure
+import scala.collection.immutable.Stack
+import org.scalatest.specs2.notifiers.ScopeElement
+import scala.collection.LinearSeq
/**
* A set of constants and minimal utility functions.
@@ -81,11 +84,13 @@ object Utils {
* <i>cannot be null</i>
* @return the Id used during the execution for ScalaTest for the given <code>spec</code>
*/
- def suiteIdFor(spec: SpecificationStructure): String = {
+ // TODO Update docs
+ def suiteIdFor(spec: SpecificationStructure, scope: Seq[ScopeElement] = List()): String = {
require(spec != null)
// TODO Ask Eric 2: Should I use fullName (i.e., decoded name) or javaClassName here?
// fullName seems to have a bit more sense I guess
+ //scope.foldLeft(spec.identification.fullName)((cum, act) => cum + act)
spec.identification.fullName
}
}
View
57 src/main/scala/org/scalatest/specs2/notifiers/ScalaTestNotifier.scala
@@ -78,7 +78,7 @@ object ScalaTestNotifier {
/**
* Simple utility class for handling the scope elements.
- *
+ *
* @author rlegendi
*/
case class ScopeElement(val name: String, val location: Option[Location])
@@ -95,14 +95,14 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
// --------------------------------------------------------------------------
// --- Members --------------------------------------------------------------
- val debug = false
+ val debug = true
val suiteStack: Stack[ScopeElement] = Stack()
private var indentLevel: Int = 0
// --------------------------------------------------------------------------
// --- Scope handling -------------------------------------------------------
-
+
def scopeOpened(name: String, location: String): Unit = {
// TODO Requires... in the whole file
suiteStack.push(new ScopeElement(name, loc(location)))
@@ -162,10 +162,9 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
if (debug) {
println(">>> contextEnd: " + text + "@" + location)
}
-
scopeClosed(text, location);
}
-
+
// --------------------------------------------------------------------------
// --- Specific events ------------------------------------------------------
@@ -180,7 +179,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
message = text,
nameInfo = Some(NameInfo(
suiteName = suiteStack.head.name,
- suiteID = suiteIdFor(spec),
+ suiteID = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
testName = getNameInfo())),
@@ -210,6 +209,10 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
suiteStack.pop
}
+ private def testNameFor(name: String): String = {
+ suiteStack.foldLeft(name + ": ")((cum, act) => cum + act)
+ }
+
def exampleStarted(name: String, location: String): Unit = {
if (debug) {
println(">>> exampleStarted: " + name + "@" + location)
@@ -217,16 +220,15 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
testStarted(name, location)
- val testName = name
reporter(TestStarting(
ordinal = tracker.nextOrdinal(),
suiteName = suiteNameFor(spec),
- suiteId = suiteIdFor(spec),
+ suiteId = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
- testName = testName,
- testText = testName + "(exampleName)",
- decodedTestName = getDecodedName(testName),
+ testName = testNameFor(name),
+ testText = name,
+ decodedTestName = getDecodedName(name),
formatter = Some(MotionToSuppress), // Note suppressed event - this is what we want here! See Scaladoc of Formatter
location = loc(location),
rerunner = rerunnerFor(spec)))
@@ -237,19 +239,19 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
println(">>> exampleSuccess: " + name + ", t=" + duration)
}
+ val testName = testNameFor(name)
val actScopeElement = testEnded()
val formatter = Suite.getIndentedText(name, indentLevel, true)
- val testName = name
reporter(TestSucceeded(
ordinal = tracker.nextOrdinal(),
suiteName = suiteNameFor(spec),
- suiteId = suiteIdFor(spec),
+ suiteId = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
testName = testName,
- testText = testName + "(testText)", // TODO Check where it is used
- decodedTestName = getDecodedName(testName),
+ testText = name,
+ decodedTestName = getDecodedName(name),
duration = Some(duration),
formatter = Some(formatter),
location = actScopeElement.location))
@@ -262,6 +264,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
// We do not use the actual test location, because a test might contain multiple assertions, and any of them might fail
// It is more specific if we can report the exact example which is erroreous
+ val testName = testNameFor(name)
testEnded()
val formatter = Suite.getIndentedText(name, indentLevel, true)
@@ -286,11 +289,11 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
ordinal = tracker.nextOrdinal(),
message = message,
suiteName = suiteNameFor(spec),
- suiteId = suiteIdFor(spec),
+ suiteId = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
- testName = name,
- testText = reason,
+ testName = testName,
+ testText = name + ": " + reason,
decodedTestName = Some(name),
throwable = Some(f),
duration = Some(duration),
@@ -303,7 +306,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
if (debug) {
println(">>> exampleFailure: " + name + ", t=" + message)
}
-
+
testFailed(name, message, location, f, Some(details), duration)
}
@@ -311,7 +314,7 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
if (debug) {
println(">>> exampleError: " + name + ", t=" + message)
}
-
+
// TODO Is there any way to report a test error without a suite error? Do I even need it?
testFailed(name, message, location, f, None, duration)
}
@@ -322,17 +325,18 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
println(">>> exampleSkipped: " + name + ", t=" + message)
}
+ val testName = testNameFor(name)
val actScopeElement = testEnded()
val formatter = Suite.getIndentedText(name, indentLevel, true)
reporter(TestIgnored(
ordinal = tracker.nextOrdinal(),
suiteName = suiteNameFor(spec),
- suiteId = suiteIdFor(spec),
+ suiteId = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
- testName = name,
- testText = message,
+ testName = testName,
+ testText = name + ": " + message,
decodedTestName = Some(name),
formatter = Some(formatter),
location = actScopeElement.location))
@@ -343,17 +347,18 @@ class ScalaTestNotifier(val spec: SpecificationStructure, val args: Arguments,
println(">>> examplePending: " + name + ", t=" + message)
}
+ val testName = testNameFor(name)
val actScopeElement = testEnded()
val formatter = Suite.getIndentedText(name, indentLevel, true)
reporter(TestPending(
ordinal = tracker.nextOrdinal(),
suiteName = suiteNameFor(spec),
- suiteId = suiteIdFor(spec),
+ suiteId = suiteIdFor(spec, suiteStack),
suiteClassName = suiteClassNameFor(spec),
decodedSuiteName = decodedSuiteNameFor(spec),
- testName = name,
- testText = message,
+ testName = testName,
+ testText = name + ": " + message,
decodedTestName = Some(name),
duration = Some(duration),
formatter = Some(formatter),
View
22 src/test/scala/org/scalatest/specs2/SameNamesSpecs.scala
@@ -0,0 +1,22 @@
+package org.scalatest.specs2
+
+import org.specs2.mutable.Specification
+import org.junit.runner.RunWith
+import org.scalatest.WrapWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+@WrapWith(classOf[Spec2Runner])
+class SameNamesSpecs extends Specification {
+ "One" should {
+ "a" in {
+ success
+ }
+ }
+
+ "Other" should {
+ "a" in {
+ success
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.