From 4afa092314487c0095ff9fd5756d05340f6150b0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 19 May 2011 20:06:19 +0000 Subject: Removes SUnit (long deprecated!) from the stand... Removes SUnit (long deprecated!) from the standard library. the relatively small number of partest tests in Scala's suite that were still using SUnit now either just use regular asserts, or they print stuff that partest checks with a .check file. Also fixed some bad indentation, removed ancient useless-looking commented-out code, etc. Contributed by Seth Tisue (way to go seth) no review. --- src/library/scala/testing/SUnit.scala | 272 ---------------------------------- 1 file changed, 272 deletions(-) delete mode 100644 src/library/scala/testing/SUnit.scala (limited to 'src') diff --git a/src/library/scala/testing/SUnit.scala b/src/library/scala/testing/SUnit.scala deleted file mode 100644 index 9720015d94..0000000000 --- a/src/library/scala/testing/SUnit.scala +++ /dev/null @@ -1,272 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.testing - -import scala.collection.mutable.ArrayBuffer -import xml.{ Node, NodeSeq } - -/** - *

- * Unit testing methods in the spirit of - * JUnit framework. - *

- *

- * Use these classes like this: - *

- *
- * import scala.testing.SUnit
- * import SUnit._
- *
- * class MyTest(n: String) extends TestCase(n) {
- *
- *   override def runTest() = n match {
- *     case "myTest1" => assertTrue(true)
- *     case "myTest2" => assertTrue("hello", false)
- *   }
- * }
- *
- * val r = new TestResult()
- * suite.run(r)
- * for (tf <- r.failures()) {
- *   println(tf.toString())
- * }
- * 
- *

- * The trait TestConsoleMain contains this code as - * a main method, for convenience. - *

- * - * @author Burak Emir - */ -@deprecated("SUnit will be removed in 2.8.0. There are several free and sophisticated testing\n"+ - """frameworks for Scala available, examples are "ScalaTest", "ScalaCheck" or "Specs".""", - "2.7.2") -object SUnit { - - /**

- * Convenience trait, mix it in a TestMain object and - * implement "suite" to get this code. - *

-   *  val r = new TestResult()
-   *  suite.run(r)
-   *  for (val tf <- r.failures()) {
-   *    println(tf.toString())
-   *  
- */ - trait TestConsoleMain { - def suite: TestSuite - def main(args: Array[String]) { - val r = new TestResult() - suite.run(r) - for (tf <- r.failures()) - println(tf.toString()) - } - } - - /** a Test can be run with its result being collected */ - trait Test { - def run(r: TestResult): Unit - } - - /** The class TestCase defines the fixture to run multiple - * tests. - * - * @param name ... - */ - abstract class TestCase(val name: String) extends Test with Assert { - - protected def runTest(): Unit - - def run(r: TestResult) { - try { - runTest() - } catch { - case t:Throwable => r.addFailure(this, t) - } - } - - def setUp() {} - - def tearDown() {} - - override def toString() = name - } - - /** The class TestFailure collects a failed test together - * with the thrown exception. - */ - class TestFailure(val failedTest: Test, val thrownException: Throwable) { - - def this(p: (Test, Throwable)) = this(p._1, p._2) - - override def toString() = - failedTest.toString() + " failed due to " + thrownException.toString() - - def trace(): String = thrownException.getStackTraceString - - } - - /** a TestResult collects the result of executing a test case */ - class TestResult { - val buf = new ArrayBuffer[(Test, Throwable)]() - - def addFailure(test: Test, t: Throwable) { - buf += ((test, t)) - } - - def failureCount() = - buf.length - - def failures() = - buf.iterator map { x => new TestFailure(x) } - } - - /** The class TestSuite runs a composite of test cases. - */ - class TestSuite(tests: Test*) extends Test { - - def this(names: Seq[String], constr: String => Test) = - this((names map constr):_*) - - val buf = new ArrayBuffer[Test]() - - buf ++= tests - - def addTest(t: Test) { - buf += t - } - - def run(r: TestResult) { - for (t <- buf) t.run(r) - } - } - - /** an AssertFailed is thrown for a failed assertion */ - case class AssertFailed(msg: String, stackTrace: Boolean) extends RuntimeException { - private val msg0 = - if (stackTrace) super.getStackTrace().map(_.toString + "\n").mkString - else msg - override def toString() = - if (msg0 eq null) "failed assertion: " + msg else msg0 - } - - /** this class defines useful assert methods */ - trait Assert { - - def enableStackTrace: Boolean = true - - /** fails if ! actual.sameElements(expected) */ - def assertSameElements[A](actual: Seq[A], expected: Seq[A]) { - if (! actual.sameElements(expected)) - fail("(no message)", actual.toString, expected.toString) - } - - /** fails if expected != actual */ - def assertEquals[A](msg: String, expected: A, actual: A) { - if (expected != actual) fail(msg, expected, actual) - } - - /** fails if expected != actual */ - def assertEquals[A](expected: A, actual: A) { - assertEquals("(no message)", expected, actual) - } - - /** succeeds if actual is false */ - def assertFalse(msg: String, actual: Boolean) { - assertEquals(msg, false, actual) - } - - /** succeeds if actual is false */ - def assertFalse(actual: Boolean) { - assertFalse("(no message)", actual) - } - - /** fails if null eq actual */ - def assertNotNull(msg: String, actual: AnyRef) { - if (null eq actual) fail(msg) - } - - /** fails if null eq actual */ - def assertNotNull(actual: AnyRef): Unit = - assertNotNull("(no message)", actual) - - /** fails if expected eq actual */ - def assertNotEq(msg: String, expected: AnyRef, actual: AnyRef) { - if (expected eq actual) fail(msg) - } - - /** fails if expected eq actual */ - def assertNotEq(expected: AnyRef, actual: AnyRef) { - assertNotEq("(no message)", expected, actual) - } - - /** fails if actual ne null */ - def assertNull(msg: String, actual: AnyRef) { - if (null ne actual) fail(msg) - } - - /** fails if actual ne null */ - def assertNull(actual: AnyRef) { - assertNull("(no message)", actual) - } - - /** fails if expected ne actual */ - def assertEq(msg: String, expected: AnyRef, actual: AnyRef) { - if (expected ne actual) fail(msg) - } - - /** fails if expected ne actual */ - def assertEq(expected: AnyRef, actual: AnyRef) { - assertEq("(no message)", expected, actual) - } - - /** succeeds if actual == true */ - def assertTrue(msg: String, actual: Boolean) { - assertEquals(msg, true, actual) - } - - /** succeeds if actual == true */ - def assertTrue(actual: Boolean) { - assertTrue("(no message)", actual) - } - - /** Temporary patchwork trying to nurse xml forward. */ - def assertEqualsXML(msg: String, expected: NodeSeq, actual: NodeSeq) { - if (!expected.xml_==(actual)) - fail(msg, expected, actual) - } - def assertEqualsXML(msg: String, expected: Seq[Node], actual: Seq[Node]) { - assertEqualsXML(msg, expected: NodeSeq, actual: NodeSeq) - } - - def assertEqualsXML(expected: NodeSeq, actual: NodeSeq) { - assertEqualsXML("(no message)", expected, actual) - } - - def assertSameElementsXML(actual: Seq[Node], expected: Seq[Node]) { - val res = (actual: NodeSeq) xml_sameElements expected - - assert(res, "\nassertSameElementsXML:\n actual = %s\n expected = %s".format(actual, expected)) - } - - /** throws AssertFailed with given message msg. - */ - def fail(msg: String) { - throw AssertFailed(msg, enableStackTrace) - } - - def fail[A](msg: String, expected: A, actual: A) { - throw AssertFailed(msg + - ", expected: " + expected + - ", actual: " + actual, enableStackTrace) - } - } -} -- cgit v1.2.3