test-unit 3.1.5 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/BSDL +24 -0
  3. data/COPYING +41 -41
  4. data/README.md +24 -17
  5. data/Rakefile +21 -24
  6. data/doc/text/getting-started.md +246 -0
  7. data/doc/text/news.md +797 -56
  8. data/lib/test/unit/assertion-failed-error.rb +35 -0
  9. data/lib/test/unit/assertions.rb +542 -220
  10. data/lib/test/unit/attribute.rb +78 -4
  11. data/lib/test/unit/auto-runner-loader.rb +17 -0
  12. data/lib/test/unit/autorunner.rb +175 -78
  13. data/lib/test/unit/code-snippet-fetcher.rb +7 -7
  14. data/lib/test/unit/collector/descendant.rb +1 -0
  15. data/lib/test/unit/collector/dir.rb +4 -2
  16. data/lib/test/unit/collector/load.rb +25 -15
  17. data/lib/test/unit/collector/objectspace.rb +1 -0
  18. data/lib/test/unit/collector.rb +31 -0
  19. data/lib/test/unit/color-scheme.rb +29 -2
  20. data/lib/test/unit/data-sets.rb +127 -0
  21. data/lib/test/unit/data.rb +121 -12
  22. data/lib/test/unit/diff.rb +10 -11
  23. data/lib/test/unit/fixture.rb +77 -27
  24. data/lib/test/unit/notification.rb +9 -7
  25. data/lib/test/unit/omission.rb +34 -31
  26. data/lib/test/unit/pending.rb +12 -11
  27. data/lib/test/unit/priority.rb +7 -5
  28. data/lib/test/unit/runner/console.rb +20 -1
  29. data/lib/test/unit/test-suite-creator.rb +30 -9
  30. data/lib/test/unit/testcase.rb +349 -196
  31. data/lib/test/unit/testresult.rb +7 -0
  32. data/lib/test/unit/testsuite.rb +1 -1
  33. data/lib/test/unit/ui/console/testrunner.rb +171 -60
  34. data/lib/test/unit/ui/emacs/testrunner.rb +5 -5
  35. data/lib/test/unit/ui/testrunnermediator.rb +9 -7
  36. data/lib/test/unit/util/backtracefilter.rb +17 -5
  37. data/lib/test/unit/util/memory-usage.rb +47 -0
  38. data/lib/test/unit/util/observable.rb +2 -2
  39. data/lib/test/unit/util/output.rb +5 -4
  40. data/lib/test/unit/util/procwrapper.rb +4 -4
  41. data/lib/test/unit/version.rb +1 -1
  42. data/lib/test/unit/warning.rb +3 -0
  43. data/lib/test/unit.rb +177 -161
  44. data/lib/test-unit.rb +2 -17
  45. metadata +20 -94
  46. data/GPL +0 -339
  47. data/LGPL +0 -502
  48. data/test/collector/test-descendant.rb +0 -178
  49. data/test/collector/test-load.rb +0 -442
  50. data/test/collector/test_dir.rb +0 -406
  51. data/test/collector/test_objectspace.rb +0 -100
  52. data/test/fixtures/header-label.csv +0 -3
  53. data/test/fixtures/header-label.tsv +0 -3
  54. data/test/fixtures/header.csv +0 -3
  55. data/test/fixtures/header.tsv +0 -3
  56. data/test/fixtures/no-header.csv +0 -2
  57. data/test/fixtures/no-header.tsv +0 -2
  58. data/test/fixtures/plus.csv +0 -3
  59. data/test/run-test.rb +0 -22
  60. data/test/test-assertions.rb +0 -2157
  61. data/test/test-attribute-matcher.rb +0 -38
  62. data/test/test-attribute.rb +0 -123
  63. data/test/test-code-snippet.rb +0 -37
  64. data/test/test-color-scheme.rb +0 -82
  65. data/test/test-color.rb +0 -47
  66. data/test/test-data.rb +0 -281
  67. data/test/test-diff.rb +0 -518
  68. data/test/test-emacs-runner.rb +0 -60
  69. data/test/test-error.rb +0 -26
  70. data/test/test-failure.rb +0 -33
  71. data/test/test-fault-location-detector.rb +0 -163
  72. data/test/test-fixture.rb +0 -659
  73. data/test/test-notification.rb +0 -33
  74. data/test/test-omission.rb +0 -81
  75. data/test/test-pending.rb +0 -70
  76. data/test/test-priority.rb +0 -173
  77. data/test/test-test-case.rb +0 -1171
  78. data/test/test-test-result.rb +0 -113
  79. data/test/test-test-suite-creator.rb +0 -97
  80. data/test/test-test-suite.rb +0 -150
  81. data/test/testunit-test-util.rb +0 -31
  82. data/test/ui/test_testrunmediator.rb +0 -20
  83. data/test/util/test-method-owner-finder.rb +0 -38
  84. data/test/util/test-output.rb +0 -11
  85. data/test/util/test_backtracefilter.rb +0 -41
  86. data/test/util/test_observable.rb +0 -102
  87. data/test/util/test_procwrapper.rb +0 -36
@@ -1,38 +0,0 @@
1
- require 'test/unit'
2
- require 'testunit-test-util'
3
-
4
- class TestAttributeMatcher < Test::Unit::TestCase
5
- include TestUnitTestUtil
6
-
7
- def setup
8
- @test = {}
9
- @matcher = Test::Unit::AttributeMatcher.new(@test)
10
- end
11
-
12
- def test_nonexistent
13
- assert_false(@matcher.match?("nonexistent"))
14
- end
15
-
16
- def test_existent
17
- @test[:existent] = true
18
- assert_true(@matcher.match?("existent"))
19
- end
20
-
21
- def test_and
22
- @test[:slow] = true
23
- @test[:important] = true
24
- assert_true(@matcher.match?("important and slow"))
25
- end
26
-
27
- def test_complex
28
- @test[:tags] = [:slow, :web]
29
- @test[:bug] = "2929"
30
- assert_true(@matcher.match?("tags.include?(:web) or bug == '29'"))
31
- end
32
-
33
- def test_exception
34
- assert_raise(NoMethodError) do
35
- @matcher.match?("nonexistent > 100")
36
- end
37
- end
38
- end
@@ -1,123 +0,0 @@
1
- class TestUnitAttribute < Test::Unit::TestCase
2
- class TestStack < Test::Unit::TestCase
3
- class << self
4
- def suite
5
- Test::Unit::TestSuite.new(name)
6
- end
7
- end
8
-
9
- class Stack
10
- def initialize
11
- @data = []
12
- end
13
-
14
- def push(data)
15
- @data.push(data)
16
- end
17
-
18
- def peek
19
- @data[-2]
20
- end
21
-
22
- def empty?
23
- @data.empty?
24
- end
25
-
26
- def size
27
- @data.size + 11
28
- end
29
- end
30
-
31
- def setup
32
- @stack = Stack.new
33
- end
34
-
35
- attribute :category, :accessor
36
- def test_peek
37
- @stack.push(1)
38
- @stack.push(2)
39
- assert_equal(2, @stack.peek)
40
- end
41
-
42
- attribute :bug, 1234
43
- def test_bug_1234
44
- assert_equal(0, @stack.size)
45
- end
46
-
47
- def test_no_attributes
48
- assert(@stack.empty?)
49
- @stack.push(1)
50
- assert(!@stack.empty?)
51
- assert_equal(1, @stack.size)
52
- end
53
- end
54
-
55
- def test_set_attributes
56
- test_for_accessor_category = TestStack.new("test_peek")
57
- assert_equal({"category" => :accessor},
58
- test_for_accessor_category.attributes)
59
-
60
- test_for_bug_1234 = TestStack.new("test_bug_1234")
61
- assert_equal({"bug" => 1234}, test_for_bug_1234.attributes)
62
-
63
- test_no_attributes = TestStack.new("test_no_attributes")
64
- assert_equal({}, test_no_attributes.attributes)
65
- end
66
-
67
- def test_callback
68
- changed_attributes = []
69
- observer = Proc.new do |test_case, key, old_value, value, method_name|
70
- changed_attributes << [test_case, key, old_value, value, method_name]
71
- end
72
-
73
- test_case = Class.new(TestStack) do
74
- register_attribute_observer(:bug, &observer)
75
- attribute("bug", 9876, "test_bug_1234")
76
- attribute(:description, "Test for peek", "test_peek")
77
- attribute(:bug, 29, "test_peek")
78
- end
79
-
80
- assert_equal([
81
- [test_case, "bug", 1234, 9876, "test_bug_1234"],
82
- [test_case, "bug", nil, 29, "test_peek"],
83
- ],
84
- changed_attributes)
85
- end
86
-
87
- def test_attributes_with_prepended_module
88
- omit("Module#prepend is needed") unless Module.respond_to?(:prepend, true)
89
- test_case = Class.new(TestStack) do
90
- prepend Module.new
91
- end
92
- assert_equal({
93
- "category" => :accessor,
94
- },
95
- test_case.attributes("test_peek"))
96
- end
97
-
98
- class TestDescription < self
99
- def test_decoration_style
100
- test_case = Class.new(TestStack) do
101
- description "Test for push"
102
- def test_push
103
- end
104
- end
105
-
106
- test_push = test_case.new("test_push")
107
- assert_equal({"description" => "Test for push"},
108
- test_push.attributes)
109
- end
110
-
111
- def test_explicit_test_name_style
112
- test_case = Class.new(TestStack) do
113
- def test_push
114
- end
115
- description "Test for push", :test_push
116
- end
117
-
118
- test_push = test_case.new("test_push")
119
- assert_equal({"description" => "Test for push"},
120
- test_push.attributes)
121
- end
122
- end
123
- end
@@ -1,37 +0,0 @@
1
- require "test-unit"
2
- require "testunit-test-util"
3
-
4
- class TestCodeSnippet < Test::Unit::TestCase
5
- include TestUnitTestUtil
6
-
7
- class TestJRuby < self
8
- def test_error_inside_jruby
9
- jruby_only_test
10
-
11
- backtrace = backtrace_from_jruby
12
- no_rb_entries = backtrace.find_all do |(file, _, _)|
13
- File.extname(file) != ".rb"
14
- end
15
-
16
- fetcher = Test::Unit::CodeSnippetFetcher.new
17
- snippets = no_rb_entries.collect do |(file, line, _)|
18
- fetcher.fetch(file, line)
19
- end
20
- assert_equal([[]] * no_rb_entries.size,
21
- snippets)
22
- end
23
-
24
- private
25
- def backtrace_from_jruby
26
- begin
27
- java.util.Vector.new(-1)
28
- rescue Exception
29
- $@.collect do |entry|
30
- entry.split(/:/, 3)
31
- end
32
- else
33
- flunk("failed to raise an exception from JRuby.")
34
- end
35
- end
36
- end
37
- end
@@ -1,82 +0,0 @@
1
- class TestUnitColorScheme < Test::Unit::TestCase
2
- def test_register
3
- inverted_scheme_spec = {
4
- "success" => {:name => "red"},
5
- "failure" => {:name => "green"},
6
- }
7
- Test::Unit::ColorScheme["inverted"] = inverted_scheme_spec
8
- assert_equal({
9
- "success" => color("red"),
10
- "failure" => color("green"),
11
- },
12
- Test::Unit::ColorScheme["inverted"].to_hash)
13
- end
14
-
15
- def test_new_with_colors
16
- scheme = Test::Unit::ColorScheme.new(:success => color("blue"),
17
- "failure" => color("green",
18
- :underline => true))
19
- assert_equal({
20
- "success" => color("blue"),
21
- "failure" => color("green", :underline => true),
22
- },
23
- scheme.to_hash)
24
- end
25
-
26
- def test_new_with_spec
27
- scheme = Test::Unit::ColorScheme.new(:success => {
28
- :name => "blue",
29
- :bold => true
30
- },
31
- "failure" => {:name => "green"})
32
- assert_equal({
33
- "success" => color("blue", :bold => true),
34
- "failure" => color("green"),
35
- },
36
- scheme.to_hash)
37
- end
38
-
39
- private
40
- def color(name, options={})
41
- Test::Unit::Color.new(name, options)
42
- end
43
-
44
- class TestFor8Colors < self
45
- def setup
46
- @original_term, ENV["TERM"] = ENV["TERM"], nil
47
- @original_color_term, ENV["COLORTERM"] = ENV["COLORTERM"], nil
48
- ENV["TERM"] = "xterm"
49
- end
50
-
51
- def teardown
52
- ENV["TERM"] = @original_term
53
- ENV["COLORTERM"] = @original_color_term
54
- end
55
-
56
- def test_default
57
- expected_schema_keys = [
58
- "pass",
59
- "pass-marker",
60
- "failure",
61
- "failure-marker",
62
- "pending",
63
- "pending-marker",
64
- "omission",
65
- "omission-marker",
66
- "notification",
67
- "notification-marker",
68
- "error",
69
- "error-marker",
70
- "case",
71
- "suite",
72
- "diff-inserted-tag",
73
- "diff-deleted-tag",
74
- "diff-difference-tag",
75
- "diff-inserted",
76
- "diff-deleted",
77
- ]
78
- assert_equal(expected_schema_keys.sort,
79
- Test::Unit::ColorScheme.default.to_hash.keys.sort)
80
- end
81
- end
82
- end
data/test/test-color.rb DELETED
@@ -1,47 +0,0 @@
1
- class TestUnitColor < Test::Unit::TestCase
2
- def test_color_escape_sequence
3
- assert_escape_sequence(["31"], color("red"))
4
- assert_escape_sequence(["32", "1"], color("green", :bold => true))
5
- assert_escape_sequence(["0"], color("reset"))
6
- assert_escape_sequence(["45"], color("magenta", :background => true))
7
- end
8
-
9
- def test_mix_color_escape_sequence
10
- assert_escape_sequence(["34", "1"],
11
- mix_color([color("blue"),
12
- color("none", :bold => true)]))
13
- assert_escape_sequence(["34", "1", "4"],
14
- mix_color([color("blue"),
15
- color("none", :bold => true)]) +
16
- color("none", :underline => true))
17
- assert_escape_sequence(["34", "1", "4"],
18
- color("blue") +
19
- color("none", :bold => true) +
20
- color("none", :underline => true))
21
- end
22
-
23
- def test_equal
24
- red = color("red")
25
- red_bold = color("red", :bold => true)
26
-
27
- assert_operator(red, :==, red)
28
- assert_not_equal(red, nil)
29
- assert_equal(red, color("red"))
30
- assert_not_equal(red, red_bold)
31
- end
32
-
33
- private
34
- def color(name, options={})
35
- Test::Unit::Color.new(name, options)
36
- end
37
-
38
- def mix_color(colors)
39
- Test::Unit::MixColor.new(colors)
40
- end
41
-
42
- def assert_escape_sequence(expected, color)
43
- assert_equal(expected, color.sequence)
44
- assert_match(/\e\[(?:\d+;)*\d+m/, color.escape_sequence)
45
- assert_equal(expected, color.escape_sequence[2..-2].split(";"))
46
- end
47
- end
data/test/test-data.rb DELETED
@@ -1,281 +0,0 @@
1
- require "testunit-test-util"
2
-
3
- class TestData < Test::Unit::TestCase
4
- class Calc
5
- def initialize
6
- end
7
-
8
- def plus(augend, addend)
9
- augend + addend
10
- end
11
- end
12
-
13
- class TestCalc < Test::Unit::TestCase
14
- @@testing = false
15
-
16
- class << self
17
- def testing=(testing)
18
- @@testing = testing
19
- end
20
- end
21
-
22
- def valid?
23
- @@testing
24
- end
25
-
26
- def setup
27
- @calc = Calc.new
28
- end
29
-
30
- class TestDataSet < TestCalc
31
- data("positive positive" => {:expected => 4, :augend => 3, :addend => 1},
32
- "positive negative" => {:expected => -1, :augend => 1, :addend => -2})
33
- def test_plus(data)
34
- assert_equal(data[:expected],
35
- @calc.plus(data[:augend], data[:addend]))
36
- end
37
- end
38
-
39
- class TestNData < TestCalc
40
- data("positive positive", {:expected => 4, :augend => 3, :addend => 1})
41
- data("positive negative", {:expected => -1, :augend => 1, :addend => -2})
42
- def test_plus(data)
43
- assert_equal(data[:expected],
44
- @calc.plus(data[:augend], data[:addend]))
45
- end
46
- end
47
-
48
- class TestDynamicDataSet < TestCalc
49
- data do
50
- data_set = {}
51
- data_set["positive positive"] = {
52
- :expected => 3,
53
- :augend => 1,
54
- :addend => 2
55
- }
56
- data_set["positive negative"] = {
57
- :expected => -1,
58
- :augend => 1,
59
- :addend => -2
60
- }
61
- data_set
62
- end
63
- DATA_PROC = current_attribute(:data)[:value].first
64
- def test_plus(data)
65
- assert_equal(data[:expected],
66
- @calc.plus(data[:augend], data[:addend]))
67
- end
68
- end
69
-
70
- class TestLoadDataSet < TestCalc
71
- extend TestUnitTestUtil
72
- load_data(fixture_file_path("plus.csv"))
73
- def test_plus(data)
74
- assert_equal(data["expected"],
75
- @calc.plus(data["augend"], data["addend"]))
76
- end
77
- end
78
- end
79
-
80
- def setup
81
- TestCalc.testing = true
82
- end
83
-
84
- def teardown
85
- TestCalc.testing = false
86
- end
87
-
88
- def test_data_no_arguments_without_block
89
- assert_raise(ArgumentError) do
90
- self.class.data
91
- end
92
- end
93
-
94
- data("data set",
95
- {
96
- :test_case => TestCalc::TestDataSet,
97
- :data_set => [{
98
- "positive positive" => {
99
- :expected => 4,
100
- :augend => 3,
101
- :addend => 1,
102
- },
103
- "positive negative" => {
104
- :expected => -1,
105
- :augend => 1,
106
- :addend => -2,
107
- },
108
- }],
109
- })
110
- data("n-data",
111
- {
112
- :test_case => TestCalc::TestNData,
113
- :data_set => [{
114
- "positive positive" => {
115
- :expected => 4,
116
- :augend => 3,
117
- :addend => 1,
118
- },
119
- },
120
- {
121
- "positive negative" => {
122
- :expected => -1,
123
- :augend => 1,
124
- :addend => -2,
125
- },
126
- }],
127
- })
128
- data("dynamic-data-set",
129
- {
130
- :test_case => TestCalc::TestDynamicDataSet,
131
- :data_set => [TestCalc::TestDynamicDataSet::DATA_PROC],
132
- })
133
- data("load-data-set",
134
- {
135
- :test_case => TestCalc::TestLoadDataSet,
136
- :data_set => [{
137
- "positive positive" => {
138
- "expected" => 4,
139
- "augend" => 3,
140
- "addend" => 1,
141
- },
142
- },
143
- {
144
- "positive negative" => {
145
- "expected" => -1,
146
- "augend" => 1,
147
- "addend" => -2,
148
- },
149
- }],
150
- })
151
- def test_data(data)
152
- test_plus = data[:test_case].new("test_plus")
153
- assert_equal(data[:data_set], test_plus[:data])
154
- assert_not_nil(data[:data_set])
155
- end
156
-
157
- data("data set" => TestCalc::TestDataSet,
158
- "n-data" => TestCalc::TestNData,
159
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
160
- "load-data-set" => TestCalc::TestLoadDataSet)
161
- def test_suite(test_case)
162
- suite = test_case.suite
163
- assert_equal(["test_plus[positive negative](#{test_case.name})",
164
- "test_plus[positive positive](#{test_case.name})"],
165
- suite.tests.collect {|test| test.name}.sort)
166
- end
167
-
168
- data("data set" => TestCalc::TestDataSet,
169
- "n-data" => TestCalc::TestNData,
170
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
171
- "load-data-set" => TestCalc::TestLoadDataSet)
172
- def test_run(test_case)
173
- result = _run_test(test_case)
174
- assert_equal("2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
175
- "0 omissions, 0 notifications", result.to_s)
176
- end
177
-
178
- data("data set" => TestCalc::TestDataSet,
179
- "n-data" => TestCalc::TestNData,
180
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
181
- "load-data-set" => TestCalc::TestLoadDataSet)
182
- def test_equal(test_case)
183
- suite = test_case.suite
184
- positive_positive_test = suite.tests.find do |test|
185
- test.data_label == "positive positive"
186
- end
187
- suite.tests.delete(positive_positive_test)
188
- assert_equal(["test_plus[positive negative](#{test_case.name})"],
189
- suite.tests.collect {|test| test.name}.sort)
190
- end
191
-
192
- data("true" => {:expected => true, :target => "true"},
193
- "false" => {:expected => false, :target => "false"},
194
- "integer" => {:expected => 1, :target => "1"},
195
- "float" => {:expected => 1.5, :target => "1.5"},
196
- "string" => {:expected => "hello", :target => "hello"})
197
- def test_normalize_value(data)
198
- loader = Test::Unit::Data::ClassMethods::Loader.new(self)
199
- assert_equal(data[:expected], loader.__send__(:normalize_value, data[:target]))
200
- end
201
-
202
- def _run_test(test_case)
203
- result = Test::Unit::TestResult.new
204
- test = test_case.suite
205
- yield(test) if block_given?
206
- test.run(result) {}
207
- result
208
- end
209
-
210
- class TestLoadData < Test::Unit::TestCase
211
- include TestUnitTestUtil
212
- def test_invalid_csv_file_name
213
- garbage = "X"
214
- file_name = "data.csv#{garbage}"
215
- assert_raise(ArgumentError, "unsupported file format: <#{file_name}>") do
216
- self.class.load_data(file_name)
217
- end
218
- end
219
-
220
- class TestFileFormat < self
221
- def setup
222
- self.class.current_attribute(:data).clear
223
- end
224
-
225
- class TestHeader < self
226
- data("csv" => "header.csv",
227
- "tsv" => "header.tsv")
228
- def test_normal(file_name)
229
- self.class.load_data(fixture_file_path(file_name))
230
- assert_equal([
231
- {
232
- "empty string" => {
233
- "expected" => true,
234
- "target" => ""
235
- }
236
- },
237
- {
238
- "plain string" => {
239
- "expected" => false,
240
- "target" => "hello"
241
- }
242
- }
243
- ],
244
- self.class.current_attribute(:data)[:value])
245
- end
246
-
247
- data("csv" => "header-label.csv",
248
- "tsv" => "header-label.tsv")
249
- def test_label(file_name)
250
- self.class.load_data(fixture_file_path(file_name))
251
- assert_equal([
252
- {
253
- "upper case" => {
254
- "expected" => "HELLO",
255
- "label" => "HELLO"
256
- }
257
- },
258
- {
259
- "lower case" => {
260
- "expected" => "Hello",
261
- "label" => "hello"
262
- }
263
- }
264
- ],
265
- self.class.current_attribute(:data)[:value])
266
- end
267
- end
268
-
269
- data("csv" => "no-header.csv",
270
- "tsv" => "no-header.tsv")
271
- def test_without_header(file_name)
272
- self.class.load_data(fixture_file_path(file_name))
273
- assert_equal([
274
- {"empty string" => [true, ""]},
275
- {"plain string" => [false, "hello"]}
276
- ],
277
- self.class.current_attribute(:data)[:value])
278
- end
279
- end
280
- end
281
- end