aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/scala/org/perl8/test/ExtensionTest.scala
blob: a74392e861c94fce9cd71c04aa2ac4db27fc87cc (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
package org.perl8.test

import java.io.ByteArrayOutputStream

import org.perl8.test.tap.Parser

trait NumberZero { this: TestMore =>
  def is_zero (i: Int, desc: String): Boolean = hideTestMethod {
    is(i, 0, desc)
  }
}

trait NumberZeroWrapped extends NumberZero { this: TestMore =>
  def isZero (i: Int): Boolean = hideTestMethod {
    is_zero(i, "the number is zero")
  }
}

class ExtensionTest extends TestMore {
  val lineZero = Thread.currentThread.getStackTrace()(1).getLineNumber + 3
  def line (offset: Int) = lineZero + offset

  private class ExtensionTestTest extends TestMore with NumberZeroWrapped {
    is_zero(0, "it's zero")
    is_zero(1, "it's not zero")
    isZero(0)
    isZero(1)
  }

  val out = new ByteArrayOutputStream
  val exitCode = Console.withOut(out) {
    Console.withErr(out) {
      (new ExtensionTestTest).run
    }
  }

  is((new Parser).parse(out).exitCode, 2)
  is(exitCode, 2)

  val tap =
    "ok 1 - it's zero\n" +
    "not ok 2 - it's not zero\n" +
    "#   Failed test 'it's not zero'\n" +
    "#   at ExtensionTest.scala line " + line(2) + ".\n" +
    "#          got: '1'\n" +
    "#     expected: '0'\n" +
    "ok 3 - the number is zero\n" +
    "not ok 4 - the number is zero\n" +
    "#   Failed test 'the number is zero'\n" +
    "#   at ExtensionTest.scala line " + line(4) + ".\n" +
    "#          got: '1'\n" +
    "#     expected: '0'\n" +
    "1..4\n" +
    "# Looks like you failed 2 tests of 4.\n"

  is(out.toString, tap)
}