File: test-emacs-runner.rb

package info (click to toggle)
ruby-test-unit 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 928 kB
  • ctags: 1,759
  • sloc: ruby: 12,818; makefile: 6
file content (60 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (12)
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
require 'test/unit'
require 'test/unit/ui/emacs/testrunner'

class TestUnitEmacsRunner < Test::Unit::TestCase
  def test_format_failure_with_a_location
    runner = create_runner
    test_name = "test_failure"
    file = "/home/user/test_xxx.rb"
    line = "3"
    info = "in `xxx'"
    location = "#{file}:#{line}: #{info}"
    message = "FAIL!!!"
    failure = Test::Unit::Failure.new(test_name, [location], message)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
Failure:
#{test_name} [#{file}:#{line}]:
#{message}
EOM
  end

  def test_format_failure_with_locations
    runner = create_runner
    test_name = "test_failure"
    locations = ["/home/user/test_xxx.rb:3: in `xxx'",
                 "/home/user/yyy/test_yyy.rb:999: in `yyy'",
                 "/home/user/xyz/zzz.rb:29: in `zzz'"]
    message = "Many backtrace!!!"
    failure = Test::Unit::Failure.new(test_name, locations, message)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
Failure:
#{test_name}
#{locations.join("\n")}:
#{message}
EOM
  end

  def test_format_error
    runner = create_runner
    test_name = "test_error"
    message = "Error Message!!!"
    backtrace = ["/home/user/test_xxx.rb:3: in `xxx'",
                 "/home/user/yyy/test_yyy.rb:999: in `yyy'",
                 "/home/user/xyz/zzz.rb:29: in `zzz'"]
    exception = RuntimeError.new(message)
    exception.set_backtrace(backtrace)
    error = Test::Unit::Error.new(test_name, exception)
    assert_equal(<<-EOM.chomp, runner.send(:format_fault, error))
Error:
#{test_name}:
#{exception.class.name}: #{message}
#{backtrace.join("\n")}
EOM
  end

  private
  def create_runner(suite=nil)
    suite ||= Test::Unit::TestSuite.new
    Test::Unit::UI::Emacs::TestRunner.new(suite)
  end
end