activeldap 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +10 -0
- data/README +3 -2
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/po/en/al-admin.po +1 -1
- data/examples/al-admin/po/ja/al-admin.po +1 -1
- data/examples/al-admin/po/nl/al-admin.po +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +7 -8
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +2 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +1 -1
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +2 -1
- data/lib/active_ldap.rb +9 -3
- data/lib/active_ldap/action_controller/ldap_benchmarking.rb +36 -0
- data/lib/active_ldap/adapter/jndi.rb +1 -1
- data/lib/active_ldap/adapter/jndi_connection.rb +2 -1
- data/lib/active_ldap/association/belongs_to_many.rb +10 -2
- data/lib/active_ldap/association/collection.rb +10 -0
- data/lib/active_ldap/association/has_many_utils.rb +13 -9
- data/lib/active_ldap/association/has_many_wrap.rb +10 -2
- data/lib/active_ldap/associations.rb +3 -3
- data/lib/active_ldap/base.rb +95 -32
- data/lib/active_ldap/connection.rb +1 -1
- data/lib/active_ldap/distinguished_name.rb +3 -0
- data/lib/active_ldap/entry_attribute.rb +2 -2
- data/lib/active_ldap/ldif.rb +2 -2
- data/lib/active_ldap/operations.rb +7 -3
- data/lib/active_ldap/user_password.rb +0 -1
- data/lib/active_ldap/validations.rb +2 -0
- data/po/en/active-ldap.po +1 -1
- data/po/ja/active-ldap.po +1 -1
- data/rails/plugin/active_ldap/init.rb +3 -34
- data/test-unit/History.txt +32 -0
- data/test-unit/Manifest.txt +70 -0
- data/test-unit/README.txt +32 -0
- data/test-unit/Rakefile +22 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +280 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +722 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +250 -0
- data/test-unit/lib/test/unit/collector.rb +43 -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 +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color.rb +61 -0
- data/test-unit/lib/test/unit/diff.rb +524 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +185 -0
- data/test-unit/lib/test/unit/notification.rb +116 -0
- data/test-unit/lib/test/unit/omission.rb +129 -0
- data/test-unit/lib/test/unit/pending.rb +130 -0
- data/test-unit/lib/test/unit/priority.rb +146 -0
- data/test-unit/lib/test/unit/runner/console.rb +46 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +174 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -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 +195 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -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 +41 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -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/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test_descendant.rb +135 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_load.rb +333 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test_assertions.rb +693 -0
- data/test-unit/test/test_attribute.rb +86 -0
- data/{test-unit-ext → test-unit}/test/test_color.rb +3 -5
- data/{test-unit-ext → test-unit}/test/test_diff.rb +18 -16
- data/test-unit/test/test_emacs_runner.rb +60 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_fixture.rb +275 -0
- data/{test-unit-ext → test-unit}/test/test_notification.rb +7 -6
- data/test-unit/test/test_omission.rb +81 -0
- data/{test-unit-ext → test-unit}/test/test_pending.rb +15 -15
- data/{test-unit-ext → test-unit}/test/test_priority.rb +4 -3
- data/test-unit/test/test_testcase.rb +411 -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 +12 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -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/al-test-utils.rb +4 -4
- data/test/command.rb +1 -1
- data/test/run-test.rb +5 -4
- data/test/test_associations.rb +143 -9
- data/test/test_base.rb +25 -1
- data/test/test_dn.rb +2 -0
- data/test/test_find.rb +8 -1
- data/test/test_ldif.rb +51 -114
- data/test/test_reflection.rb +4 -8
- data/test/test_usermod-lang-add.rb +2 -1
- data/test/test_validation.rb +4 -3
- metadata +76 -31
- data/test-unit-ext/NEWS.en +0 -28
- data/test-unit-ext/NEWS.ja +0 -28
- data/test-unit-ext/README.en +0 -247
- data/test-unit-ext/README.ja +0 -246
- data/test-unit-ext/Rakefile +0 -111
- data/test-unit-ext/lib/test-unit-ext.rb +0 -16
- data/test-unit-ext/lib/test-unit-ext/always-show-result.rb +0 -28
- data/test-unit-ext/lib/test-unit-ext/assertions.rb +0 -40
- data/test-unit-ext/lib/test-unit-ext/attributes.rb +0 -129
- data/test-unit-ext/lib/test-unit-ext/backtrace-filter.rb +0 -17
- data/test-unit-ext/lib/test-unit-ext/color.rb +0 -59
- data/test-unit-ext/lib/test-unit-ext/colorized-runner.rb +0 -111
- data/test-unit-ext/lib/test-unit-ext/diff.rb +0 -516
- data/test-unit-ext/lib/test-unit-ext/long-display-for-emacs.rb +0 -25
- data/test-unit-ext/lib/test-unit-ext/notification.rb +0 -79
- data/test-unit-ext/lib/test-unit-ext/omission.rb +0 -96
- data/test-unit-ext/lib/test-unit-ext/pending.rb +0 -97
- data/test-unit-ext/lib/test-unit-ext/priority.rb +0 -158
- data/test-unit-ext/lib/test-unit-ext/version.rb +0 -3
- data/test-unit-ext/lib/test-unit-ext/xml-report.rb +0 -224
- data/test-unit-ext/test/run-test.rb +0 -14
- data/test-unit-ext/test/test_attributes.rb +0 -139
- data/test-unit-ext/test/test_omission.rb +0 -64
- data/test-unit-ext/test/test_xml_report.rb +0 -161
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
"Use 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
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Nathaniel Talbott.
|
|
4
|
+
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
require 'test/unit/attribute'
|
|
8
|
+
require 'test/unit/fixture'
|
|
9
|
+
require 'test/unit/exceptionhandler'
|
|
10
|
+
require 'test/unit/assertions'
|
|
11
|
+
require 'test/unit/failure'
|
|
12
|
+
require 'test/unit/error'
|
|
13
|
+
require 'test/unit/pending'
|
|
14
|
+
require 'test/unit/omission'
|
|
15
|
+
require 'test/unit/notification'
|
|
16
|
+
require 'test/unit/priority'
|
|
17
|
+
require 'test/unit/testsuite'
|
|
18
|
+
require 'test/unit/assertionfailederror'
|
|
19
|
+
require 'test/unit/util/backtracefilter'
|
|
20
|
+
|
|
21
|
+
module Test
|
|
22
|
+
module Unit
|
|
23
|
+
|
|
24
|
+
# Ties everything together. If you subclass and add your own
|
|
25
|
+
# test methods, it takes care of making them into tests and
|
|
26
|
+
# wrapping those tests into a suite. It also does the
|
|
27
|
+
# nitty-gritty of actually running an individual test and
|
|
28
|
+
# collecting its results into a Test::Unit::TestResult object.
|
|
29
|
+
class TestCase
|
|
30
|
+
include Attribute
|
|
31
|
+
include Fixture
|
|
32
|
+
include ExceptionHandler
|
|
33
|
+
include ErrorHandler
|
|
34
|
+
include FailureHandler
|
|
35
|
+
include TestCasePendingSupport
|
|
36
|
+
include TestCaseOmissionSupport
|
|
37
|
+
include TestCaseNotificationSupport
|
|
38
|
+
include Priority
|
|
39
|
+
include Assertions
|
|
40
|
+
include Util::BacktraceFilter
|
|
41
|
+
|
|
42
|
+
STARTED = name + "::STARTED"
|
|
43
|
+
FINISHED = name + "::FINISHED"
|
|
44
|
+
|
|
45
|
+
DESCENDANTS = []
|
|
46
|
+
|
|
47
|
+
class << self
|
|
48
|
+
def inherited(sub_class)
|
|
49
|
+
DESCENDANTS << sub_class
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Rolls up all of the test* methods in the fixture into
|
|
53
|
+
# one suite, creating a new instance of the fixture for
|
|
54
|
+
# each method.
|
|
55
|
+
def suite
|
|
56
|
+
method_names = public_instance_methods(true).collect {|name| name.to_s}
|
|
57
|
+
tests = method_names.delete_if {|method_name| method_name !~ /^test./}
|
|
58
|
+
suite = TestSuite.new(name, self)
|
|
59
|
+
tests.sort.each do |test|
|
|
60
|
+
catch(:invalid_test) do
|
|
61
|
+
suite << new(test)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
if suite.empty?
|
|
65
|
+
catch(:invalid_test) do
|
|
66
|
+
suite << new("default_test")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
suite
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
attr_reader :method_name
|
|
74
|
+
|
|
75
|
+
# Creates a new instance of the fixture for running the
|
|
76
|
+
# test represented by test_method_name.
|
|
77
|
+
def initialize(test_method_name)
|
|
78
|
+
throw :invalid_test unless respond_to?(test_method_name)
|
|
79
|
+
throw :invalid_test if method(test_method_name).arity > 0
|
|
80
|
+
@method_name = test_method_name
|
|
81
|
+
@test_passed = true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Runs the individual test method represented by this
|
|
85
|
+
# instance of the fixture, collecting statistics, failures
|
|
86
|
+
# and errors in result.
|
|
87
|
+
def run(result)
|
|
88
|
+
begin
|
|
89
|
+
@_result = result
|
|
90
|
+
yield(STARTED, name)
|
|
91
|
+
begin
|
|
92
|
+
run_setup
|
|
93
|
+
__send__(@method_name)
|
|
94
|
+
rescue Exception
|
|
95
|
+
raise unless handle_exception($!)
|
|
96
|
+
ensure
|
|
97
|
+
begin
|
|
98
|
+
run_teardown
|
|
99
|
+
rescue Exception
|
|
100
|
+
raise unless handle_exception($!)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
result.add_run
|
|
104
|
+
yield(FINISHED, name)
|
|
105
|
+
ensure
|
|
106
|
+
@_result = nil
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Called before every test method runs. Can be used
|
|
111
|
+
# to set up fixture information.
|
|
112
|
+
def setup
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Called after every test method runs. Can be used to tear
|
|
116
|
+
# down fixture information.
|
|
117
|
+
def teardown
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def default_test
|
|
121
|
+
flunk("No tests were specified")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def size
|
|
125
|
+
1
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Returns a human-readable name for the specific test that
|
|
129
|
+
# this instance of TestCase represents.
|
|
130
|
+
def name
|
|
131
|
+
"#{@method_name}(#{self.class.name})"
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Overridden to return #name.
|
|
135
|
+
def to_s
|
|
136
|
+
name
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# It's handy to be able to compare TestCase instances.
|
|
140
|
+
def ==(other)
|
|
141
|
+
return false unless(other.kind_of?(self.class))
|
|
142
|
+
return false unless(@method_name == other.method_name)
|
|
143
|
+
self.class == other.class
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
private
|
|
147
|
+
def current_result
|
|
148
|
+
@_result
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def handle_exception(exception)
|
|
152
|
+
self.class.exception_handlers.each do |handler|
|
|
153
|
+
return true if send(handler, exception)
|
|
154
|
+
end
|
|
155
|
+
false
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Returns whether this individual test passed or
|
|
159
|
+
# not. Primarily for use in teardown so that artifacts
|
|
160
|
+
# can be left behind if the test fails.
|
|
161
|
+
def passed?
|
|
162
|
+
@test_passed
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def problem_occurred
|
|
166
|
+
@test_passed = false
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def add_assertion
|
|
170
|
+
current_result.add_assertion
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Author:: Nathaniel Talbott.
|
|
3
|
+
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
|
4
|
+
# License:: Ruby license.
|
|
5
|
+
|
|
6
|
+
require 'test/unit/util/observable'
|
|
7
|
+
require 'test/unit/failure'
|
|
8
|
+
require 'test/unit/error'
|
|
9
|
+
require 'test/unit/omission'
|
|
10
|
+
require 'test/unit/pending'
|
|
11
|
+
require 'test/unit/notification'
|
|
12
|
+
|
|
13
|
+
module Test
|
|
14
|
+
module Unit
|
|
15
|
+
module NullResultContainerInitializer
|
|
16
|
+
private
|
|
17
|
+
def initialize_containers
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Collects Test::Unit::Failure and Test::Unit::Error so that
|
|
22
|
+
# they can be displayed to the user. To this end, observers
|
|
23
|
+
# can be added to it, allowing the dynamic updating of, say, a
|
|
24
|
+
# UI.
|
|
25
|
+
class TestResult
|
|
26
|
+
include Util::Observable
|
|
27
|
+
include NullResultContainerInitializer
|
|
28
|
+
include TestResultFailureSupport
|
|
29
|
+
include TestResultErrorSupport
|
|
30
|
+
include TestResultPendingSupport
|
|
31
|
+
include TestResultOmissionSupport
|
|
32
|
+
include TestResultNotificationSupport
|
|
33
|
+
|
|
34
|
+
CHANGED = "CHANGED"
|
|
35
|
+
FAULT = "FAULT"
|
|
36
|
+
|
|
37
|
+
attr_reader :run_count, :assertion_count, :faults
|
|
38
|
+
|
|
39
|
+
# Constructs a new, empty TestResult.
|
|
40
|
+
def initialize
|
|
41
|
+
@run_count, @assertion_count = 0, 0
|
|
42
|
+
@summary_generators = []
|
|
43
|
+
@problem_checkers = []
|
|
44
|
+
@faults = []
|
|
45
|
+
initialize_containers
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Records a test run.
|
|
49
|
+
def add_run
|
|
50
|
+
@run_count += 1
|
|
51
|
+
notify_changed
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Records an individual assertion.
|
|
55
|
+
def add_assertion
|
|
56
|
+
@assertion_count += 1
|
|
57
|
+
notify_changed
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Returns a string contain the recorded runs, assertions,
|
|
61
|
+
# failures and errors in this TestResult.
|
|
62
|
+
def summary
|
|
63
|
+
["#{run_count} tests",
|
|
64
|
+
"#{assertion_count} assertions",
|
|
65
|
+
*@summary_generators.collect {|generator| send(generator)}].join(", ")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def to_s
|
|
69
|
+
summary
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Returns whether or not this TestResult represents
|
|
73
|
+
# successful completion.
|
|
74
|
+
def passed?
|
|
75
|
+
@problem_checkers.all? {|checker| not send(checker)}
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
def notify_changed
|
|
80
|
+
notify_listeners(CHANGED, self)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def notify_fault(fault)
|
|
84
|
+
@faults << fault
|
|
85
|
+
notify_listeners(FAULT, fault)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Nathaniel Talbott.
|
|
4
|
+
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
require 'test/unit/error'
|
|
8
|
+
|
|
9
|
+
module Test
|
|
10
|
+
module Unit
|
|
11
|
+
|
|
12
|
+
# A collection of tests which can be #run.
|
|
13
|
+
#
|
|
14
|
+
# Note: It is easy to confuse a TestSuite instance with
|
|
15
|
+
# something that has a static suite method; I know because _I_
|
|
16
|
+
# have trouble keeping them straight. Think of something that
|
|
17
|
+
# has a suite method as simply providing a way to get a
|
|
18
|
+
# meaningful TestSuite instance.
|
|
19
|
+
class TestSuite
|
|
20
|
+
attr_reader :name, :tests
|
|
21
|
+
|
|
22
|
+
STARTED = name + "::STARTED"
|
|
23
|
+
FINISHED = name + "::FINISHED"
|
|
24
|
+
|
|
25
|
+
# Creates a new TestSuite with the given name.
|
|
26
|
+
def initialize(name="Unnamed TestSuite", test_case=nil)
|
|
27
|
+
@name = name
|
|
28
|
+
@tests = []
|
|
29
|
+
@test_case = test_case
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Runs the tests and/or suites contained in this
|
|
33
|
+
# TestSuite.
|
|
34
|
+
def run(result, &progress_block)
|
|
35
|
+
yield(STARTED, name)
|
|
36
|
+
run_startup(result)
|
|
37
|
+
@tests.each do |test|
|
|
38
|
+
test.run(result, &progress_block)
|
|
39
|
+
end
|
|
40
|
+
run_shutdown(result)
|
|
41
|
+
yield(FINISHED, name)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Adds the test to the suite.
|
|
45
|
+
def <<(test)
|
|
46
|
+
@tests << test
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def delete(test)
|
|
51
|
+
@tests.delete(test)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Retuns the rolled up number of tests in this suite;
|
|
55
|
+
# i.e. if the suite contains other suites, it counts the
|
|
56
|
+
# tests within those suites, not the suites themselves.
|
|
57
|
+
def size
|
|
58
|
+
total_size = 0
|
|
59
|
+
@tests.each { |test| total_size += test.size }
|
|
60
|
+
total_size
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def empty?
|
|
64
|
+
tests.empty?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Overridden to return the name given the suite at
|
|
68
|
+
# creation.
|
|
69
|
+
def to_s
|
|
70
|
+
@name
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# It's handy to be able to compare TestSuite instances.
|
|
74
|
+
def ==(other)
|
|
75
|
+
return false unless(other.kind_of?(self.class))
|
|
76
|
+
return false unless(@name == other.name)
|
|
77
|
+
@tests == other.tests
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
def run_startup(result)
|
|
82
|
+
return if @test_case.nil? or !@test_case.respond_to?(:startup)
|
|
83
|
+
begin
|
|
84
|
+
@test_case.startup
|
|
85
|
+
rescue Exception
|
|
86
|
+
raise unless handle_exception($!, result)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def run_shutdown(result)
|
|
91
|
+
return if @test_case.nil? or !@test_case.respond_to?(:shutdown)
|
|
92
|
+
begin
|
|
93
|
+
@test_case.shutdown
|
|
94
|
+
rescue Exception
|
|
95
|
+
raise unless handle_exception($!, result)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def handle_exception(exception, result)
|
|
100
|
+
case exception
|
|
101
|
+
when *ErrorHandler::PASS_THROUGH_EXCEPTIONS
|
|
102
|
+
false
|
|
103
|
+
else
|
|
104
|
+
result.add_error(Error.new(@test_case.name, exception))
|
|
105
|
+
true
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Nathaniel Talbott.
|
|
4
|
+
# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
require 'test/unit/color'
|
|
8
|
+
require 'test/unit/ui/testrunner'
|
|
9
|
+
require 'test/unit/ui/testrunnermediator'
|
|
10
|
+
require 'test/unit/ui/console/outputlevel'
|
|
11
|
+
|
|
12
|
+
module Test
|
|
13
|
+
module Unit
|
|
14
|
+
module UI
|
|
15
|
+
module Console
|
|
16
|
+
|
|
17
|
+
# Runs a Test::Unit::TestSuite on the console.
|
|
18
|
+
class TestRunner < UI::TestRunner
|
|
19
|
+
include OutputLevel
|
|
20
|
+
|
|
21
|
+
COLOR_SCHEMES = {
|
|
22
|
+
:default => {
|
|
23
|
+
"success" => Color.new("green", :bold => true),
|
|
24
|
+
"failure" => Color.new("red", :bold => true),
|
|
25
|
+
"pending" => Color.new("magenta", :bold => true),
|
|
26
|
+
"omission" => Color.new("blue", :bold => true),
|
|
27
|
+
"notification" => Color.new("cyan", :bold => true),
|
|
28
|
+
"error" => Color.new("yellow", :bold => true),
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Creates a new TestRunner for running the passed
|
|
33
|
+
# suite. If quiet_mode is true, the output while
|
|
34
|
+
# running is limited to progress dots, errors and
|
|
35
|
+
# failures, and the final result. io specifies
|
|
36
|
+
# where runner output should go to; defaults to
|
|
37
|
+
# STDOUT.
|
|
38
|
+
def initialize(suite, options={})
|
|
39
|
+
super
|
|
40
|
+
@output_level = @options[:output_level] || NORMAL
|
|
41
|
+
@output = @options[:output] || STDOUT
|
|
42
|
+
@use_color = @options[:use_color]
|
|
43
|
+
@use_color = guess_color_availability if @use_color.nil?
|
|
44
|
+
@color_scheme = COLOR_SCHEMES[:default]
|
|
45
|
+
@reset_color = Color.new("reset")
|
|
46
|
+
@already_outputted = false
|
|
47
|
+
@faults = []
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Begins the test run.
|
|
51
|
+
def start
|
|
52
|
+
setup_mediator
|
|
53
|
+
attach_to_mediator
|
|
54
|
+
return start_mediator
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
def setup_mediator
|
|
59
|
+
@mediator = create_mediator(@suite)
|
|
60
|
+
output_setup_end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def output_setup_end
|
|
64
|
+
suite_name = @suite.to_s
|
|
65
|
+
suite_name = @suite.name if @suite.kind_of?(Module)
|
|
66
|
+
output("Loaded suite #{suite_name}")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def create_mediator(suite)
|
|
70
|
+
return TestRunnerMediator.new(suite)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def attach_to_mediator
|
|
74
|
+
@mediator.add_listener(TestResult::FAULT, &method(:add_fault))
|
|
75
|
+
@mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
|
|
76
|
+
@mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
|
|
77
|
+
@mediator.add_listener(TestCase::STARTED, &method(:test_started))
|
|
78
|
+
@mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def start_mediator
|
|
82
|
+
return @mediator.run_suite
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def add_fault(fault)
|
|
86
|
+
@faults << fault
|
|
87
|
+
output_single(fault.single_character_display,
|
|
88
|
+
fault_color(fault),
|
|
89
|
+
PROGRESS_ONLY)
|
|
90
|
+
@already_outputted = true
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def started(result)
|
|
94
|
+
@result = result
|
|
95
|
+
output_started
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def output_started
|
|
99
|
+
output("Started")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def finished(elapsed_time)
|
|
103
|
+
nl if output?(NORMAL) and !output?(VERBOSE)
|
|
104
|
+
nl
|
|
105
|
+
output("Finished in #{elapsed_time} seconds.")
|
|
106
|
+
@faults.each_with_index do |fault, index|
|
|
107
|
+
nl
|
|
108
|
+
output_single("%3d) " % (index + 1))
|
|
109
|
+
label, detail = format_fault(fault).split(/\r?\n/, 2)
|
|
110
|
+
output(label, fault_color(fault))
|
|
111
|
+
output(detail)
|
|
112
|
+
end
|
|
113
|
+
nl
|
|
114
|
+
output(@result, result_color)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def format_fault(fault)
|
|
118
|
+
fault.long_display
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_started(name)
|
|
122
|
+
output_single(name + ": ", nil, VERBOSE)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_finished(name)
|
|
126
|
+
unless @already_outputted
|
|
127
|
+
output_single(".", @color_scheme["success"], PROGRESS_ONLY)
|
|
128
|
+
end
|
|
129
|
+
nl(VERBOSE)
|
|
130
|
+
@already_outputted = false
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def nl(level=NORMAL)
|
|
134
|
+
output("", nil, level)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def output(something, color=nil, level=NORMAL)
|
|
138
|
+
return unless output?(level)
|
|
139
|
+
output_single(something, color, level)
|
|
140
|
+
@output.puts
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def output_single(something, color=nil, level=NORMAL)
|
|
144
|
+
return unless output?(level)
|
|
145
|
+
if @use_color and color
|
|
146
|
+
something = "%s%s%s" % [color.escape_sequence,
|
|
147
|
+
something,
|
|
148
|
+
@reset_color.escape_sequence]
|
|
149
|
+
end
|
|
150
|
+
@output.write(something)
|
|
151
|
+
@output.flush
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def output?(level)
|
|
155
|
+
level <= @output_level
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def fault_color(fault)
|
|
159
|
+
@color_scheme[fault.class.name.split(/::/).last.downcase]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def result_color
|
|
163
|
+
if @result.passed?
|
|
164
|
+
if @result.pending_count > 0
|
|
165
|
+
@color_scheme["pending"]
|
|
166
|
+
elsif @result.omission_count > 0
|
|
167
|
+
@color_scheme["omission"]
|
|
168
|
+
elsif @result.notification_count > 0
|
|
169
|
+
@color_scheme["notification"]
|
|
170
|
+
else
|
|
171
|
+
@color_scheme["success"]
|
|
172
|
+
end
|
|
173
|
+
elsif @result.error_count > 0
|
|
174
|
+
@color_scheme["error"]
|
|
175
|
+
elsif @result.failure_count > 0
|
|
176
|
+
@color_scheme["failure"]
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def guess_color_availability
|
|
181
|
+
return false unless @output.tty?
|
|
182
|
+
term = ENV["TERM"]
|
|
183
|
+
return true if term and (/term\z/ =~ term or term == "screen")
|
|
184
|
+
return true if ENV["EMACS"] == "t"
|
|
185
|
+
false
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
if __FILE__ == $0
|
|
194
|
+
Test::Unit::UI::Console::TestRunner.start_command_line_test
|
|
195
|
+
end
|