Skip to content

Instantly share code, notes, and snippets.

@lefou
Created May 28, 2014 13:40
Show Gist options
  • Save lefou/05a21cf83abc77d44667 to your computer and use it in GitHub Desktop.
Save lefou/05a21cf83abc77d44667 to your computer and use it in GitHub Desktop.
Minimized test case to reproduce a ScalaTest issue
package scalatest_issue
// The following test will not run with Scala 2.11.1 and ScalaTest 2.1.7
import org.scalatest.FreeSpec
object TargetRefs2 {
def apply(targetRefs: String*): TargetRefs2 = new TargetRefs2(Seq(targetRefs))
}
class TargetRefs2 private (val targetRefGroups: Seq[Seq[String]]) {
private[this] def closedGroups: Seq[Seq[String]] = targetRefGroups.size match {
case 1 => Seq()
case n => targetRefGroups.take(n - 1)
}
private[this] def openGroup: Seq[String] = targetRefGroups.lastOption match {
case Some(last) => last
case None => Seq()
}
def ~(targetRefs: TargetRefs2): TargetRefs2 =
new TargetRefs2((
closedGroups ++
Seq((openGroup ++ targetRefs.targetRefGroups.head).distinct) ++
targetRefs.targetRefGroups.tail
).filter(!_.isEmpty))
def ~(string: String): TargetRefs2 = this.~(TargetRefs2(string))
def ~~(targetRefs: TargetRefs2): TargetRefs2 =
new TargetRefs2((
targetRefGroups ++
Seq(targetRefs.targetRefGroups.head) ++
targetRefs.targetRefGroups.tail
).filter(!_.isEmpty))
def ~~(string: String): TargetRefs2 = ~~(TargetRefs2(string))
override def toString: String = targetRefGroups.map { _.mkString(" ~ ") }.mkString(" ~~ ")
}
class TargetRefTest2 extends FreeSpec {
"TargetRefs2 merge" - {
def mergeTest(refs: TargetRefs2, expected: Seq[Seq[String]]): Unit = {
s"merge ${refs} to ${expected}" in {
assert(refs.targetRefGroups === expected)
}
}
mergeTest(TargetRefs2("a"), Seq(Seq("a")))
mergeTest(TargetRefs2("a") ~ "b", Seq(Seq("a", "b")))
mergeTest(TargetRefs2("a") ~ "a", Seq(Seq("a")))
mergeTest(TargetRefs2("a") ~~ "a", Seq(Seq("a"), Seq("a")))
}
@lefou
Copy link
Author

lefou commented May 28, 2014

Opened issue #334.

@lefou
Copy link
Author

lefou commented Jul 16, 2015

Issue was, that test cases had the same name. In all three cases listed above, the toString() was affected resulting in different test names, thus the test ran without issues then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment