glib2 0.90.8 → 0.90.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/ChangeLog +44 -0
  2. data/Rakefile +1 -0
  3. data/ext/glib2/rbglib.h +1 -1
  4. data/ext/glib2/rbglib_iochannel.c +15 -6
  5. data/ext/glib2/rbgobj_signal.c +1 -1
  6. data/ext/glib2/rbgobject.h +1 -1
  7. data/lib/gnome2-raketask.rb +4 -2
  8. data/lib/mkmf-gnome2.rb +47 -23
  9. data/test/glib-test-init.rb +1 -3
  10. metadata +20 -121
  11. data/test-unit/COPYING +0 -56
  12. data/test-unit/GPL +0 -340
  13. data/test-unit/History.txt +0 -279
  14. data/test-unit/Manifest.txt +0 -110
  15. data/test-unit/PSFL +0 -271
  16. data/test-unit/README.txt +0 -75
  17. data/test-unit/Rakefile +0 -53
  18. data/test-unit/TODO +0 -5
  19. data/test-unit/bin/testrb +0 -5
  20. data/test-unit/html/bar.png +0 -0
  21. data/test-unit/html/bar.svg +0 -153
  22. data/test-unit/html/developer.png +0 -0
  23. data/test-unit/html/developer.svg +0 -469
  24. data/test-unit/html/famfamfam-logo.png +0 -0
  25. data/test-unit/html/favicon.ico +0 -0
  26. data/test-unit/html/favicon.png +0 -0
  27. data/test-unit/html/favicon.svg +0 -82
  28. data/test-unit/html/heading-mark.png +0 -0
  29. data/test-unit/html/heading-mark.svg +0 -393
  30. data/test-unit/html/index.html +0 -285
  31. data/test-unit/html/index.html.ja +0 -299
  32. data/test-unit/html/install.png +0 -0
  33. data/test-unit/html/install.svg +0 -636
  34. data/test-unit/html/jp.png +0 -0
  35. data/test-unit/html/kinotan-failure.png +0 -0
  36. data/test-unit/html/kinotan-pass.png +0 -0
  37. data/test-unit/html/logo.png +0 -0
  38. data/test-unit/html/logo.svg +0 -483
  39. data/test-unit/html/reference.png +0 -0
  40. data/test-unit/html/rubyforge.png +0 -0
  41. data/test-unit/html/tango-logo.png +0 -0
  42. data/test-unit/html/test-unit.css +0 -339
  43. data/test-unit/html/tutorial.png +0 -0
  44. data/test-unit/html/tutorial.svg +0 -559
  45. data/test-unit/html/us.png +0 -0
  46. data/test-unit/images/color-diff.png +0 -0
  47. data/test-unit/lib/test/unit.rb +0 -328
  48. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  49. data/test-unit/lib/test/unit/assertions.rb +0 -1792
  50. data/test-unit/lib/test/unit/attribute.rb +0 -125
  51. data/test-unit/lib/test/unit/autorunner.rb +0 -415
  52. data/test-unit/lib/test/unit/collector.rb +0 -38
  53. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  54. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  55. data/test-unit/lib/test/unit/collector/load.rb +0 -187
  56. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  57. data/test-unit/lib/test/unit/collector/xml.rb +0 -250
  58. data/test-unit/lib/test/unit/color-scheme.rb +0 -106
  59. data/test-unit/lib/test/unit/color.rb +0 -96
  60. data/test-unit/lib/test/unit/diff.rb +0 -740
  61. data/test-unit/lib/test/unit/error.rb +0 -131
  62. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  63. data/test-unit/lib/test/unit/failure.rb +0 -136
  64. data/test-unit/lib/test/unit/fixture.rb +0 -185
  65. data/test-unit/lib/test/unit/notification.rb +0 -129
  66. data/test-unit/lib/test/unit/omission.rb +0 -191
  67. data/test-unit/lib/test/unit/pending.rb +0 -150
  68. data/test-unit/lib/test/unit/priority.rb +0 -180
  69. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  70. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  71. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  72. data/test-unit/lib/test/unit/runner/xml.rb +0 -15
  73. data/test-unit/lib/test/unit/testcase.rb +0 -515
  74. data/test-unit/lib/test/unit/testresult.rb +0 -125
  75. data/test-unit/lib/test/unit/testsuite.rb +0 -134
  76. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  77. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -467
  78. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  79. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -82
  80. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -53
  81. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -86
  82. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  83. data/test-unit/lib/test/unit/ui/xml/testrunner.rb +0 -224
  84. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -42
  85. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  86. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  87. data/test-unit/lib/test/unit/util/output.rb +0 -31
  88. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  89. data/test-unit/lib/test/unit/version.rb +0 -7
  90. data/test-unit/sample/adder.rb +0 -13
  91. data/test-unit/sample/subtracter.rb +0 -12
  92. data/test-unit/sample/test_adder.rb +0 -20
  93. data/test-unit/sample/test_subtracter.rb +0 -20
  94. data/test-unit/sample/test_user.rb +0 -23
  95. data/test-unit/test/collector/test-descendant.rb +0 -133
  96. data/test-unit/test/collector/test-load.rb +0 -442
  97. data/test-unit/test/collector/test_dir.rb +0 -406
  98. data/test-unit/test/collector/test_objectspace.rb +0 -100
  99. data/test-unit/test/run-test.rb +0 -22
  100. data/test-unit/test/test-assertions.rb +0 -1849
  101. data/test-unit/test/test-attribute.rb +0 -86
  102. data/test-unit/test/test-color-scheme.rb +0 -69
  103. data/test-unit/test/test-color.rb +0 -47
  104. data/test-unit/test/test-diff.rb +0 -518
  105. data/test-unit/test/test-emacs-runner.rb +0 -60
  106. data/test-unit/test/test-fixture.rb +0 -324
  107. data/test-unit/test/test-notification.rb +0 -33
  108. data/test-unit/test/test-omission.rb +0 -81
  109. data/test-unit/test/test-pending.rb +0 -70
  110. data/test-unit/test/test-priority.rb +0 -119
  111. data/test-unit/test/test-testcase.rb +0 -569
  112. data/test-unit/test/test_error.rb +0 -26
  113. data/test-unit/test/test_failure.rb +0 -33
  114. data/test-unit/test/test_testresult.rb +0 -113
  115. data/test-unit/test/test_testsuite.rb +0 -137
  116. data/test-unit/test/testunit-test-util.rb +0 -14
  117. data/test-unit/test/ui/test_tap.rb +0 -33
  118. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  119. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  120. data/test-unit/test/util/test-output.rb +0 -11
  121. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  122. data/test-unit/test/util/test_observable.rb +0 -102
  123. data/test-unit/test/util/test_procwrapper.rb +0 -36
@@ -1,180 +0,0 @@
1
- module Test
2
- module Unit
3
- module Priority
4
- class << self
5
- def included(base)
6
- base.extend(ClassMethods)
7
-
8
- base.class_eval do
9
- setup :priority_setup, :before => :prepend
10
- teardown :priority_teardown, :after => :append
11
- end
12
- end
13
-
14
- @@enabled = false
15
- def enabled?
16
- @@enabled
17
- end
18
-
19
- def enable
20
- require "fileutils"
21
- require "tmpdir"
22
- @@enabled = true
23
- end
24
-
25
- def disable
26
- @@enabled = false
27
- end
28
-
29
- @@default = :normal
30
- def default
31
- @@default || :normal
32
- end
33
-
34
- def default=(default)
35
- @@default = default
36
- end
37
-
38
- def available_values
39
- Checker.available_priorities
40
- end
41
- end
42
-
43
- class Checker
44
- class << self
45
- def have_priority?(name)
46
- singleton_class = (class << self; self; end)
47
- singleton_class.method_defined?(priority_check_method_name(name))
48
- end
49
-
50
- def need_to_run?(test)
51
- priority = test[:priority] || Priority.default
52
- if have_priority?(priority)
53
- send(priority_check_method_name(priority), test)
54
- else
55
- true
56
- end
57
- end
58
-
59
- def available_priorities
60
- methods(false).collect do |name|
61
- /\Arun_priority_(.+)\?\z/ =~ name.to_s
62
- $1
63
- end.compact
64
- end
65
-
66
- def run_priority_must?(test)
67
- true
68
- end
69
-
70
- def run_priority_important?(test)
71
- rand > 0.1
72
- end
73
-
74
- def run_priority_high?(test)
75
- rand > 0.3
76
- end
77
-
78
- def run_priority_normal?(test)
79
- rand > 0.5
80
- end
81
-
82
- def run_priority_low?(test)
83
- rand > 0.75
84
- end
85
-
86
- def run_priority_never?(test)
87
- false
88
- end
89
-
90
- private
91
- def priority_check_method_name(priority_name)
92
- "run_priority_#{priority_name}?"
93
- end
94
- end
95
-
96
- attr_reader :test
97
- def initialize(test)
98
- @test = test
99
- end
100
-
101
- def setup
102
- FileUtils.rm_f(passed_file)
103
- end
104
-
105
- def teardown
106
- if @test.send(:passed?)
107
- FileUtils.touch(passed_file)
108
- else
109
- FileUtils.rm_f(passed_file)
110
- end
111
- end
112
-
113
- def need_to_run?
114
- !previous_test_success? or self.class.need_to_run?(@test)
115
- end
116
-
117
- private
118
- def previous_test_success?
119
- File.exist?(passed_file)
120
- end
121
-
122
- def result_dir
123
- components = [".test-result",
124
- @test.class.name || "AnonymousTestCase",
125
- escaped_method_name]
126
- parent_directories = [File.dirname($0), Dir.pwd]
127
- if Process.respond_to?(:uid)
128
- parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
129
- end
130
- parent_directories.each do |parent_directory|
131
- dir = File.expand_path(File.join(parent_directory, *components))
132
- begin
133
- FileUtils.mkdir_p(dir)
134
- return dir
135
- rescue Errno::EACCES
136
- end
137
- end
138
-
139
- raise Errno::EACCES, parent_directories.join(", ")
140
- end
141
-
142
- def passed_file
143
- File.join(result_dir, "passed")
144
- end
145
-
146
- def escaped_method_name
147
- @test.method_name.to_s.gsub(/[!?=]$/) do |matched|
148
- case matched
149
- when "!"
150
- ".destructive"
151
- when "?"
152
- ".predicate"
153
- when "="
154
- ".equal"
155
- end
156
- end
157
- end
158
- end
159
-
160
- module ClassMethods
161
- def priority(name, *tests)
162
- unless Checker.have_priority?(name)
163
- raise ArgumentError, "unknown priority: #{name}"
164
- end
165
- attribute(:priority, name, {:keep => true}, *tests)
166
- end
167
- end
168
-
169
- def priority_setup
170
- return unless Priority.enabled?
171
- Checker.new(self).setup
172
- end
173
-
174
- def priority_teardown
175
- return unless Priority.enabled?
176
- Checker.new(self).teardown
177
- end
178
- end
179
- end
180
- end
@@ -1,52 +0,0 @@
1
- module Test
2
- module Unit
3
- AutoRunner.register_runner(:console) do |auto_runner|
4
- require 'test/unit/ui/console/testrunner'
5
- Test::Unit::UI::Console::TestRunner
6
- end
7
-
8
- AutoRunner.setup_option do |auto_runner, opts|
9
- require 'test/unit/ui/console/outputlevel'
10
-
11
- output_levels = [
12
- [:silent, UI::Console::OutputLevel::SILENT],
13
- [:progress, UI::Console::OutputLevel::PROGRESS_ONLY],
14
- [:normal, UI::Console::OutputLevel::NORMAL],
15
- [:verbose, UI::Console::OutputLevel::VERBOSE],
16
- ]
17
- opts.on('-v', '--verbose=[LEVEL]', output_levels,
18
- "Set the output level (default is verbose).",
19
- "(#{auto_runner.keyword_display(output_levels)})") do |level|
20
- level ||= output_levels.assoc(:verbose)[1]
21
- auto_runner.runner_options[:output_level] = level
22
- end
23
-
24
- use_color_options = [
25
- [:auto, :auto],
26
- ["-", false],
27
- ["no", false],
28
- ["false", false],
29
- ["+", true],
30
- ["yes", true],
31
- ["true", true],
32
- ]
33
- opts.on("--[no-]use-color=[auto]", use_color_options,
34
- "Uses color output",
35
- "(default is auto)") do |use_color|
36
- case use_color
37
- when nil
38
- use_color = true
39
- when :auto
40
- use_color = nil
41
- end
42
- auto_runner.runner_options[:use_color] = use_color
43
- end
44
-
45
- opts.on("--progress-row-max=MAX", Integer,
46
- "Uses MAX as max terminal width for progress mark",
47
- "(default is auto)") do |max|
48
- auto_runner.runner_options[:progress_row_max] = max
49
- end
50
- end
51
- end
52
- end
@@ -1,8 +0,0 @@
1
- module Test
2
- module Unit
3
- AutoRunner.register_runner(:emacs) do |auto_runner|
4
- require 'test/unit/ui/emacs/testrunner'
5
- Test::Unit::UI::Emacs::TestRunner
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Test
2
- module Unit
3
- AutoRunner.register_runner(:tap) do |auto_runner|
4
- require 'test/unit/ui/tap/testrunner'
5
- Test::Unit::UI::Tap::TestRunner
6
- end
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- module Test
2
- module Unit
3
- AutoRunner.register_runner(:xml) do |auto_runner|
4
- require 'test/unit/ui/xml/testrunner'
5
- Test::Unit::UI::XML::TestRunner
6
- end
7
-
8
- AutoRunner.setup_option do |auto_runner, opts|
9
- opts.on("--output-file-descriptor=FD", Integer,
10
- "Outputs to file descriptor FD") do |fd|
11
- auto_runner.runner_options[:output_file_descriptor] = fd
12
- end
13
- end
14
- end
15
- end
@@ -1,515 +0,0 @@
1
- #--
2
- #
3
- # Author:: Nathaniel Talbott.
4
- # Copyright::
5
- # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
- # * Copyright (c) 2008-2009 Kouhei Sutou <tt><kou@clear-code.com></tt>
7
- # License:: Ruby license.
8
-
9
- require 'test/unit/attribute'
10
- require 'test/unit/fixture'
11
- require 'test/unit/exceptionhandler'
12
- require 'test/unit/assertions'
13
- require 'test/unit/failure'
14
- require 'test/unit/error'
15
- require 'test/unit/pending'
16
- require 'test/unit/omission'
17
- require 'test/unit/notification'
18
- require 'test/unit/priority'
19
- require 'test/unit/testsuite'
20
- require 'test/unit/assertionfailederror'
21
- require 'test/unit/util/backtracefilter'
22
- require 'test/unit/util/output'
23
- require 'test/unit/util/method-owner-finder'
24
-
25
- module Test
26
- module Unit
27
-
28
- # Ties everything together. If you subclass and add your own
29
- # test methods, it takes care of making them into tests and
30
- # wrapping those tests into a suite. It also does the
31
- # nitty-gritty of actually running an individual test and
32
- # collecting its results into a Test::Unit::TestResult object.
33
- #
34
- # You can run two hooks before/after a TestCase run.
35
- #
36
- # Example:
37
- # class TestMyClass < Test::Unit::TestCase
38
- # class << self
39
- # def startup
40
- # ...
41
- # end
42
- #
43
- # def shutdown
44
- # ...
45
- # end
46
- # end
47
- #
48
- # def setup
49
- # ...
50
- # end
51
- #
52
- # def teardown
53
- # ...
54
- # end
55
- #
56
- # def test_my_method1
57
- # ...
58
- # end
59
- #
60
- # def test_my_method2
61
- # ...
62
- # end
63
- # end
64
- #
65
- # Here is a call order:
66
- # * startup
67
- # * setup
68
- # * test_my_method1
69
- # * teardown
70
- # * setup
71
- # * test_my_method2
72
- # * teardown
73
- # * shutdown
74
- class TestCase
75
- include Attribute
76
- include Fixture
77
- include ExceptionHandler
78
- include ErrorHandler
79
- include FailureHandler
80
- include TestCasePendingSupport
81
- include TestCaseOmissionSupport
82
- include TestCaseNotificationSupport
83
- include Priority
84
- include Assertions
85
- include Util::BacktraceFilter
86
- include Util::Output
87
-
88
- STARTED = name + "::STARTED" # :nodoc:
89
- FINISHED = name + "::FINISHED" # :nodoc:
90
- STARTED_OBJECT = name + "::STARTED::OBJECT" # :nodoc:
91
- FINISHED_OBJECT = name + "::FINISHED::OBJECT" # :nodoc:
92
-
93
- DESCENDANTS = [] # :nodoc:
94
- AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
95
-
96
- class << self
97
- def inherited(sub_class) # :nodoc:
98
- DESCENDANTS << sub_class
99
- end
100
-
101
- @@added_methods = {}
102
- def method_added(name) # :nodoc:
103
- super
104
- added_methods = (@@added_methods[self] ||= [])
105
- stringified_name = name.to_s
106
- if added_methods.include?(stringified_name)
107
- attribute(:redefined, true, {}, stringified_name)
108
- end
109
- added_methods << stringified_name
110
- end
111
-
112
- # Rolls up all of the test* methods in the fixture into
113
- # one suite, creating a new instance of the fixture for
114
- # each method.
115
- def suite
116
- suite = TestSuite.new(name, self)
117
- collect_test_names.each do |test|
118
- catch(:invalid_test) do
119
- suite << new(test)
120
- end
121
- end
122
- if suite.empty?
123
- catch(:invalid_test) do
124
- suite << new("default_test")
125
- end
126
- end
127
- suite
128
- end
129
-
130
- # Called before every test case runs. Can be used
131
- # to set up fixture information used in test case
132
- # scope.
133
- #
134
- # Here is an example test case:
135
- # class TestMyClass < Test::Unit::TestCase
136
- # class << self
137
- # def startup
138
- # ...
139
- # end
140
- # end
141
- #
142
- # def setup
143
- # ...
144
- # end
145
- #
146
- # def test_my_class1
147
- # ...
148
- # end
149
- #
150
- # def test_my_class2
151
- # ...
152
- # end
153
- # end
154
- #
155
- # Here is a call order:
156
- # * startup
157
- # * setup
158
- # * test_my_class1 (or test_my_class2)
159
- # * setup
160
- # * test_my_class2 (or test_my_class1)
161
- #
162
- # Note that you should not assume test order. Tests
163
- # should be worked in any order.
164
- def startup
165
- end
166
-
167
- # Called after every test case runs. Can be used to tear
168
- # down fixture information used in test case scope.
169
- #
170
- # Here is an example test case:
171
- # class TestMyClass < Test::Unit::TestCase
172
- # class << self
173
- # def shutdown
174
- # ...
175
- # end
176
- # end
177
- #
178
- # def teardown
179
- # ...
180
- # end
181
- #
182
- # def test_my_class1
183
- # ...
184
- # end
185
- #
186
- # def test_my_class2
187
- # ...
188
- # end
189
- # end
190
- #
191
- # Here is a call order:
192
- # * test_my_class1 (or test_my_class2)
193
- # * teardown
194
- # * test_my_class2 (or test_my_class1)
195
- # * teardown
196
- # * shutdown
197
- #
198
- # Note that you should not assume test order. Tests
199
- # should be worked in any order.
200
- def shutdown
201
- end
202
-
203
- @@test_orders = {}
204
-
205
- # Returns the current test order. This returns
206
- # +:alphabetic+ by default.
207
- def test_order
208
- @@test_orders[self] || AVAILABLE_ORDERS.first
209
- end
210
-
211
- # Sets the current test order.
212
- #
213
- # Here are the available _order_:
214
- # [:alphabetic]
215
- # Default. Tests are sorted in alphabetic order.
216
- # [:random]
217
- # Tests are sorted in random order.
218
- # [:defined]
219
- # Tests are sorted in defined order.
220
- def test_order=(order)
221
- @@test_orders[self] = order
222
- end
223
-
224
- # Defines a test in declarative syntax or marks
225
- # following method as a test method.
226
- #
227
- # In declarative syntax usage, the following two
228
- # test definitions are the almost same:
229
- #
230
- # description "register user"
231
- # def test_register_user
232
- # ...
233
- # end
234
- #
235
- # test "register user" do
236
- # ...
237
- # end
238
- #
239
- # In test method mark usage, the "my_test_method" is
240
- # treated as a test method:
241
- #
242
- # test
243
- # def my_test_method
244
- # assert_equal("call me", ...)
245
- # end
246
- def test(*test_description_or_targets, &block)
247
- if block_given?
248
- test_description = test_description_or_targets.first
249
- if test_description.nil?
250
- raise ArgumentError, "test description is missing"
251
- end
252
- n_arguments = test_description_or_targets.size
253
- if n_arguments > 1
254
- message = "wrong number of arguments (#{n_arguments} for 1)"
255
- raise ArgumentError, message
256
- end
257
- method_name = test_description
258
- define_method(method_name, &block)
259
- description(test_description, method_name)
260
- attribute(:test, true, {}, method_name)
261
- else
262
- targets = test_description_or_targets
263
- attribute(:test, true, {}, *targets)
264
- end
265
- end
266
-
267
- # Describes a test.
268
- #
269
- # The following example associates "register a
270
- # normal user" description with "test_register"
271
- # test.
272
- #
273
- # description "register a normal user"
274
- # def test_register
275
- # ...
276
- # end
277
- def description(value, target=nil)
278
- attribute(:description, value, {}, target || [])
279
- end
280
-
281
- # :stopdoc:
282
- private
283
- def collect_test_names
284
- method_names = public_instance_methods(true).collect do |name|
285
- name.to_s
286
- end
287
- test_names = method_names.find_all do |method_name|
288
- method_name =~ /^test./ or get_attribute(method_name, :test)
289
- end
290
- send("sort_test_names_in_#{test_order}_order", test_names)
291
- end
292
-
293
- def sort_test_names_in_alphabetic_order(test_names)
294
- test_names.sort
295
- end
296
-
297
- def sort_test_names_in_random_order(test_names)
298
- test_names.sort_by {rand(test_names.size)}
299
- end
300
-
301
- def sort_test_names_in_defined_order(test_names)
302
- added_methods = @@added_methods[self]
303
- test_names.sort do |test1, test2|
304
- test1_defined_order = added_methods.index(test1)
305
- test2_defined_order = added_methods.index(test2)
306
- if test1_defined_order and test2_defined_order
307
- test1_defined_order <=> test2_defined_order
308
- elsif test1_defined_order
309
- 1
310
- elsif test2_defined_order
311
- -1
312
- else
313
- test1 <=> test2
314
- end
315
- end
316
- end
317
- # :startdoc:
318
- end
319
-
320
- attr_reader :method_name, :start_time, :elapsed_time
321
-
322
- # Creates a new instance of the fixture for running the
323
- # test represented by test_method_name.
324
- def initialize(test_method_name)
325
- throw :invalid_test unless respond_to?(test_method_name)
326
- test_method = method(test_method_name)
327
- throw :invalid_test if test_method.arity > 0
328
- owner = Util::MethodOwnerFinder.find(self, test_method_name)
329
- if owner.class != Module and self.class != owner
330
- throw :invalid_test
331
- end
332
- @method_name = test_method_name
333
- @test_passed = true
334
- @interrupted = false
335
- @start_time = nil
336
- @elapsed_time = nil
337
- end
338
-
339
- # Runs the individual test method represented by this
340
- # instance of the fixture, collecting statistics, failures
341
- # and errors in result.
342
- def run(result)
343
- begin
344
- @_result = result
345
- @start_time = Time.now
346
- yield(STARTED, name)
347
- yield(STARTED_OBJECT, self)
348
- begin
349
- run_setup
350
- run_test
351
- rescue Exception
352
- @interrupted = true
353
- raise unless handle_exception($!)
354
- ensure
355
- begin
356
- run_teardown
357
- rescue Exception
358
- raise unless handle_exception($!)
359
- end
360
- end
361
- @elapsed_time = Time.now - @start_time
362
- result.add_run
363
- yield(FINISHED, name)
364
- yield(FINISHED_OBJECT, self)
365
- ensure
366
- # @_result = nil # For test-spec's after_all :<
367
- end
368
- end
369
-
370
- # Called before every test method runs. Can be used
371
- # to set up fixture information.
372
- #
373
- # You can add additional setup tasks by the following
374
- # code:
375
- # class TestMyClass < Test::Unit::TestCase
376
- # def setup
377
- # ...
378
- # end
379
- #
380
- # setup
381
- # def my_setup1
382
- # ...
383
- # end
384
- #
385
- # setup
386
- # def my_setup2
387
- # ...
388
- # end
389
- #
390
- # def test_my_class
391
- # ...
392
- # end
393
- # end
394
- #
395
- # Here is a call order:
396
- # * setup
397
- # * my_setup1
398
- # * my_setup2
399
- # * test_my_class
400
- def setup
401
- end
402
-
403
- # Called after every test method runs. Can be used to tear
404
- # down fixture information.
405
- #
406
- # You can add additional teardown tasks by the following
407
- # code:
408
- # class TestMyClass < Test::Unit::TestCase
409
- # def teardown
410
- # ...
411
- # end
412
- #
413
- # teardown
414
- # def my_teardown1
415
- # ...
416
- # end
417
- #
418
- # teardown
419
- # def my_teardown2
420
- # ...
421
- # end
422
- #
423
- # def test_my_class
424
- # ...
425
- # end
426
- # end
427
- #
428
- # Here is a call order:
429
- # * test_my_class
430
- # * my_teardown2
431
- # * my_teardown1
432
- # * teardown
433
- def teardown
434
- end
435
-
436
- def default_test
437
- flunk("No tests were specified")
438
- end
439
-
440
- def size
441
- 1
442
- end
443
-
444
- # Returns a human-readable name for the specific test that
445
- # this instance of TestCase represents.
446
- def name
447
- "#{@method_name}(#{self.class.name})"
448
- end
449
-
450
- # Returns a description for the test. A description
451
- # will be associated by Test::Unit::TestCase.test or
452
- # Test::Unit::TestCase.description.
453
- #
454
- # Returns a name for the test for no description test.
455
- def description
456
- self[:description] || name
457
- end
458
-
459
- # Overridden to return #name.
460
- def to_s
461
- name
462
- end
463
-
464
- # It's handy to be able to compare TestCase instances.
465
- def ==(other)
466
- return false unless(other.kind_of?(self.class))
467
- return false unless(@method_name == other.method_name)
468
- self.class == other.class
469
- end
470
-
471
- def interrupted?
472
- @interrupted
473
- end
474
-
475
- # Returns whether this individual test passed or
476
- # not. Primarily for use in teardown so that artifacts
477
- # can be left behind if the test fails.
478
- def passed?
479
- @test_passed
480
- end
481
-
482
- private
483
- def current_result
484
- @_result
485
- end
486
-
487
- def run_test
488
- if self.class.get_attribute(@method_name, :redefined)
489
- notify("#{self.class}\##{@method_name} was redefined")
490
- end
491
- __send__(@method_name)
492
- add_pass
493
- end
494
-
495
- def handle_exception(exception)
496
- self.class.exception_handlers.each do |handler|
497
- return true if send(handler, exception)
498
- end
499
- false
500
- end
501
-
502
- def problem_occurred
503
- @test_passed = false
504
- end
505
-
506
- def add_assertion
507
- current_result.add_assertion
508
- end
509
-
510
- def add_pass
511
- current_result.add_pass
512
- end
513
- end
514
- end
515
- end