test-unit 3.4.4 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/Rakefile +0 -9
  4. data/doc/text/getting-started.md +1 -1
  5. data/doc/text/news.md +26 -1
  6. data/lib/test/unit/assertions.rb +93 -17
  7. data/lib/test/unit/testcase.rb +1 -1
  8. data/lib/test/unit/testsuite.rb +1 -1
  9. data/lib/test/unit/util/memory-usage.rb +47 -0
  10. data/lib/test/unit/version.rb +1 -1
  11. data/lib/test/unit.rb +4 -4
  12. metadata +6 -83
  13. data/test/collector/test-descendant.rb +0 -182
  14. data/test/collector/test-load.rb +0 -475
  15. data/test/collector/test_dir.rb +0 -407
  16. data/test/collector/test_objectspace.rb +0 -102
  17. data/test/fixtures/header-label.csv +0 -3
  18. data/test/fixtures/header-label.tsv +0 -3
  19. data/test/fixtures/header.csv +0 -3
  20. data/test/fixtures/header.tsv +0 -3
  21. data/test/fixtures/no-header.csv +0 -2
  22. data/test/fixtures/no-header.tsv +0 -2
  23. data/test/fixtures/plus.csv +0 -3
  24. data/test/run-test.rb +0 -22
  25. data/test/test-assertions.rb +0 -2281
  26. data/test/test-attribute-matcher.rb +0 -38
  27. data/test/test-attribute.rb +0 -123
  28. data/test/test-code-snippet.rb +0 -79
  29. data/test/test-color-scheme.rb +0 -123
  30. data/test/test-color.rb +0 -47
  31. data/test/test-data.rb +0 -419
  32. data/test/test-diff.rb +0 -518
  33. data/test/test-emacs-runner.rb +0 -60
  34. data/test/test-error.rb +0 -26
  35. data/test/test-failure.rb +0 -33
  36. data/test/test-fault-location-detector.rb +0 -163
  37. data/test/test-fixture.rb +0 -713
  38. data/test/test-notification.rb +0 -33
  39. data/test/test-omission.rb +0 -81
  40. data/test/test-pending.rb +0 -70
  41. data/test/test-priority.rb +0 -184
  42. data/test/test-test-case.rb +0 -1284
  43. data/test/test-test-result.rb +0 -113
  44. data/test/test-test-suite-creator.rb +0 -97
  45. data/test/test-test-suite.rb +0 -151
  46. data/test/testunit-test-util.rb +0 -33
  47. data/test/ui/test_testrunmediator.rb +0 -20
  48. data/test/util/test-method-owner-finder.rb +0 -38
  49. data/test/util/test-output.rb +0 -11
  50. data/test/util/test_backtracefilter.rb +0 -52
  51. data/test/util/test_observable.rb +0 -102
  52. 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,79 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "test-unit"
4
- require "testunit-test-util"
5
-
6
- class TestCodeSnippet < Test::Unit::TestCase
7
- include TestUnitTestUtil
8
-
9
- class TestJRuby < self
10
- def test_error_inside_jruby
11
- jruby_only_test
12
-
13
- backtrace = backtrace_from_jruby
14
- no_rb_entries = backtrace.find_all do |(file, _, _)|
15
- File.extname(file) != ".rb"
16
- end
17
-
18
- fetcher = Test::Unit::CodeSnippetFetcher.new
19
- snippets = no_rb_entries.collect do |(file, line, _)|
20
- fetcher.fetch(file, line)
21
- end
22
- assert_equal([[]] * no_rb_entries.size,
23
- snippets)
24
- end
25
-
26
- private
27
- def backtrace_from_jruby
28
- begin
29
- java.util.Vector.new(-1)
30
- rescue Exception
31
- $@.collect do |entry|
32
- entry.split(/:/, 3)
33
- end
34
- else
35
- flunk("failed to raise an exception from JRuby.")
36
- end
37
- end
38
- end
39
-
40
- class TestDefaultExternal < self
41
- def suppress_warning
42
- verbose = $VERBOSE
43
- begin
44
- $VERBOSE = false
45
- yield
46
- ensure
47
- $VERBOSE = verbose
48
- end
49
- end
50
-
51
- def setup
52
- suppress_warning do
53
- @default_external = Encoding.default_external
54
- end
55
- @fetcher = Test::Unit::CodeSnippetFetcher.new
56
- end
57
-
58
- def teardown
59
- suppress_warning do
60
- Encoding.default_external = @default_external
61
- end
62
- end
63
-
64
- def test_windows_31j
65
- source = Tempfile.new(["test-code-snippet", ".rb"])
66
- source.puts(<<-SOURCE)
67
- puts("あいうえお")
68
- SOURCE
69
- source.flush
70
- suppress_warning do
71
- Encoding.default_external = "Windows-31J"
72
- end
73
- assert_equal([
74
- [1, "puts(\"あいうえお\")", {:target_line? => false}],
75
- ],
76
- @fetcher.fetch(source.path, 0))
77
- end
78
- end
79
- end
@@ -1,123 +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
- module CleanEnvironment
45
- def setup
46
- @original_term, ENV["TERM"] = ENV["TERM"], nil
47
- @original_color_term, ENV["COLORTERM"] = ENV["COLORTERM"], nil
48
- @original_vte_version, ENV["VTE_VERSION"] = ENV["VTE_VERSION"], nil
49
- ENV["TERM"] = "xterm"
50
- end
51
-
52
- def teardown
53
- ENV["TERM"] = @original_term
54
- ENV["COLORTERM"] = @original_color_term
55
- ENV["VTE_VERSION"] = @original_vte_version
56
- end
57
- end
58
-
59
- class TestFor8Colors < self
60
- include CleanEnvironment
61
-
62
- def test_default
63
- expected_schema_keys = [
64
- "pass",
65
- "pass-marker",
66
- "failure",
67
- "failure-marker",
68
- "pending",
69
- "pending-marker",
70
- "omission",
71
- "omission-marker",
72
- "notification",
73
- "notification-marker",
74
- "error",
75
- "error-marker",
76
- "case",
77
- "suite",
78
- "diff-inserted-tag",
79
- "diff-deleted-tag",
80
- "diff-difference-tag",
81
- "diff-inserted",
82
- "diff-deleted",
83
- ]
84
- assert_equal(expected_schema_keys.sort,
85
- Test::Unit::ColorScheme.default.to_hash.keys.sort)
86
- end
87
- end
88
-
89
- class TestGuessAvailableColors < self
90
- include CleanEnvironment
91
- {
92
- "rxvt" => 8,
93
- "xterm-color" => 8,
94
- "alacritty" => 256,
95
- "iTerm.app" => 256,
96
- "screen-256color" => 256,
97
- "screenxterm-256color" => 256,
98
- "tmux-256color" => 256,
99
- "vte-256color" => 256,
100
- "vscode-direct" => 2**24,
101
- "vte-direct" => 2**24,
102
- "xterm-direct" => 2**24,
103
- }.each do |term, colors|
104
- data("%20s => %8d" % [term, colors], {term: term, colors: colors})
105
- end
106
- def test_term_env(data)
107
- ENV["TERM"] = data[:term]
108
- assert_equal(data[:colors],
109
- Test::Unit::ColorScheme.available_colors,
110
- "Incorrect available_colors for TERM=%s" % [data[:term]])
111
- end
112
- end
113
-
114
- class TestDefaultScheme < self
115
- include CleanEnvironment
116
-
117
- def test_direct_color
118
- ENV["TERM"] = "xterm-direct"
119
- assert_equal(Test::Unit::ColorScheme.default_for_256_colors,
120
- Test::Unit::ColorScheme.default)
121
- end
122
- end
123
- 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,419 +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_PROC = lambda 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
-
64
- data(&DATA_PROC)
65
- def test_plus(data)
66
- assert_equal(data[:expected],
67
- @calc.plus(data[:augend], data[:addend]))
68
- end
69
- end
70
-
71
- class TestLoadDataSet < TestCalc
72
- extend TestUnitTestUtil
73
- load_data(fixture_file_path("plus.csv"))
74
- def test_plus(data)
75
- assert_equal(data["expected"],
76
- @calc.plus(data["augend"], data["addend"]))
77
- end
78
- end
79
-
80
- class TestSuperclass < TestCalc
81
- data("positive positive" => {:expected => 4, :augend => 3, :addend => 1},
82
- "positive negative" => {:expected => -1, :augend => 1, :addend => -2})
83
- def test_plus(data)
84
- assert_equal(data[:expected],
85
- @calc.plus(data[:augend], data[:addend]))
86
- end
87
-
88
- class TestNormalTestInSubclass < self
89
- def test_plus
90
- assert_equal(2, @calc.plus(1, 1))
91
- end
92
- end
93
- end
94
-
95
- class TestMethod < TestCalc
96
- def data_test_plus
97
- {
98
- "positive positive" => {:expected => 4, :augend => 3, :addend => 1},
99
- "positive negative" => {:expected => -1, :augend => 1, :addend => -2},
100
- }
101
- end
102
-
103
- def test_plus(data)
104
- assert_equal(data[:expected],
105
- @calc.plus(data[:augend], data[:addend]))
106
- end
107
- end
108
-
109
- class TestPatterns < TestCalc
110
- data(:x, [-1, 1, 0])
111
- data(:y, [-100, 100])
112
- data(:z, ["a", "b", "c"])
113
- def test_use_data(data)
114
- end
115
- end
116
-
117
- class TestPatternsKeep < TestCalc
118
- data(:x, [-1, 1, 0], keep: true)
119
- data(:y, [-100, 100])
120
- data(:z, ["a", "b", "c"], keep: true)
121
- def test_use_data(data)
122
- end
123
-
124
- def test_use_data_keep(data)
125
- end
126
- end
127
-
128
- class TestPatternsGroup < TestCalc
129
- data(:a, [-1, 1, 0], group: 1)
130
- data(:b, [:a, :b], group: 1)
131
- data(:x, [2, 9], group: :z)
132
- data(:y, ["a", "b", "c"], group: :z)
133
- def test_use_data(data)
134
- end
135
- end
136
- end
137
-
138
- def setup
139
- TestCalc.testing = true
140
- end
141
-
142
- def teardown
143
- TestCalc.testing = false
144
- end
145
-
146
- def test_data_no_arguments_without_block
147
- assert_raise(ArgumentError) do
148
- self.class.data
149
- end
150
- end
151
-
152
- data("data set",
153
- {
154
- :test_case => TestCalc::TestDataSet,
155
- :data_sets => [
156
- {
157
- "positive positive" => {
158
- :expected => 4,
159
- :augend => 3,
160
- :addend => 1,
161
- },
162
- "positive negative" => {
163
- :expected => -1,
164
- :augend => 1,
165
- :addend => -2,
166
- },
167
- },
168
- ],
169
- })
170
- data("n-data",
171
- {
172
- :test_case => TestCalc::TestNData,
173
- :data_sets => [
174
- {
175
- "positive positive" => {
176
- :expected => 4,
177
- :augend => 3,
178
- :addend => 1,
179
- },
180
- },
181
- {
182
- "positive negative" => {
183
- :expected => -1,
184
- :augend => 1,
185
- :addend => -2,
186
- },
187
- },
188
- ],
189
- })
190
- data("dynamic-data-set",
191
- {
192
- :test_case => TestCalc::TestDynamicDataSet,
193
- :data_sets => [TestCalc::TestDynamicDataSet::DATA_PROC],
194
- })
195
- data("load-data-set",
196
- {
197
- :test_case => TestCalc::TestLoadDataSet,
198
- :data_sets => [
199
- {
200
- "positive positive" => {
201
- "expected" => 4,
202
- "augend" => 3,
203
- "addend" => 1,
204
- },
205
- },
206
- {
207
- "positive negative" => {
208
- "expected" => -1,
209
- "augend" => 1,
210
- "addend" => -2,
211
- },
212
- },
213
- ],
214
- })
215
- def test_data(data)
216
- test_plus = data[:test_case].new("test_plus")
217
- data_sets = Test::Unit::DataSets.new
218
- data[:data_sets].each do |data_set|
219
- data_sets.add(data_set)
220
- end
221
- assert_equal(data_sets, test_plus[:data])
222
- end
223
-
224
- def test_data_patterns
225
- test = TestCalc::TestPatterns.new("test_use_data")
226
- data_sets = Test::Unit::DataSets.new
227
- data_sets << [:x, [-1, 1, 0]]
228
- data_sets << [:y, [-100, 100]]
229
- data_sets << [:z, ["a", "b", "c"]]
230
- assert_equal(data_sets, test[:data])
231
- end
232
-
233
- def test_data_patterns_keep
234
- test = TestCalc::TestPatternsKeep.new("test_use_data_keep")
235
- data_sets = Test::Unit::DataSets.new
236
- data_sets.add([:x, [-1, 1, 0]], {keep: true})
237
- data_sets.add([:z, ["a", "b", "c"]], {keep: true})
238
- assert_equal(data_sets, test[:data])
239
- end
240
-
241
- data("data set" => TestCalc::TestDataSet,
242
- "n-data" => TestCalc::TestNData,
243
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
244
- "load-data-set" => TestCalc::TestLoadDataSet)
245
- def test_suite(test_case)
246
- suite = test_case.suite
247
- assert_equal(["test_plus[positive negative](#{test_case.name})",
248
- "test_plus[positive positive](#{test_case.name})"],
249
- suite.tests.collect {|test| test.name}.sort)
250
- end
251
-
252
- def test_suite_patterns
253
- test_case = TestCalc::TestPatterns
254
- suite = test_case.suite
255
- assert_equal([
256
- "test_use_data[x: -1, y: -100, z: \"a\"](#{test_case.name})",
257
- "test_use_data[x: -1, y: -100, z: \"b\"](#{test_case.name})",
258
- "test_use_data[x: -1, y: -100, z: \"c\"](#{test_case.name})",
259
- "test_use_data[x: -1, y: 100, z: \"a\"](#{test_case.name})",
260
- "test_use_data[x: -1, y: 100, z: \"b\"](#{test_case.name})",
261
- "test_use_data[x: -1, y: 100, z: \"c\"](#{test_case.name})",
262
- "test_use_data[x: 0, y: -100, z: \"a\"](#{test_case.name})",
263
- "test_use_data[x: 0, y: -100, z: \"b\"](#{test_case.name})",
264
- "test_use_data[x: 0, y: -100, z: \"c\"](#{test_case.name})",
265
- "test_use_data[x: 0, y: 100, z: \"a\"](#{test_case.name})",
266
- "test_use_data[x: 0, y: 100, z: \"b\"](#{test_case.name})",
267
- "test_use_data[x: 0, y: 100, z: \"c\"](#{test_case.name})",
268
- "test_use_data[x: 1, y: -100, z: \"a\"](#{test_case.name})",
269
- "test_use_data[x: 1, y: -100, z: \"b\"](#{test_case.name})",
270
- "test_use_data[x: 1, y: -100, z: \"c\"](#{test_case.name})",
271
- "test_use_data[x: 1, y: 100, z: \"a\"](#{test_case.name})",
272
- "test_use_data[x: 1, y: 100, z: \"b\"](#{test_case.name})",
273
- "test_use_data[x: 1, y: 100, z: \"c\"](#{test_case.name})",
274
- ],
275
- suite.tests.collect {|test| test.name}.sort)
276
- end
277
-
278
- def test_suite_patterns_group
279
- test_case = TestCalc::TestPatternsGroup
280
- suite = test_case.suite
281
- assert_equal([
282
- "test_use_data[group: 1, a: -1, b: :a](#{test_case.name})",
283
- "test_use_data[group: 1, a: -1, b: :b](#{test_case.name})",
284
- "test_use_data[group: 1, a: 0, b: :a](#{test_case.name})",
285
- "test_use_data[group: 1, a: 0, b: :b](#{test_case.name})",
286
- "test_use_data[group: 1, a: 1, b: :a](#{test_case.name})",
287
- "test_use_data[group: 1, a: 1, b: :b](#{test_case.name})",
288
- "test_use_data[group: :z, x: 2, y: \"a\"](#{test_case.name})",
289
- "test_use_data[group: :z, x: 2, y: \"b\"](#{test_case.name})",
290
- "test_use_data[group: :z, x: 2, y: \"c\"](#{test_case.name})",
291
- "test_use_data[group: :z, x: 9, y: \"a\"](#{test_case.name})",
292
- "test_use_data[group: :z, x: 9, y: \"b\"](#{test_case.name})",
293
- "test_use_data[group: :z, x: 9, y: \"c\"](#{test_case.name})",
294
- ],
295
- suite.tests.collect {|test| test.name}.sort)
296
- end
297
-
298
- data("data set" => TestCalc::TestDataSet,
299
- "n-data" => TestCalc::TestNData,
300
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
301
- "load-data-set" => TestCalc::TestLoadDataSet,
302
- "superclass" => TestCalc::TestSuperclass,
303
- "method" => TestCalc::TestMethod)
304
- def test_run(test_case)
305
- result = _run_test(test_case)
306
- assert_equal("2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
307
- "0 omissions, 0 notifications", result.to_s)
308
- end
309
-
310
- def test_run_normal_test_in_subclass
311
- result = _run_test(TestCalc::TestSuperclass::TestNormalTestInSubclass)
312
- assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
313
- "0 omissions, 0 notifications", result.to_s)
314
- end
315
-
316
- data("data set" => TestCalc::TestDataSet,
317
- "n-data" => TestCalc::TestNData,
318
- "dynamic-data-set" => TestCalc::TestDynamicDataSet,
319
- "load-data-set" => TestCalc::TestLoadDataSet)
320
- def test_equal(test_case)
321
- suite = test_case.suite
322
- positive_positive_test = suite.tests.find do |test|
323
- test.data_label == "positive positive"
324
- end
325
- suite.tests.delete(positive_positive_test)
326
- assert_equal(["test_plus[positive negative](#{test_case.name})"],
327
- suite.tests.collect {|test| test.name}.sort)
328
- end
329
-
330
- data("true" => {:expected => true, :target => "true"},
331
- "false" => {:expected => false, :target => "false"},
332
- "integer" => {:expected => 1, :target => "1"},
333
- "float" => {:expected => 1.5, :target => "1.5"},
334
- "string" => {:expected => "hello", :target => "hello"})
335
- def test_normalize_value(data)
336
- loader = Test::Unit::Data::ClassMethods::Loader.new(self)
337
- assert_equal(data[:expected], loader.__send__(:normalize_value, data[:target]))
338
- end
339
-
340
- def _run_test(test_case)
341
- result = Test::Unit::TestResult.new
342
- test = test_case.suite
343
- yield(test) if block_given?
344
- test.run(result) {}
345
- result
346
- end
347
-
348
- class TestLoadData < Test::Unit::TestCase
349
- include TestUnitTestUtil
350
- def test_invalid_csv_file_name
351
- garbage = "X"
352
- file_name = "data.csv#{garbage}"
353
- assert_raise(ArgumentError, "unsupported file format: <#{file_name}>") do
354
- self.class.load_data(file_name)
355
- end
356
- end
357
-
358
- class TestFileFormat < self
359
- def setup
360
- self.class.current_attribute(:data).clear
361
- end
362
-
363
- class TestHeader < self
364
- data("csv" => "header.csv",
365
- "tsv" => "header.tsv")
366
- def test_normal(file_name)
367
- self.class.load_data(fixture_file_path(file_name))
368
- data_sets = Test::Unit::DataSets.new
369
- data_sets << {
370
- "empty string" => {
371
- "expected" => true,
372
- "target" => ""
373
- }
374
- }
375
- data_sets << {
376
- "plain string" => {
377
- "expected" => false,
378
- "target" => "hello"
379
- }
380
- }
381
- assert_equal(data_sets,
382
- self.class.current_attribute(:data)[:value])
383
- end
384
-
385
- data("csv" => "header-label.csv",
386
- "tsv" => "header-label.tsv")
387
- def test_label(file_name)
388
- self.class.load_data(fixture_file_path(file_name))
389
- data_sets = Test::Unit::DataSets.new
390
- data_sets << {
391
- "upper case" => {
392
- "expected" => "HELLO",
393
- "label" => "HELLO"
394
- }
395
- }
396
- data_sets << {
397
- "lower case" => {
398
- "expected" => "Hello",
399
- "label" => "hello"
400
- }
401
- }
402
- assert_equal(data_sets,
403
- self.class.current_attribute(:data)[:value])
404
- end
405
- end
406
-
407
- data("csv" => "no-header.csv",
408
- "tsv" => "no-header.tsv")
409
- def test_without_header(file_name)
410
- self.class.load_data(fixture_file_path(file_name))
411
- data_sets = Test::Unit::DataSets.new
412
- data_sets << {"empty string" => [true, ""]}
413
- data_sets << {"plain string" => [false, "hello"]}
414
- assert_equal(data_sets,
415
- self.class.current_attribute(:data)[:value])
416
- end
417
- end
418
- end
419
- end