File: test-color-scheme.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 (89 lines) | stat: -rw-r--r-- 3,840 bytes parent folder | download | duplicates (2)
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
88
89
class TestUnitColorScheme < Test::Unit::TestCase
  def test_register
    inverted_scheme_spec = {
      "success" => {:name => "red"},
      "failure" => {:name => "green"},
    }
    Test::Unit::ColorScheme["inverted"] = inverted_scheme_spec
    assert_equal({
                   "success" => color("red"),
                   "failure" => color("green"),
                 },
                 Test::Unit::ColorScheme["inverted"].to_hash)
  end

  def test_new_with_colors
    scheme = Test::Unit::ColorScheme.new(:success => color("blue"),
                                         "failure" => color("green",
                                                            :underline => true))
    assert_equal({
                   "success" => color("blue"),
                   "failure" => color("green", :underline => true),
                 },
                 scheme.to_hash)
  end

  def test_new_with_spec
    scheme = Test::Unit::ColorScheme.new(:success => {
                                           :name => "blue",
                                           :bold => true
                                         },
                                         "failure" => {:name => "green"})
    assert_equal({
                   "success" => color("blue", :bold => true),
                   "failure" => color("green"),
                 },
                 scheme.to_hash)
  end

  private
  def color(name, options={})
    Test::Unit::Color.new(name, options)
  end

  class TestFor8Colors < self
    def setup
      @original_term, ENV["TERM"] = ENV["TERM"], nil
      @original_color_term, ENV["COLORTERM"] = ENV["COLORTERM"], nil
      ENV["TERM"] = "xterm"
    end

    def teardown
      ENV["TERM"] = @original_term
      ENV["COLORTERM"] = @original_color_term
    end

    def test_default
      expected_schema = {
        "pass"                => color("green",   :background => true) +
                                 color("white",   :bold       => true),
        "failure"             => color("red",     :background => true) +
                                 color("white",   :bold       => true),
        "pending"             => color("magenta", :background => true) +
                                 color("white",   :bold       => true),
        "omission"            => color("blue",    :background => true) +
                                 color("white",   :bold       => true),
        "notification"        => color("cyan",    :background => true) +
                                 color("white",   :bold       => true),
        "error"               => color("black",   :background => true) +
                                 color("yellow",  :bold       => true),
        "case"                => color("blue",    :background => true) +
                                 color("white",   :bold       => true),
        "suite"               => color("green",   :background => true) +
                                 color("white",   :bold       => true),
        "diff-inserted-tag"   => color("red",     :background => true) +
                                 color("black",   :bold       => true),
        "diff-deleted-tag"    => color("green",   :background => true) +
                                 color("black",   :bold       => true),
        "diff-difference-tag" => color("cyan",    :background => true) +
                                 color("white",   :bold       => true),
        "diff-inserted"       => color("red",     :background => true) +
                                 color("white",   :bold       => true),
        "diff-deleted"        => color("green",   :background => true) +
                                 color("white",   :bold       => true),
      }
      assert_equal(expected_schema,
                   Test::Unit::ColorScheme.default.to_hash)
    end
  end
end