cairo 1.8.5 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cairo might be problematic. Click here for more details.

Files changed (106) hide show
  1. data/NEWS +2 -2
  2. data/Rakefile +44 -7
  3. data/ext/cairo/cairo.def +28 -1
  4. data/ext/cairo/extconf.rb +14 -16
  5. data/ext/cairo/rb_cairo.c +4 -1
  6. data/ext/cairo/rb_cairo.h +65 -1
  7. data/ext/cairo/rb_cairo_constants.c +150 -3
  8. data/ext/cairo/rb_cairo_context.c +17 -0
  9. data/ext/cairo/rb_cairo_device.c +406 -0
  10. data/ext/cairo/rb_cairo_exception.c +83 -32
  11. data/ext/cairo/rb_cairo_io.c +166 -0
  12. data/ext/cairo/rb_cairo_io.h +44 -0
  13. data/ext/cairo/rb_cairo_matrix.c +1 -1
  14. data/ext/cairo/rb_cairo_private.h +3 -0
  15. data/ext/cairo/rb_cairo_region.c +385 -0
  16. data/ext/cairo/rb_cairo_surface.c +674 -199
  17. data/samples/blur.rb +2 -3
  18. data/samples/{pac2.rb → pac-nomralize.rb} +5 -6
  19. data/samples/pac-tee.rb +170 -0
  20. data/samples/pac.rb +2 -3
  21. data/samples/png.rb +2 -3
  22. data/samples/scalable.rb +2 -3
  23. data/samples/text-on-path.rb +2 -3
  24. data/samples/text2.rb +2 -3
  25. data/test/cairo-test-utils.rb +15 -0
  26. data/test/run-test.rb +5 -4
  27. data/test/test_context.rb +4 -4
  28. data/test/test_font_face.rb +34 -21
  29. data/test/test_recording_surface.rb +18 -0
  30. data/test/test_region.rb +102 -0
  31. data/test/test_script_device.rb +46 -0
  32. data/test/test_script_surface.rb +13 -0
  33. data/test/test_surface.rb +14 -4
  34. data/test/test_tee_surface.rb +32 -0
  35. data/test/test_xml_device.rb +22 -0
  36. data/test/test_xml_surface.rb +32 -0
  37. metadata +49 -77
  38. data/pkg-config.rb +0 -313
  39. data/test-unit/Rakefile +0 -30
  40. data/test-unit/bin/testrb +0 -5
  41. data/test-unit/lib/test/unit.rb +0 -280
  42. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -14
  43. data/test-unit/lib/test/unit/assertions.rb +0 -722
  44. data/test-unit/lib/test/unit/attribute.rb +0 -125
  45. data/test-unit/lib/test/unit/autorunner.rb +0 -254
  46. data/test-unit/lib/test/unit/collector.rb +0 -43
  47. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  48. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  49. data/test-unit/lib/test/unit/collector/load.rb +0 -135
  50. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  51. data/test-unit/lib/test/unit/color.rb +0 -61
  52. data/test-unit/lib/test/unit/diff.rb +0 -524
  53. data/test-unit/lib/test/unit/error.rb +0 -124
  54. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  55. data/test-unit/lib/test/unit/failure.rb +0 -110
  56. data/test-unit/lib/test/unit/fixture.rb +0 -185
  57. data/test-unit/lib/test/unit/notification.rb +0 -125
  58. data/test-unit/lib/test/unit/omission.rb +0 -143
  59. data/test-unit/lib/test/unit/pending.rb +0 -146
  60. data/test-unit/lib/test/unit/priority.rb +0 -146
  61. data/test-unit/lib/test/unit/runner/console.rb +0 -46
  62. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  63. data/test-unit/lib/test/unit/testcase.rb +0 -281
  64. data/test-unit/lib/test/unit/testresult.rb +0 -89
  65. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  66. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  67. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -195
  68. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -49
  69. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -20
  70. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  71. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  72. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  73. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  74. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  75. data/test-unit/lib/test/unit/version.rb +0 -7
  76. data/test-unit/sample/adder.rb +0 -13
  77. data/test-unit/sample/subtracter.rb +0 -12
  78. data/test-unit/sample/tc_adder.rb +0 -18
  79. data/test-unit/sample/tc_subtracter.rb +0 -18
  80. data/test-unit/sample/ts_examples.rb +0 -7
  81. data/test-unit/test/collector/test_descendant.rb +0 -135
  82. data/test-unit/test/collector/test_dir.rb +0 -406
  83. data/test-unit/test/collector/test_load.rb +0 -333
  84. data/test-unit/test/collector/test_objectspace.rb +0 -98
  85. data/test-unit/test/run-test.rb +0 -13
  86. data/test-unit/test/test_assertions.rb +0 -693
  87. data/test-unit/test/test_attribute.rb +0 -86
  88. data/test-unit/test/test_color.rb +0 -37
  89. data/test-unit/test/test_diff.rb +0 -477
  90. data/test-unit/test/test_emacs_runner.rb +0 -60
  91. data/test-unit/test/test_error.rb +0 -26
  92. data/test-unit/test/test_failure.rb +0 -33
  93. data/test-unit/test/test_fixture.rb +0 -252
  94. data/test-unit/test/test_notification.rb +0 -33
  95. data/test-unit/test/test_omission.rb +0 -81
  96. data/test-unit/test/test_pending.rb +0 -70
  97. data/test-unit/test/test_priority.rb +0 -89
  98. data/test-unit/test/test_testcase.rb +0 -430
  99. data/test-unit/test/test_testresult.rb +0 -113
  100. data/test-unit/test/test_testsuite.rb +0 -129
  101. data/test-unit/test/testunit_test_util.rb +0 -14
  102. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  103. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  104. data/test-unit/test/util/test_observable.rb +0 -102
  105. data/test-unit/test/util/test_procwrapper.rb +0 -36
  106. data/test/test_pkg_config.rb +0 -123
@@ -1,333 +0,0 @@
1
- require 'tmpdir'
2
- require 'pathname'
3
-
4
- require 'test/unit'
5
- require 'test/unit/collector/load'
6
-
7
- class TestUnitCollectorLoad < Test::Unit::TestCase
8
- def setup
9
- @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
10
- Test::Unit::TestCase::DESCENDANTS.clear
11
-
12
- @temporary_test_cases_module_name = "TempTestCases"
13
- ::Object.const_set(@temporary_test_cases_module_name, Module.new)
14
-
15
- @test_dir = Pathname(Dir.tmpdir) + "test-unit"
16
- @test_dir.rmtree if @test_dir.exist?
17
- @test_dir.mkpath
18
- end
19
-
20
- setup
21
- def setup_top_level_test_cases
22
- @test_case1 = @test_dir + "test_case1.rb"
23
- @test_case2 = @test_dir + "test_case2.rb"
24
- @no_load_test_case3 = @test_dir + "case3.rb"
25
-
26
- @test_case1.open("w") do |test_case|
27
- test_case.puts(<<-EOT)
28
- module #{@temporary_test_cases_module_name}
29
- class TestCase1 < Test::Unit::TestCase
30
- def test1_1
31
- end
32
-
33
- def test1_2
34
- end
35
- end
36
- end
37
- EOT
38
- end
39
-
40
- @test_case2.open("w") do |test_case|
41
- test_case.puts(<<-EOT)
42
- module #{@temporary_test_cases_module_name}
43
- class TestCase2 < Test::Unit::TestCase
44
- def test2
45
- end
46
- end
47
- end
48
- EOT
49
- end
50
-
51
- @no_load_test_case3.open("w") do |test_case|
52
- test_case.puts(<<-EOT)
53
- module #{@temporary_test_cases_module_name}
54
- class NoLoadTestCase3 < Test::Unit::TestCase
55
- def test3
56
- end
57
- end
58
- end
59
- EOT
60
- end
61
- end
62
-
63
- setup
64
- def setup_sub_level_test_cases
65
- @sub_test_dir = @test_dir + "sub"
66
- @sub_test_dir.mkpath
67
-
68
- @sub_test_case4 = @sub_test_dir + "test_case4.rb"
69
- @no_load_sub_test_case5 = @sub_test_dir + "case5.rb"
70
- @sub_test_case6 = @sub_test_dir + "test_case6.rb"
71
-
72
- @sub_test_case4.open("w") do |test_case|
73
- test_case.puts(<<-EOT)
74
- module #{@temporary_test_cases_module_name}
75
- class SubTestCase4 < Test::Unit::TestCase
76
- def test4_1
77
- end
78
-
79
- def test4_2
80
- end
81
- end
82
- end
83
- EOT
84
- end
85
-
86
- @no_load_sub_test_case5.open("w") do |test_case|
87
- test_case.puts(<<-EOT)
88
- module #{@temporary_test_cases_module_name}
89
- class NoLoadSubTestCase5 < Test::Unit::TestCase
90
- def test5_1
91
- end
92
-
93
- def test5_2
94
- end
95
- end
96
- end
97
- EOT
98
- end
99
-
100
- @sub_test_case6.open("w") do |test_case|
101
- test_case.puts(<<-EOT)
102
- module #{@temporary_test_cases_module_name}
103
- class SubTestCase6 < Test::Unit::TestCase
104
- def test6
105
- end
106
- end
107
- end
108
- EOT
109
- end
110
- end
111
-
112
- setup
113
- def setup_sub_level_test_cases2
114
- @sub2_test_dir = @test_dir + "sub2"
115
- @sub2_test_dir.mkpath
116
-
117
- @no_load_sub2_test_case7 = @sub2_test_dir + "case7.rb"
118
- @sub2_test_case8 = @sub2_test_dir + "test_case8.rb"
119
- @sub2_test_case9 = @sub2_test_dir + "test_case9.rb"
120
-
121
- @no_load_sub2_test_case7.open("w") do |test_case|
122
- test_case.puts(<<-EOT)
123
- module #{@temporary_test_cases_module_name}
124
- class NoLoadSub2TestCase7 < Test::Unit::TestCase
125
- def test7_1
126
- end
127
-
128
- def test7_2
129
- end
130
- end
131
- end
132
- EOT
133
- end
134
-
135
- @sub2_test_case8.open("w") do |test_case|
136
- test_case.puts(<<-EOT)
137
- module #{@temporary_test_cases_module_name}
138
- class Sub2TestCase8 < Test::Unit::TestCase
139
- def test8_1
140
- end
141
-
142
- def test8_2
143
- end
144
- end
145
- end
146
- EOT
147
- end
148
-
149
- @sub2_test_case9.open("w") do |test_case|
150
- test_case.puts(<<-EOT)
151
- module #{@temporary_test_cases_module_name}
152
- class Sub2TestCase9 < Test::Unit::TestCase
153
- def test9
154
- end
155
- end
156
- end
157
- EOT
158
- end
159
- end
160
-
161
- setup
162
- def setup_svn_test_cases
163
- @svn_test_dir = @test_dir + ".svn"
164
- @svn_test_dir.mkpath
165
-
166
- @svn_test_case10 = @svn_test_dir + "test_case10.rb"
167
-
168
- @svn_test_case10.open("w") do |test_case|
169
- test_case.puts(<<-EOT)
170
- module #{@temporary_test_cases_module_name}
171
- class SvnTestCase10 < Test::Unit::TestCase
172
- def test7
173
- end
174
- end
175
- end
176
- EOT
177
- end
178
- end
179
-
180
- setup
181
- def setup_sub_cvs_test_cases
182
- @sub_cvs_test_dir = @sub_test_dir + "CVS"
183
- @sub_cvs_test_dir.mkpath
184
-
185
- @sub_cvs_test_case11 = @sub_cvs_test_dir + "test_case11.rb"
186
-
187
- @sub_cvs_test_case11.open("w") do |test_case|
188
- test_case.puts(<<-EOT)
189
- module #{@temporary_test_cases_module_name}
190
- class SubCVSTestCase11 < Test::Unit::TestCase
191
- def test11
192
- end
193
- end
194
- end
195
- EOT
196
- end
197
- end
198
-
199
- def teardown
200
- @test_dir.rmtree if @test_dir.exist?
201
- ::Object.send(:remove_const, @temporary_test_cases_module_name)
202
- Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
203
- end
204
-
205
- def test_simple_collect
206
- assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
207
- [:suite, {:name => _test_case_name("SubTestCase4")},
208
- [:test, {:name => "test4_1"}],
209
- [:test, {:name => "test4_2"}]],
210
- [:suite, {:name => _test_case_name("SubTestCase6")},
211
- [:test, {:name => "test6"}]]],
212
- @sub_test_dir.to_s)
213
- end
214
-
215
- def test_multilevel_collect
216
- assert_collect([:suite, {:name => "."},
217
- [:suite, {:name => _test_case_name("TestCase1")},
218
- [:test, {:name => "test1_1"}],
219
- [:test, {:name => "test1_2"}]],
220
- [:suite, {:name => _test_case_name("TestCase2")},
221
- [:test, {:name => "test2"}]],
222
- [:suite, {:name => @sub_test_dir.basename.to_s},
223
- [:suite, {:name => _test_case_name("SubTestCase4")},
224
- [:test, {:name => "test4_1"}],
225
- [:test, {:name => "test4_2"}]],
226
- [:suite, {:name => _test_case_name("SubTestCase6")},
227
- [:test, {:name => "test6"}]]],
228
- [:suite, {:name => @sub2_test_dir.basename.to_s},
229
- [:suite, {:name => _test_case_name("Sub2TestCase8")},
230
- [:test, {:name => "test8_1"}],
231
- [:test, {:name => "test8_2"}]],
232
- [:suite, {:name => _test_case_name("Sub2TestCase9")},
233
- [:test, {:name => "test9"}]]]])
234
- end
235
-
236
- def test_collect_file
237
- assert_collect([:suite, {:name => @test_case1.basename.to_s},
238
- [:suite, {:name => _test_case_name("TestCase1")},
239
- [:test, {:name => "test1_1"}],
240
- [:test, {:name => "test1_2"}]]],
241
- @test_case1.to_s)
242
-
243
- assert_collect([:suite, {:name => @no_load_sub_test_case5.basename.to_s},
244
- [:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
245
- [:test, {:name => "test5_1"}],
246
- [:test, {:name => "test5_2"}]]],
247
- @no_load_sub_test_case5.to_s)
248
- end
249
-
250
- def test_nil_pattern
251
- assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
252
- [:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
253
- [:test, {:name => "test5_1"}],
254
- [:test, {:name => "test5_2"}]],
255
- [:suite, {:name => _test_case_name("SubTestCase4")},
256
- [:test, {:name => "test4_1"}],
257
- [:test, {:name => "test4_2"}]],
258
- [:suite, {:name => _test_case_name("SubTestCase6")},
259
- [:test, {:name => "test6"}]]],
260
- @sub_test_dir.to_s) do |collector|
261
- collector.patterns.clear
262
- end
263
- end
264
-
265
- def test_filtering
266
- assert_collect([:suite, {:name => "."},
267
- [:suite, {:name => _test_case_name("TestCase1")},
268
- [:test, {:name => "test1_1"}],
269
- [:test, {:name => "test1_2"}]]]) do |collector|
270
- collector.filter = Proc.new do |test|
271
- not /\Atest1/.match(test.method_name).nil?
272
- end
273
- end
274
- end
275
-
276
- def test_collect_multi
277
- test_dirs = [@sub_test_dir.to_s, @sub2_test_dir.to_s]
278
- assert_collect([:suite, {:name => "[#{test_dirs.join(', ')}]"},
279
- [:suite, {:name => @sub_test_dir.basename.to_s},
280
- [:suite, {:name => _test_case_name("SubTestCase4")},
281
- [:test, {:name => "test4_1"}],
282
- [:test, {:name => "test4_2"}]],
283
- [:suite, {:name => _test_case_name("SubTestCase6")},
284
- [:test, {:name => "test6"}]]],
285
- [:suite, {:name => @sub2_test_dir.basename.to_s},
286
- [:suite, {:name => _test_case_name("Sub2TestCase8")},
287
- [:test, {:name => "test8_1"}],
288
- [:test, {:name => "test8_2"}]],
289
- [:suite, {:name => _test_case_name("Sub2TestCase9")},
290
- [:test, {:name => "test9"}]]]],
291
- *test_dirs)
292
- end
293
-
294
- private
295
- def assert_collect(expected, *collect_args)
296
- keep_required_files do
297
- Dir.chdir(@test_dir.to_s) do
298
- collector = Test::Unit::Collector::Load.new
299
- yield(collector) if block_given?
300
- actual = inspect_test_object(collector.send(:collect, *collect_args))
301
- assert_equal(expected, actual)
302
- end
303
- end
304
- end
305
-
306
- def keep_required_files
307
- required_files = $".dup
308
- yield
309
- ensure
310
- $".replace(required_files)
311
- end
312
-
313
- def _test_case_name(test_case_class_name)
314
- "#{@temporary_test_cases_module_name}::#{test_case_class_name}"
315
- end
316
-
317
- def inspect_test_object(test_object)
318
- return nil if test_object.nil?
319
- case test_object
320
- when Test::Unit::TestSuite
321
- sub_tests = test_object.tests.collect do |test|
322
- inspect_test_object(test)
323
- end.sort_by do |type, attributes, *children|
324
- attributes[:name]
325
- end
326
- [:suite, {:name => test_object.name}, *sub_tests]
327
- when Test::Unit::TestCase
328
- [:test, {:name => test_object.method_name}]
329
- else
330
- raise "unexpected test object: #{test_object.inspect}"
331
- end
332
- end
333
- end
@@ -1,98 +0,0 @@
1
- # Author:: Nathaniel Talbott.
2
- # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
3
- # License:: Ruby license.
4
-
5
- require 'test/unit'
6
- require 'test/unit/collector/objectspace'
7
-
8
- module Test
9
- module Unit
10
- module Collector
11
- class TC_ObjectSpace < TestCase
12
- def setup
13
- @tc1 = Class.new(TestCase) do
14
- def self.name
15
- "tc_1"
16
- end
17
- def test_1
18
- end
19
- def test_2
20
- end
21
- end
22
-
23
- @tc2 = Class.new(TestCase) do
24
- def self.name
25
- "tc_2"
26
- end
27
- def test_0
28
- end
29
- end
30
-
31
- @no_tc = Class.new do
32
- def test_4
33
- end
34
- end
35
-
36
- @object_space = {Class => [@tc1, @tc2, @no_tc], String => ['']}
37
- def @object_space.each_object(type)
38
- self[type].each{|item| yield(item) }
39
- end
40
-
41
- @c = ObjectSpace.new(@object_space)
42
- end
43
-
44
- def full_suite(name=ObjectSpace::NAME)
45
- expected = TestSuite.new(name)
46
- expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1') << @tc1.new('test_2'))
47
- expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
48
- end
49
-
50
- def empty_suite
51
- TestSuite.new(ObjectSpace::NAME)
52
- end
53
-
54
- def test_basic_collection
55
- assert_equal(full_suite("name"), @c.collect("name"))
56
-
57
- @c.filter = []
58
- assert_equal(full_suite("name"), @c.collect("name"))
59
- end
60
-
61
- def test_filtered_collection
62
- @c.filter = proc{false}
63
- assert_equal(empty_suite, @c.collect)
64
-
65
- @c.filter = proc{true}
66
- assert_equal(full_suite, @c.collect)
67
-
68
- @c.filter = proc{nil}
69
- assert_equal(full_suite, @c.collect)
70
-
71
- @c.filter = [proc{false}, proc{true}]
72
- assert_equal(empty_suite, @c.collect)
73
-
74
- @c.filter = [proc{true}, proc{false}]
75
- assert_equal(full_suite, @c.collect)
76
-
77
- @c.filter = [proc{nil}, proc{false}]
78
- assert_equal(empty_suite, @c.collect)
79
-
80
- @c.filter = [proc{nil}, proc{true}]
81
- assert_equal(full_suite, @c.collect)
82
-
83
- expected = TestSuite.new(ObjectSpace::NAME)
84
- expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
85
- expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
86
- @c.filter = proc{|test| ['test_1', 'test_0'].include?(test.method_name)}
87
- assert_equal(expected, @c.collect)
88
-
89
- expected = TestSuite.new(ObjectSpace::NAME)
90
- expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
91
- expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
92
- @c.filter = [proc{|t| t.method_name == 'test_1' ? true : nil}, proc{|t| t.method_name == 'test_0' ? true : nil}, proc{false}]
93
- assert_equal(expected, @c.collect)
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $VERBOSE = true
4
-
5
- base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
6
- lib_dir = File.join(base_dir, "lib")
7
- test_dir = File.join(base_dir, "test")
8
-
9
- $LOAD_PATH.unshift(lib_dir)
10
-
11
- require 'test/unit'
12
-
13
- exit Test::Unit::AutoRunner.run(true, test_dir)
@@ -1,693 +0,0 @@
1
- # Author:: Nathaniel Talbott.
2
- # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
- # License:: Ruby license.
4
-
5
- require 'test/unit'
6
-
7
- module Test
8
- module Unit
9
- class TC_Assertions < TestCase
10
- def check(value, message="")
11
- add_assertion
12
- raise AssertionFailedError.new(message) unless value
13
- end
14
-
15
- def check_assertions(expect_fail, expected_message="",
16
- return_value_expected=false)
17
- @actual_assertion_count = 0
18
- failed = true
19
- actual_message = nil
20
- @catch_assertions = true
21
- return_value = nil
22
- begin
23
- return_value = yield
24
- failed = false
25
- rescue AssertionFailedError => error
26
- actual_message = error.message
27
- end
28
- @catch_assertions = false
29
-
30
- if expect_fail
31
- message = "Should have failed, but didn't"
32
- else
33
- message = "Should not have failed, but did with message\n" +
34
- "<#{actual_message}>"
35
- end
36
- check(expect_fail == failed, message)
37
-
38
- message = "Should have made one assertion but made\n" +
39
- "<#{@actual_assertion_count}>"
40
- check(1 == @actual_assertion_count, message)
41
-
42
- if expect_fail
43
- case expected_message
44
- when String
45
- check(actual_message == expected_message,
46
- "Should have the correct message.\n" +
47
- "<#{expected_message.inspect}> expected but was\n" +
48
- "<#{actual_message.inspect}>")
49
- when Regexp
50
- check(actual_message =~ expected_message,
51
- "The message should match correctly.\n" +
52
- "</#{expected_message.source}/> expected to match\n" +
53
- "<#{actual_message.inspect}>")
54
- else
55
- check(false,
56
- "Incorrect expected message type in assert_nothing_failed")
57
- end
58
- else
59
- if return_value_expected
60
- check(!return_value.nil?, "Should return a value")
61
- else
62
- check(return_value.nil?,
63
- "Should not return a value but returned <#{return_value}>")
64
- end
65
- end
66
-
67
- return_value
68
- end
69
-
70
- def check_nothing_fails(return_value_expected=false, &proc)
71
- check_assertions(false, "", return_value_expected, &proc)
72
- end
73
-
74
- def check_fails(expected_message="", &proc)
75
- check_assertions(true, expected_message, &proc)
76
- end
77
-
78
- def inspect_tag(tag)
79
- begin
80
- throw tag
81
- rescue NameError
82
- tag.to_s.inspect
83
- rescue ArgumentError
84
- tag.inspect
85
- end
86
- end
87
-
88
- def test_assert_block
89
- check_nothing_fails {
90
- assert_block {true}
91
- }
92
- check_nothing_fails {
93
- assert_block("successful assert_block") {true}
94
- }
95
- check_nothing_fails {
96
- assert_block("successful assert_block") {true}
97
- }
98
- check_fails("assert_block failed.") {
99
- assert_block {false}
100
- }
101
- check_fails("failed assert_block") {
102
- assert_block("failed assert_block") {false}
103
- }
104
- end
105
-
106
- def test_assert
107
- check_nothing_fails{assert("a")}
108
- check_nothing_fails{assert(true)}
109
- check_nothing_fails{assert(true, "successful assert")}
110
- check_fails("<nil> is not true."){assert(nil)}
111
- check_fails("<false> is not true."){assert(false)}
112
- check_fails("failed assert.\n<false> is not true."){assert(false, "failed assert")}
113
- end
114
-
115
- def test_assert_equal
116
- check_nothing_fails {
117
- assert_equal("string1", "string1")
118
- }
119
- check_nothing_fails {
120
- assert_equal( "string1", "string1", "successful assert_equal")
121
- }
122
- check_nothing_fails {
123
- assert_equal("string1", "string1", "successful assert_equal")
124
- }
125
-
126
- message = <<-EOM.chomp
127
- <"string1"> expected but was
128
- <"string2">.
129
-
130
- diff:
131
- - string1
132
- ? ^
133
- + string2
134
- ? ^
135
- EOM
136
- check_fails(message) {
137
- assert_equal("string1", "string2")
138
- }
139
-
140
- message = <<-EOM.chomp
141
- failed assert_equal.
142
- <"string1"> expected but was
143
- <"string2">.
144
-
145
- diff:
146
- - string1
147
- ? ^
148
- + string2
149
- ? ^
150
- EOM
151
- check_fails(message) {
152
- assert_equal("string1", "string2", "failed assert_equal")
153
- }
154
-
155
- message = <<-EOM.chomp
156
- <"111111"> expected but was
157
- <111111>.
158
-
159
- diff:
160
- - "111111"
161
- ? - -
162
- + 111111
163
- EOM
164
- check_fails(message) do
165
- assert_equal("111111", 111111)
166
- end
167
- end
168
-
169
- def test_assert_equal_for_too_small_difference
170
- message = <<-EOM.chomp
171
- <1> expected but was
172
- <2>.
173
- EOM
174
- check_fails(message) do
175
- assert_equal(1, 2)
176
- end
177
- end
178
-
179
- def test_assert_equal_for_same_inspected_objects
180
- now = Time.now
181
- now_without_usec = Time.at(now.to_i)
182
- message = <<-EOM.chomp
183
- <#{now.inspect}> expected but was
184
- <#{now.inspect}>.
185
- EOM
186
- check_fails(message) do
187
- assert_equal(now, now_without_usec)
188
- end
189
- end
190
-
191
- def test_assert_equal_with_multi_lines_result
192
- message = <<-EOM.chomp
193
- <#{"a\nb".inspect}> expected but was
194
- <#{"x".inspect}>.
195
-
196
- diff:
197
- + x
198
- - a
199
- - b
200
- EOM
201
- check_fails(message) do
202
- assert_equal("a\nb", "x")
203
- end
204
- end
205
-
206
- def test_assert_raise
207
- return_value = nil
208
- check_nothing_fails(true) {
209
- return_value = assert_raise(RuntimeError) {
210
- raise "Error"
211
- }
212
- }
213
- check(return_value.kind_of?(Exception), "Should have returned the exception from a successful assert_raise")
214
- check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
215
- check_nothing_fails(true) {
216
- assert_raise(ArgumentError, "successful assert_raise") {
217
- raise ArgumentError.new("Error")
218
- }
219
- }
220
- check_nothing_fails(true) {
221
- assert_raise(RuntimeError) {
222
- raise "Error"
223
- }
224
- }
225
- check_nothing_fails(true) {
226
- assert_raise(RuntimeError, "successful assert_raise") {
227
- raise "Error"
228
- }
229
- }
230
- check_fails("<RuntimeError> exception expected but none was thrown.") {
231
- assert_raise(RuntimeError) {
232
- 1 + 1
233
- }
234
- }
235
- check_fails(%r{\Afailed assert_raise.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
236
- assert_raise(ArgumentError, "failed assert_raise") {
237
- raise "Error"
238
- }
239
- }
240
- check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
241
- assert_nothing_raised(Object) {
242
- 1 + 1
243
- }
244
- }
245
-
246
- exceptions = [ArgumentError, TypeError]
247
- modules = [Math, Comparable]
248
- rescues = exceptions + modules
249
- exceptions.each do |exc|
250
- check_nothing_fails(true) {
251
- return_value = assert_raise(*rescues) {
252
- raise exc, "Error"
253
- }
254
- }
255
- check(return_value.instance_of?(exc), "Should have returned #{exc} but was #{return_value.class}")
256
- check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
257
- end
258
- modules.each do |mod|
259
- check_nothing_fails(true) {
260
- return_value = assert_raise(*rescues) {
261
- raise Exception.new("Error").extend(mod)
262
- }
263
- }
264
- check(mod === return_value, "Should have returned #{mod}")
265
- check(return_value.message == "Error", "Should have returned the correct exception from a successful assert_raise")
266
- end
267
- check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception expected but none was thrown.") {
268
- assert_raise(*rescues) {
269
- 1 + 1
270
- }
271
- }
272
- check_fails(%r{\Afailed assert_raise.
273
- <\[ArgumentError, TypeError\]> exception expected but was
274
- Class: <RuntimeError>
275
- Message: <"Error">
276
- ---Backtrace---
277
- .+
278
- ---------------\Z}m) {
279
- assert_raise(ArgumentError, TypeError, "failed assert_raise") {
280
- raise "Error"
281
- }
282
- }
283
- end
284
-
285
- def test_assert_instance_of
286
- check_nothing_fails {
287
- assert_instance_of(String, "string")
288
- }
289
- check_nothing_fails {
290
- assert_instance_of(String, "string", "successful assert_instance_of")
291
- }
292
- check_nothing_fails {
293
- assert_instance_of(String, "string", "successful assert_instance_of")
294
- }
295
- check_fails(%Q{<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
296
- assert_instance_of(Hash, "string")
297
- }
298
- check_fails(%Q{failed assert_instance_of.\n<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
299
- assert_instance_of(Hash, "string", "failed assert_instance_of")
300
- }
301
- end
302
-
303
- def test_assert_nil
304
- check_nothing_fails {
305
- assert_nil(nil)
306
- }
307
- check_nothing_fails {
308
- assert_nil(nil, "successful assert_nil")
309
- }
310
- check_nothing_fails {
311
- assert_nil(nil, "successful assert_nil")
312
- }
313
- check_fails(%Q{<"string"> expected to be nil.}) {
314
- assert_nil("string")
315
- }
316
- check_fails(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
317
- assert_nil("string", "failed assert_nil")
318
- }
319
- end
320
-
321
- def test_assert_not_nil
322
- check_nothing_fails{assert_not_nil(false)}
323
- check_nothing_fails{assert_not_nil(false, "message")}
324
- check_fails("<nil> expected to not be nil."){assert_not_nil(nil)}
325
- check_fails("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
326
- end
327
-
328
- def test_assert_kind_of
329
- check_nothing_fails {
330
- assert_kind_of(Module, Array)
331
- }
332
- check_nothing_fails {
333
- assert_kind_of(Object, "string", "successful assert_kind_of")
334
- }
335
- check_nothing_fails {
336
- assert_kind_of(Object, "string", "successful assert_kind_of")
337
- }
338
- check_nothing_fails {
339
- assert_kind_of(Comparable, 1)
340
- }
341
- check_fails(%Q{<"string">\nexpected to be kind_of?\n<Class> but was\n<String>.}) {
342
- assert_kind_of(Class, "string")
343
- }
344
- check_fails(%Q{failed assert_kind_of.\n<"string">\nexpected to be kind_of?\n<Class> but was\n<String>.}) {
345
- assert_kind_of(Class, "string", "failed assert_kind_of")
346
- }
347
- end
348
-
349
- def test_assert_match
350
- check_nothing_fails {
351
- assert_match(/strin./, "string")
352
- }
353
- check_nothing_fails {
354
- assert_match("strin", "string")
355
- }
356
- check_nothing_fails {
357
- assert_match(/strin./, "string", "successful assert_match")
358
- }
359
- check_nothing_fails {
360
- assert_match(/strin./, "string", "successful assert_match")
361
- }
362
- check_fails(%Q{<"string"> expected to be =~\n</slin./>.}) {
363
- assert_match(/slin./, "string")
364
- }
365
- check_fails(%Q{<"string"> expected to be =~\n</strin\\./>.}) {
366
- assert_match("strin.", "string")
367
- }
368
- check_fails(%Q{failed assert_match.\n<"string"> expected to be =~\n</slin./>.}) {
369
- assert_match(/slin./, "string", "failed assert_match")
370
- }
371
- end
372
-
373
- def test_assert_same
374
- thing = "thing"
375
- check_nothing_fails {
376
- assert_same(thing, thing)
377
- }
378
- check_nothing_fails {
379
- assert_same(thing, thing, "successful assert_same")
380
- }
381
- check_nothing_fails {
382
- assert_same(thing, thing, "successful assert_same")
383
- }
384
- thing2 = "thing"
385
- check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
386
- assert_same(thing, thing2)
387
- }
388
- check_fails(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
389
- assert_same(thing, thing2, "failed assert_same")
390
- }
391
- end
392
-
393
- def test_assert_nothing_raised
394
- check_nothing_fails {
395
- assert_nothing_raised {
396
- 1 + 1
397
- }
398
- }
399
- check_nothing_fails {
400
- assert_nothing_raised("successful assert_nothing_raised") {
401
- 1 + 1
402
- }
403
- }
404
- check_nothing_fails {
405
- assert_nothing_raised("successful assert_nothing_raised") {
406
- 1 + 1
407
- }
408
- }
409
- check_nothing_fails {
410
- begin
411
- assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
412
- raise ZeroDivisionError.new("ArgumentError")
413
- }
414
- rescue ZeroDivisionError
415
- end
416
- }
417
- check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
418
- assert_nothing_raised(Object) {
419
- 1 + 1
420
- }
421
- }
422
- check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
423
- assert_nothing_raised {
424
- raise "Error"
425
- }
426
- }
427
- check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
428
- assert_nothing_raised("failed assert_nothing_raised") {
429
- raise "Error"
430
- }
431
- }
432
- check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
433
- assert_nothing_raised(StandardError, RuntimeError) {
434
- raise "Error"
435
- }
436
- }
437
- check_fails("Failure.") do
438
- assert_nothing_raised do
439
- flunk("Failure")
440
- end
441
- end
442
- end
443
-
444
- def test_flunk
445
- check_fails("Flunked.") {
446
- flunk
447
- }
448
- check_fails("flunk message.") {
449
- flunk("flunk message")
450
- }
451
- end
452
-
453
- def test_assert_not_same
454
- thing = "thing"
455
- thing2 = "thing"
456
- check_nothing_fails {
457
- assert_not_same(thing, thing2)
458
- }
459
- check_nothing_fails {
460
- assert_not_same(thing, thing2, "message")
461
- }
462
- check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
463
- assert_not_same(thing, thing)
464
- }
465
- check_fails(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
466
- assert_not_same(thing, thing, "message")
467
- }
468
- end
469
-
470
- def test_assert_not_equal
471
- check_nothing_fails {
472
- assert_not_equal("string1", "string2")
473
- }
474
- check_nothing_fails {
475
- assert_not_equal("string1", "string2", "message")
476
- }
477
- check_fails(%Q{<"string"> expected to be != to\n<"string">.}) {
478
- assert_not_equal("string", "string")
479
- }
480
- check_fails(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
481
- assert_not_equal("string", "string", "message")
482
- }
483
- end
484
-
485
- def test_assert_no_match
486
- check_nothing_fails{assert_no_match(/sling/, "string")}
487
- check_nothing_fails{assert_no_match(/sling/, "string", "message")}
488
- check_fails(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be an instance of\n<Regexp> but was\n<String>.}) do
489
- assert_no_match("asdf", "asdf")
490
- end
491
- check_fails(%Q{</string/> expected to not match\n<"string">.}) do
492
- assert_no_match(/string/, "string")
493
- end
494
- check_fails(%Q{message.\n</string/> expected to not match\n<"string">.}) do
495
- assert_no_match(/string/, "string", "message")
496
- end
497
- end
498
-
499
- def test_assert_throws
500
- check_nothing_fails do
501
- assert_throws(:thing, "message") do
502
- throw :thing
503
- end
504
- end
505
-
506
- tag = :thing2
507
- check_fails("message.\n" +
508
- "<:thing> expected to be thrown but\n" +
509
- "<#{inspect_tag(tag)}> was thrown.") do
510
- assert_throws(:thing, "message") do
511
- throw :thing2
512
- end
513
- end
514
- check_fails("message.\n" +
515
- "<:thing> should have been thrown.") do
516
- assert_throws(:thing, "message") do
517
- 1 + 1
518
- end
519
- end
520
- end
521
-
522
- def test_assert_nothing_thrown
523
- check_nothing_fails do
524
- assert_nothing_thrown("message") do
525
- 1 + 1
526
- end
527
- end
528
-
529
- tag = :thing
530
- inspected = inspect_tag(tag)
531
- check_fails("message.\n" +
532
- "<#{inspected}> was thrown when nothing was expected.") do
533
- assert_nothing_thrown("message") do
534
- throw tag
535
- end
536
- end
537
- end
538
-
539
- def test_assert_operator
540
- check_nothing_fails {
541
- assert_operator("thing", :==, "thing", "message")
542
- }
543
- check_fails(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
544
- assert_operator("thing", 0.15, "thing")
545
- end
546
- check_fails(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
547
- assert_operator("thing1", :==, "thing2", "message")
548
- }
549
- end
550
-
551
- def test_assert_respond_to
552
- check_nothing_fails {
553
- assert_respond_to("thing", :to_s, "message")
554
- }
555
- check_nothing_fails {
556
- assert_respond_to("thing", "to_s", "message")
557
- }
558
- check_fails("<0.15>\ngiven as the method name argument to #assert_respond_to must be a Symbol or #respond_to?(:to_str).") {
559
- assert_respond_to("thing", 0.15)
560
- }
561
- check_fails("message.\n<:symbol>\nof type <Symbol>\nexpected to respond_to?<:non_existent>.") {
562
- assert_respond_to(:symbol, :non_existent, "message")
563
- }
564
- end
565
-
566
- def test_assert_in_delta
567
- check_nothing_fails {
568
- assert_in_delta(1.4, 1.4, 0)
569
- }
570
- check_nothing_fails {
571
- assert_in_delta(0.5, 0.4, 0.1, "message")
572
- }
573
- check_nothing_fails {
574
- float_thing = Object.new
575
- def float_thing.to_f
576
- 0.2
577
- end
578
- assert_in_delta(0.1, float_thing, 0.1)
579
- }
580
- check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
581
- assert_in_delta(0.5, 0.4, 0.05, "message")
582
- }
583
- check_fails(%r{The arguments must respond to to_f; the first float did not\.\n<.+>\nof type <Object>\nexpected to respond_to\?<:to_f>.}) {
584
- assert_in_delta(Object.new, 0.4, 0.1)
585
- }
586
- check_fails("The delta should not be negative.\n<-0.1> expected to be\n>=\n<0.0>.") {
587
- assert_in_delta(0.5, 0.4, -0.1, "message")
588
- }
589
- end
590
-
591
- def test_assert_send
592
- object = Object.new
593
- class << object
594
- private
595
- def return_argument(argument, bogus)
596
- return argument
597
- end
598
- end
599
- check_nothing_fails {
600
- assert_send([object, :return_argument, true, "bogus"], "message")
601
- }
602
- check_fails(%r{\Amessage\.\n<.+> expected to respond to\n<return_argument\(\[false, "bogus"\]\)> with a true value.\Z}) {
603
- assert_send([object, :return_argument, false, "bogus"], "message")
604
- }
605
- end
606
-
607
- def test_condition_invariant
608
- object = Object.new
609
- def object.inspect
610
- @changed = true
611
- end
612
- def object.==(other)
613
- @changed ||= false
614
- return (!@changed)
615
- end
616
- check_nothing_fails do
617
- assert_equal(object, object, "message")
618
- end
619
- end
620
-
621
- def test_assert_boolean
622
- check_nothing_fails do
623
- assert_boolean(true)
624
- end
625
- check_nothing_fails do
626
- assert_boolean(false)
627
- end
628
-
629
- check_fails("<true> or <false> expected but was\n<1>") do
630
- assert_boolean(1)
631
- end
632
-
633
- check_fails("<true> or <false> expected but was\n<nil>") do
634
- assert_boolean(nil)
635
- end
636
-
637
- check_fails("message.\n<true> or <false> expected but was\n<\"XXX\">") do
638
- assert_boolean("XXX", "message")
639
- end
640
- end
641
-
642
- def test_assert_true
643
- check_nothing_fails do
644
- assert_true(true)
645
- end
646
-
647
- check_fails("<true> expected but was\n<false>") do
648
- assert_true(false)
649
- end
650
-
651
- check_fails("<true> expected but was\n<1>") do
652
- assert_true(1)
653
- end
654
-
655
- check_fails("message.\n<true> expected but was\n<nil>") do
656
- assert_true(nil, "message")
657
- end
658
- end
659
-
660
- def test_assert_false
661
- check_nothing_fails do
662
- assert_false(false)
663
- end
664
-
665
- check_fails("<false> expected but was\n<true>") do
666
- assert_false(true)
667
- end
668
-
669
- check_fails("<false> expected but was\n<nil>") do
670
- assert_false(nil)
671
- end
672
-
673
- check_fails("message.\n<false> expected but was\n<:false>") do
674
- assert_false(:false, "message")
675
- end
676
- end
677
-
678
- def add_failure(message, location=caller)
679
- unless @catch_assertions
680
- super
681
- end
682
- end
683
-
684
- def add_assertion
685
- if @catch_assertions
686
- @actual_assertion_count += 1
687
- else
688
- super
689
- end
690
- end
691
- end
692
- end
693
- end