summaryrefslogtreecommitdiff
path: root/src/library/scala/testing/UnitTest.scala
blob: b6975a8e2218ba809b6e78454d2e2844e6559d19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.testing


/**
 * Some simple methods to support unit testing with assertions
 * to contain more JUnit style assertions which use Scala's features.
 * @deprecated use SUnit instead
 */
@deprecated
object UnitTest {

  class Report(report_ok: () => Unit, report_fail: (String,String) => Unit) {
    def ok(): Unit = report_ok()
    def fail(actual: String, expected: String): Unit =
      report_fail(actual, expected)
  }

  var report = new Report(
    { () => Console.println("passed ok") },
    { (actual: String, expected: String) =>
        Console.print("failed! we got")
        Console.print( "\""+ actual +"\"" )
        Console.println(" but expected \"" + expected + "\"") })

  /**
   *  @param r ...
   */
  def setReporter(r: Report) = {
    this.report = r
  }

  /**
   *  @param actual   ...
   *  @param expected ...
   */
  def assertSameElements[a](actual: Seq[a], expected: Seq[a]): Unit =
    if (actual.sameElements(expected))
      report.ok
    else
      report.fail(actual.toString, expected.toString)

  /**
   *  @param actual   ...
   *  @param expected ...
   */
  def assertEquals[a](actual: a, expected: a): Unit =
    if (actual == expected)
      report.ok
    else
      report.fail(actual.toString(), expected.toString())

  def assertTrue(actual: Boolean): Unit = assertEquals(actual, true)
  def assertFalse(actual: Boolean): Unit = assertEquals(actual, false)

  def assertNull(actual: AnyRef): Unit =
   if (actual eq null)
     report.ok
    else
      report.fail(actual.toString, "null")

  def assertNonNull(actual: AnyRef): Unit =
   if (actual ne null)
     report.ok
    else
      report.fail(actual.toString, "null")


  def assertNotEquals[a]( actual: a, expected: a): Unit =
    if (actual != expected)
      report.ok
    else
      report.fail(actual.toString(), "x != "+expected.toString())

  //def test[a](def doit: a, expected: a): Unit = assertEquals(doit, expected)

} // unitTest