Created
May 28, 2014 13:40
-
-
Save lefou/05a21cf83abc77d44667 to your computer and use it in GitHub Desktop.
Minimized test case to reproduce a ScalaTest issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) | |
} | |
Compile:
java -cp /home/lefou/.m2/repository/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar:/home/lefou/.m2/repository/org/scala-lang/scala-reflect/2.11.1/scala-reflect-2.11.1.jar:/home/lefou/.m2/repository/org/scala-lang/scala-compiler/2.11.1/scala-compiler-2.11.1.jar scala.tools.nsc.Main -d target/ org.sbuild.runner/src/test/scala/org/sbuild/TargetRefTest2.scala -cp /home/lefou/.m2/repository/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar:/home/lefou/.m2/repository/org/scalatest/scalatest_2.11/2.1.7/scalatest_2.11-2.1.7.jar
Test:
java -cp /home/lefou/.m2/repository/org/scala-lang/scala-library/2.11.1/scala-library-2.11.1.jar:/home/lefou/.m2/repository/org/scalatest/scalatest_2.11/2.1.7/scalatest_2.11-2.1.7.jar:/home/lefou/.m2/repository/org/scala-lang/modules/scala-xml_2.11/1.0.1/scala-xml_2.11-1.0.1.jar org.scalatest.tools.Runner -oG -p target/
Opened issue #334.
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
The test case above will result in a RuntimeException: Unable to load a Suite class that was discovered in the runpath: scalatest_issue.TargetRefTest2
Scala 2.11.1
ScalaTest 2.1.7
When I apply one of the minimal changes below, the test will run!
.distinct
in line 26, unfortunately now test case in line 54 failstoString
method anymore