summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/testing
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-09-05 00:24:27 -0700
committerSom Snytt <som.snytt@gmail.com>2014-11-11 07:33:52 -0800
commitda60dda202f386ed85fa15bf8fe02252d4dfb911 (patch)
treee452ff2e24d9ac3ff0c5441b269e974323e88644 /test/junit/scala/tools/testing
parentd28d4f49088eb5e0809cbb68655319c68e981caa (diff)
downloadscala-da60dda202f386ed85fa15bf8fe02252d4dfb911.tar.gz
scala-da60dda202f386ed85fa15bf8fe02252d4dfb911.tar.bz2
scala-da60dda202f386ed85fa15bf8fe02252d4dfb911.zip
SI-8835 Iterator tests can be junit
Without loss of generality or convenience, but helps reduce the number of files in test/files and may reduce compile times for test suite. This commit includes the fix from #3963 and an extra test of that fix that ensures the stack doesn't grow on chained drops.
Diffstat (limited to 'test/junit/scala/tools/testing')
-rw-r--r--test/junit/scala/tools/testing/AssertUtil.scala20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/junit/scala/tools/testing/AssertUtil.scala b/test/junit/scala/tools/testing/AssertUtil.scala
index 9b4833d46b..83a637783f 100644
--- a/test/junit/scala/tools/testing/AssertUtil.scala
+++ b/test/junit/scala/tools/testing/AssertUtil.scala
@@ -1,6 +1,11 @@
package scala.tools
package testing
+import org.junit.Assert
+import Assert.fail
+import scala.runtime.ScalaRunTime.stringOf
+import scala.collection.{ GenIterable, IterableLike }
+
/** This module contains additional higher-level assert statements
* that are ultimately based on junit.Assert primitives.
*/
@@ -21,6 +26,19 @@ object AssertUtil {
throw e
else return
}
- throw new AssertionError("Expression did not throw!")
+ fail("Expression did not throw!")
}
+
+ /** JUnit-style assertion for `IterableLike.sameElements`.
+ */
+ def assertSameElements[A, B >: A](expected: IterableLike[A, _], actual: GenIterable[B], message: String = ""): Unit =
+ if (!(expected sameElements actual))
+ fail(
+ f"${ if (message.nonEmpty) s"$message " else "" }expected:<${ stringOf(expected) }> but was:<${ stringOf(actual) }>"
+ )
+
+ /** Convenient for testing iterators.
+ */
+ def assertSameElements[A, B >: A](expected: IterableLike[A, _], actual: Iterator[B]): Unit =
+ assertSameElements(expected, actual.toList, "")
}