glib2 0.20.0 → 0.90.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +92 -0
- data/README +22 -10
- data/Rakefile +54 -72
- data/ext/glib2/depend +10 -0
- data/ext/glib2/extconf.rb +61 -0
- data/ext/glib2/glib2.def +89 -0
- data/{src → ext/glib2}/rbgcompat.h +0 -0
- data/{src → ext/glib2}/rbglib.c +17 -7
- data/{src → ext/glib2}/rbglib.h +2 -2
- data/{src → ext/glib2}/rbglib_bookmarkfile.c +0 -0
- data/{src → ext/glib2}/rbglib_completion.c +0 -0
- data/{src → ext/glib2}/rbglib_convert.c +0 -0
- data/{src → ext/glib2}/rbglib_error.c +0 -0
- data/{src → ext/glib2}/rbglib_fileutils.c +0 -0
- data/{src → ext/glib2}/rbglib_i18n.c +0 -0
- data/{src → ext/glib2}/rbglib_int64.c +0 -0
- data/{src → ext/glib2}/rbglib_iochannel.c +0 -0
- data/{src → ext/glib2}/rbglib_keyfile.c +0 -0
- data/{src → ext/glib2}/rbglib_maincontext.c +1 -3
- data/{src → ext/glib2}/rbglib_mainloop.c +0 -0
- data/{src → ext/glib2}/rbglib_messages.c +0 -0
- data/{src → ext/glib2}/rbglib_pollfd.c +0 -0
- data/{src → ext/glib2}/rbglib_shell.c +0 -0
- data/{src → ext/glib2}/rbglib_source.c +0 -0
- data/{src → ext/glib2}/rbglib_spawn.c +0 -0
- data/{src → ext/glib2}/rbglib_threads.c +0 -0
- data/{src → ext/glib2}/rbglib_timer.c +0 -0
- data/{src → ext/glib2}/rbglib_unicode.c +0 -0
- data/{src → ext/glib2}/rbglib_utils.c +0 -0
- data/{src → ext/glib2}/rbglib_win32.c +0 -0
- data/{src → ext/glib2}/rbgobj_boxed.c +0 -0
- data/{src → ext/glib2}/rbgobj_closure.c +0 -0
- data/{src → ext/glib2}/rbgobj_convert.c +0 -0
- data/{src → ext/glib2}/rbgobj_enums.c +0 -0
- data/{src → ext/glib2}/rbgobj_fundamental.c +0 -0
- data/{src → ext/glib2}/rbgobj_object.c +0 -0
- data/{src → ext/glib2}/rbgobj_param.c +0 -0
- data/{src → ext/glib2}/rbgobj_paramspecs.c +0 -0
- data/{src → ext/glib2}/rbgobj_signal.c +0 -0
- data/{src → ext/glib2}/rbgobj_strv.c +0 -0
- data/{src → ext/glib2}/rbgobj_type.c +0 -0
- data/{src → ext/glib2}/rbgobj_typeinstance.c +0 -0
- data/{src → ext/glib2}/rbgobj_typeinterface.c +0 -0
- data/{src → ext/glib2}/rbgobj_typemodule.c +0 -0
- data/{src → ext/glib2}/rbgobj_typeplugin.c +0 -0
- data/{src → ext/glib2}/rbgobj_value.c +0 -0
- data/{src → ext/glib2}/rbgobj_valuearray.c +0 -0
- data/{src → ext/glib2}/rbgobj_valuetypes.c +0 -0
- data/{src → ext/glib2}/rbgobject.c +0 -0
- data/{src → ext/glib2}/rbgobject.h +0 -0
- data/{src → ext/glib2}/rbgprivate.h +0 -0
- data/ext/glib2/rbgutil.c +316 -0
- data/{src → ext/glib2}/rbgutil.h +9 -9
- data/{src → ext/glib2}/rbgutil_callback.c +0 -0
- data/extconf.rb +48 -60
- data/{src/lib → lib}/glib-mkenums.rb +2 -2
- data/{src/lib → lib}/glib2.rb +28 -9
- data/lib/gnome2-win32-binary-downloader.rb +92 -0
- data/{src/lib → lib}/mkmf-gnome2.rb +76 -89
- data/test-unit/COPYING +56 -0
- data/test-unit/GPL +340 -0
- data/test-unit/History.txt +232 -0
- data/test-unit/Manifest.txt +110 -0
- data/test-unit/PSFL +271 -0
- data/test-unit/README.txt +75 -0
- data/test-unit/Rakefile +53 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/bar.png +0 -0
- data/test-unit/html/bar.svg +153 -0
- data/test-unit/html/developer.png +0 -0
- data/test-unit/html/developer.svg +469 -0
- data/test-unit/html/famfamfam-logo.png +0 -0
- data/test-unit/html/favicon.ico +0 -0
- data/test-unit/html/favicon.png +0 -0
- data/test-unit/html/favicon.svg +82 -0
- data/test-unit/html/heading-mark.png +0 -0
- data/test-unit/html/heading-mark.svg +393 -0
- data/test-unit/html/index.html +247 -0
- data/test-unit/html/index.html.ja +270 -0
- data/test-unit/html/install.png +0 -0
- data/test-unit/html/install.svg +636 -0
- data/test-unit/html/jp.png +0 -0
- data/test-unit/html/kinotan-failure.png +0 -0
- data/test-unit/html/kinotan-pass.png +0 -0
- data/test-unit/html/logo.png +0 -0
- data/test-unit/html/logo.svg +483 -0
- data/test-unit/html/reference.png +0 -0
- data/test-unit/html/rubyforge.png +0 -0
- data/test-unit/html/tango-logo.png +0 -0
- data/test-unit/html/test-unit.css +339 -0
- data/test-unit/html/tutorial.png +0 -0
- data/test-unit/html/tutorial.svg +559 -0
- data/test-unit/html/us.png +0 -0
- data/test-unit/images/color-diff.png +0 -0
- data/test-unit/lib/test/unit.rb +328 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
- data/test-unit/lib/test/unit/assertions.rb +1334 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +363 -0
- data/test-unit/lib/test/unit/collector.rb +36 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +144 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +106 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +740 -0
- data/test-unit/lib/test/unit/error.rb +130 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +136 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +129 -0
- data/test-unit/lib/test/unit/omission.rb +191 -0
- data/test-unit/lib/test/unit/pending.rb +150 -0
- data/test-unit/lib/test/unit/priority.rb +180 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/runner/tap.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +483 -0
- data/test-unit/lib/test/unit/testresult.rb +121 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +430 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +82 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +53 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +42 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/output.rb +31 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/test_adder.rb +20 -0
- data/test-unit/sample/test_subtracter.rb +20 -0
- data/test-unit/sample/test_user.rb +23 -0
- data/test-unit/test/collector/test-descendant.rb +133 -0
- data/test-unit/test/collector/test-load.rb +442 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +100 -0
- data/test-unit/test/run-test.rb +15 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +69 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +518 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +544 -0
- data/test-unit/test/test_assertions.rb +1197 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_tap.rb +33 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test-output.rb +11 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/run-test.rb +2 -6
- metadata +197 -100
- data/src/glib-enum-types.c +0 -1032
- data/src/glib-enum-types.h +0 -140
- data/src/lib/pkg-config.rb +0 -137
- data/src/rbgutil.c +0 -222
@@ -0,0 +1,180 @@
|
|
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
|
@@ -0,0 +1,52 @@
|
|
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
|
@@ -0,0 +1,483 @@
|
|
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
|
+
|
91
|
+
DESCENDANTS = [] # :nodoc:
|
92
|
+
AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
|
93
|
+
|
94
|
+
class << self
|
95
|
+
def inherited(sub_class) # :nodoc:
|
96
|
+
DESCENDANTS << sub_class
|
97
|
+
end
|
98
|
+
|
99
|
+
@@added_methods = {}
|
100
|
+
def method_added(name) # :nodoc:
|
101
|
+
super
|
102
|
+
added_methods = (@@added_methods[self] ||= [])
|
103
|
+
stringified_name = name.to_s
|
104
|
+
if added_methods.include?(stringified_name)
|
105
|
+
attribute(:redefined, true, {}, stringified_name)
|
106
|
+
end
|
107
|
+
added_methods << stringified_name
|
108
|
+
end
|
109
|
+
|
110
|
+
# Rolls up all of the test* methods in the fixture into
|
111
|
+
# one suite, creating a new instance of the fixture for
|
112
|
+
# each method.
|
113
|
+
def suite
|
114
|
+
suite = TestSuite.new(name, self)
|
115
|
+
collect_test_names.each do |test|
|
116
|
+
catch(:invalid_test) do
|
117
|
+
suite << new(test)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
if suite.empty?
|
121
|
+
catch(:invalid_test) do
|
122
|
+
suite << new("default_test")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
suite
|
126
|
+
end
|
127
|
+
|
128
|
+
# Called before every test case runs. Can be used
|
129
|
+
# to set up fixture information used in test case
|
130
|
+
# scope.
|
131
|
+
#
|
132
|
+
# Here is an example test case:
|
133
|
+
# class TestMyClass < Test::Unit::TestCase
|
134
|
+
# class << self
|
135
|
+
# def startup
|
136
|
+
# ...
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# def setup
|
141
|
+
# ...
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# def test_my_class1
|
145
|
+
# ...
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# def test_my_class2
|
149
|
+
# ...
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# Here is a call order:
|
154
|
+
# * startup
|
155
|
+
# * setup
|
156
|
+
# * test_my_class1 (or test_my_class2)
|
157
|
+
# * setup
|
158
|
+
# * test_my_class2 (or test_my_class1)
|
159
|
+
#
|
160
|
+
# Note that you should not assume test order. Tests
|
161
|
+
# should be worked in any order.
|
162
|
+
def startup
|
163
|
+
end
|
164
|
+
|
165
|
+
# Called after every test case runs. Can be used to tear
|
166
|
+
# down fixture information used in test case scope.
|
167
|
+
#
|
168
|
+
# Here is an example test case:
|
169
|
+
# class TestMyClass < Test::Unit::TestCase
|
170
|
+
# class << self
|
171
|
+
# def shutdown
|
172
|
+
# ...
|
173
|
+
# end
|
174
|
+
# end
|
175
|
+
#
|
176
|
+
# def teardown
|
177
|
+
# ...
|
178
|
+
# end
|
179
|
+
#
|
180
|
+
# def test_my_class1
|
181
|
+
# ...
|
182
|
+
# end
|
183
|
+
#
|
184
|
+
# def test_my_class2
|
185
|
+
# ...
|
186
|
+
# end
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# Here is a call order:
|
190
|
+
# * test_my_class1 (or test_my_class2)
|
191
|
+
# * teardown
|
192
|
+
# * test_my_class2 (or test_my_class1)
|
193
|
+
# * teardown
|
194
|
+
# * shutdown
|
195
|
+
#
|
196
|
+
# Note that you should not assume test order. Tests
|
197
|
+
# should be worked in any order.
|
198
|
+
def shutdown
|
199
|
+
end
|
200
|
+
|
201
|
+
@@test_orders = {}
|
202
|
+
|
203
|
+
# Returns the current test order. This returns
|
204
|
+
# +:alphabetic+ by default.
|
205
|
+
def test_order
|
206
|
+
@@test_orders[self] || AVAILABLE_ORDERS.first
|
207
|
+
end
|
208
|
+
|
209
|
+
# Sets the current test order.
|
210
|
+
#
|
211
|
+
# Here are the available _order_:
|
212
|
+
# [:alphabetic]
|
213
|
+
# Default. Tests are sorted in alphabetic order.
|
214
|
+
# [:random]
|
215
|
+
# Tests are sorted in random order.
|
216
|
+
# [:defined]
|
217
|
+
# Tests are sorted in defined order.
|
218
|
+
def test_order=(order)
|
219
|
+
@@test_orders[self] = order
|
220
|
+
end
|
221
|
+
|
222
|
+
# Defines a test in declarative syntax.
|
223
|
+
#
|
224
|
+
# The following two test definitions are the same:
|
225
|
+
#
|
226
|
+
# description "register user"
|
227
|
+
# def test_register_user
|
228
|
+
# ...
|
229
|
+
# end
|
230
|
+
#
|
231
|
+
# test "register user" do
|
232
|
+
# ...
|
233
|
+
# end
|
234
|
+
def test(test_description, &block)
|
235
|
+
normalized_description = test_description.gsub(/[^a-zA-Z\d_]+/, '_')
|
236
|
+
method_name = "test_#{normalized_description}".to_sym
|
237
|
+
define_method(method_name, &block)
|
238
|
+
description(test_description, method_name)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Describes a test.
|
242
|
+
#
|
243
|
+
# The following example associates "register a
|
244
|
+
# normal user" description with "test_register"
|
245
|
+
# test.
|
246
|
+
#
|
247
|
+
# description "register a normal user"
|
248
|
+
# def test_register
|
249
|
+
# ...
|
250
|
+
# end
|
251
|
+
def description(value, target=nil)
|
252
|
+
attribute(:description, value, {}, target || [])
|
253
|
+
end
|
254
|
+
|
255
|
+
# :stopdoc:
|
256
|
+
private
|
257
|
+
def collect_test_names
|
258
|
+
method_names = public_instance_methods(true).collect do |name|
|
259
|
+
name.to_s
|
260
|
+
end
|
261
|
+
test_names = method_names.find_all do |method_name|
|
262
|
+
method_name =~ /^test./
|
263
|
+
end
|
264
|
+
send("sort_test_names_in_#{test_order}_order", test_names)
|
265
|
+
end
|
266
|
+
|
267
|
+
def sort_test_names_in_alphabetic_order(test_names)
|
268
|
+
test_names.sort
|
269
|
+
end
|
270
|
+
|
271
|
+
def sort_test_names_in_random_order(test_names)
|
272
|
+
test_names.sort_by {rand(test_names.size)}
|
273
|
+
end
|
274
|
+
|
275
|
+
def sort_test_names_in_defined_order(test_names)
|
276
|
+
added_methods = @@added_methods[self]
|
277
|
+
test_names.sort do |test1, test2|
|
278
|
+
test1_defined_order = added_methods.index(test1)
|
279
|
+
test2_defined_order = added_methods.index(test2)
|
280
|
+
if test1_defined_order and test2_defined_order
|
281
|
+
test1_defined_order <=> test2_defined_order
|
282
|
+
elsif test1_defined_order
|
283
|
+
1
|
284
|
+
elsif test2_defined_order
|
285
|
+
-1
|
286
|
+
else
|
287
|
+
test1 <=> test2
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
# :startdoc:
|
292
|
+
end
|
293
|
+
|
294
|
+
attr_reader :method_name
|
295
|
+
|
296
|
+
# Creates a new instance of the fixture for running the
|
297
|
+
# test represented by test_method_name.
|
298
|
+
def initialize(test_method_name)
|
299
|
+
throw :invalid_test unless respond_to?(test_method_name)
|
300
|
+
test_method = method(test_method_name)
|
301
|
+
throw :invalid_test if test_method.arity > 0
|
302
|
+
owner = Util::MethodOwnerFinder.find(self, test_method_name)
|
303
|
+
if owner.class != Module and self.class != owner
|
304
|
+
throw :invalid_test
|
305
|
+
end
|
306
|
+
@method_name = test_method_name
|
307
|
+
@test_passed = true
|
308
|
+
@interrupted = false
|
309
|
+
end
|
310
|
+
|
311
|
+
# Runs the individual test method represented by this
|
312
|
+
# instance of the fixture, collecting statistics, failures
|
313
|
+
# and errors in result.
|
314
|
+
def run(result)
|
315
|
+
begin
|
316
|
+
@_result = result
|
317
|
+
yield(STARTED, name)
|
318
|
+
begin
|
319
|
+
run_setup
|
320
|
+
run_test
|
321
|
+
rescue Exception
|
322
|
+
@interrupted = true
|
323
|
+
raise unless handle_exception($!)
|
324
|
+
ensure
|
325
|
+
begin
|
326
|
+
run_teardown
|
327
|
+
rescue Exception
|
328
|
+
raise unless handle_exception($!)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
result.add_run
|
332
|
+
yield(FINISHED, name)
|
333
|
+
ensure
|
334
|
+
# @_result = nil # For test-spec's after_all :<
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
# Called before every test method runs. Can be used
|
339
|
+
# to set up fixture information.
|
340
|
+
#
|
341
|
+
# You can add additional setup tasks by the following
|
342
|
+
# code:
|
343
|
+
# class TestMyClass < Test::Unit::TestCase
|
344
|
+
# def setup
|
345
|
+
# ...
|
346
|
+
# end
|
347
|
+
#
|
348
|
+
# setup
|
349
|
+
# def my_setup1
|
350
|
+
# ...
|
351
|
+
# end
|
352
|
+
#
|
353
|
+
# setup
|
354
|
+
# def my_setup2
|
355
|
+
# ...
|
356
|
+
# end
|
357
|
+
#
|
358
|
+
# def test_my_class
|
359
|
+
# ...
|
360
|
+
# end
|
361
|
+
# end
|
362
|
+
#
|
363
|
+
# Here is a call order:
|
364
|
+
# * setup
|
365
|
+
# * my_setup1
|
366
|
+
# * my_setup2
|
367
|
+
# * test_my_class
|
368
|
+
def setup
|
369
|
+
end
|
370
|
+
|
371
|
+
# Called after every test method runs. Can be used to tear
|
372
|
+
# down fixture information.
|
373
|
+
#
|
374
|
+
# You can add additional teardown tasks by the following
|
375
|
+
# code:
|
376
|
+
# class TestMyClass < Test::Unit::TestCase
|
377
|
+
# def teardown
|
378
|
+
# ...
|
379
|
+
# end
|
380
|
+
#
|
381
|
+
# teardown
|
382
|
+
# def my_teardown1
|
383
|
+
# ...
|
384
|
+
# end
|
385
|
+
#
|
386
|
+
# teardown
|
387
|
+
# def my_teardown2
|
388
|
+
# ...
|
389
|
+
# end
|
390
|
+
#
|
391
|
+
# def test_my_class
|
392
|
+
# ...
|
393
|
+
# end
|
394
|
+
# end
|
395
|
+
#
|
396
|
+
# Here is a call order:
|
397
|
+
# * test_my_class
|
398
|
+
# * my_teardown2
|
399
|
+
# * my_teardown1
|
400
|
+
# * teardown
|
401
|
+
def teardown
|
402
|
+
end
|
403
|
+
|
404
|
+
def default_test
|
405
|
+
flunk("No tests were specified")
|
406
|
+
end
|
407
|
+
|
408
|
+
def size
|
409
|
+
1
|
410
|
+
end
|
411
|
+
|
412
|
+
# Returns a human-readable name for the specific test that
|
413
|
+
# this instance of TestCase represents.
|
414
|
+
def name
|
415
|
+
"#{@method_name}(#{self.class.name})"
|
416
|
+
end
|
417
|
+
|
418
|
+
# Returns a description for the test. A description
|
419
|
+
# will be associated by Test::Unit::TestCase.test or
|
420
|
+
# Test::Unit::TestCase.description.
|
421
|
+
#
|
422
|
+
# Returns a name for the test for no description test.
|
423
|
+
def description
|
424
|
+
self[:description] || name
|
425
|
+
end
|
426
|
+
|
427
|
+
# Overridden to return #name.
|
428
|
+
def to_s
|
429
|
+
name
|
430
|
+
end
|
431
|
+
|
432
|
+
# It's handy to be able to compare TestCase instances.
|
433
|
+
def ==(other)
|
434
|
+
return false unless(other.kind_of?(self.class))
|
435
|
+
return false unless(@method_name == other.method_name)
|
436
|
+
self.class == other.class
|
437
|
+
end
|
438
|
+
|
439
|
+
def interrupted?
|
440
|
+
@interrupted
|
441
|
+
end
|
442
|
+
|
443
|
+
private
|
444
|
+
def current_result
|
445
|
+
@_result
|
446
|
+
end
|
447
|
+
|
448
|
+
def run_test
|
449
|
+
if self.class.get_attribute(@method_name, :redefined)
|
450
|
+
notify("#{self.class}\##{@method_name} was redefined")
|
451
|
+
end
|
452
|
+
__send__(@method_name)
|
453
|
+
add_pass
|
454
|
+
end
|
455
|
+
|
456
|
+
def handle_exception(exception)
|
457
|
+
self.class.exception_handlers.each do |handler|
|
458
|
+
return true if send(handler, exception)
|
459
|
+
end
|
460
|
+
false
|
461
|
+
end
|
462
|
+
|
463
|
+
# Returns whether this individual test passed or
|
464
|
+
# not. Primarily for use in teardown so that artifacts
|
465
|
+
# can be left behind if the test fails.
|
466
|
+
def passed?
|
467
|
+
@test_passed
|
468
|
+
end
|
469
|
+
|
470
|
+
def problem_occurred
|
471
|
+
@test_passed = false
|
472
|
+
end
|
473
|
+
|
474
|
+
def add_assertion
|
475
|
+
current_result.add_assertion
|
476
|
+
end
|
477
|
+
|
478
|
+
def add_pass
|
479
|
+
current_result.add_pass
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|