activeldap 0.10.0 → 1.0.0
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 +6 -30
- data/README +4 -2
- data/Rakefile +7 -0
- 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 +3 -3
- data/examples/al-admin/po/ja/al-admin.po +3 -3
- data/examples/al-admin/po/nl/al-admin.po +3 -3
- data/lib/active_ldap/adapter/base.rb +0 -2
- data/lib/active_ldap/base.rb +4 -2
- data/lib/active_ldap/get_text_support.rb +3 -11
- data/lib/active_ldap/operations.rb +1 -0
- data/lib/active_ldap/schema/syntaxes.rb +5 -3
- data/lib/active_ldap/validations.rb +25 -15
- data/lib/active_ldap.rb +1 -1
- data/po/en/active-ldap.po +1 -1
- data/po/ja/active-ldap.po +1 -1
- data/rails/plugin/active_ldap/init.rb +1 -1
- data/test/run-test.rb +2 -0
- data/test/test_base.rb +63 -1
- data/test/test_syntax.rb +3 -2
- data/test-unit-ext/NEWS.en +28 -0
- data/test-unit-ext/NEWS.ja +28 -0
- data/test-unit-ext/README.en +247 -0
- data/test-unit-ext/README.ja +246 -0
- data/test-unit-ext/Rakefile +111 -0
- data/{test → test-unit-ext/lib}/test-unit-ext/always-show-result.rb +0 -0
- data/test-unit-ext/lib/test-unit-ext/assertions.rb +40 -0
- data/test-unit-ext/lib/test-unit-ext/attributes.rb +129 -0
- data/{test → test-unit-ext/lib}/test-unit-ext/backtrace-filter.rb +0 -0
- data/test-unit-ext/lib/test-unit-ext/color.rb +59 -0
- data/test-unit-ext/lib/test-unit-ext/colorized-runner.rb +111 -0
- data/test-unit-ext/lib/test-unit-ext/diff.rb +516 -0
- data/{test → test-unit-ext/lib}/test-unit-ext/long-display-for-emacs.rb +0 -0
- data/test-unit-ext/lib/test-unit-ext/notification.rb +79 -0
- data/test-unit-ext/lib/test-unit-ext/omission.rb +96 -0
- data/test-unit-ext/lib/test-unit-ext/pending.rb +97 -0
- data/{test → test-unit-ext/lib}/test-unit-ext/priority.rb +25 -53
- data/test-unit-ext/lib/test-unit-ext/version.rb +3 -0
- data/test-unit-ext/lib/test-unit-ext/xml-report.rb +224 -0
- data/test-unit-ext/lib/test-unit-ext.rb +16 -0
- data/test-unit-ext/misc/rd2html.rb +42 -0
- data/test-unit-ext/test/run-test.rb +14 -0
- data/test-unit-ext/test/test_attributes.rb +139 -0
- data/test-unit-ext/test/test_color.rb +39 -0
- data/test-unit-ext/test/test_diff.rb +475 -0
- data/test-unit-ext/test/test_notification.rb +32 -0
- data/test-unit-ext/test/test_omission.rb +64 -0
- data/test-unit-ext/test/test_pending.rb +64 -0
- data/test-unit-ext/test/test_priority.rb +88 -0
- data/test-unit-ext/test/test_xml_report.rb +161 -0
- metadata +34 -7
- data/test/test-unit-ext.rb +0 -4
@@ -0,0 +1,97 @@
|
|
1
|
+
module Test
|
2
|
+
module Unit
|
3
|
+
class TestResult
|
4
|
+
attr_reader :pendings
|
5
|
+
|
6
|
+
alias_method(:initialize_without_pendings, :initialize)
|
7
|
+
def initialize
|
8
|
+
initialize_without_pendings
|
9
|
+
@pendings = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_pending(pending)
|
13
|
+
@pendings << pending
|
14
|
+
notify_listeners(FAULT, pending)
|
15
|
+
notify_listeners(CHANGED, self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def pending_count
|
19
|
+
@pendings.size
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method(:to_s_without_pendings, :to_s)
|
23
|
+
def to_s
|
24
|
+
to_s_without_pendings + ", #{pending_count} pendings"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Pending
|
29
|
+
include Util::BacktraceFilter
|
30
|
+
attr_reader :test_name, :location, :message
|
31
|
+
|
32
|
+
SINGLE_CHARACTER = 'P'
|
33
|
+
|
34
|
+
# Creates a new Pending with the given location and
|
35
|
+
# message.
|
36
|
+
def initialize(test_name, location, message)
|
37
|
+
@test_name = test_name
|
38
|
+
@location = location
|
39
|
+
@message = message
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a single character representation of a pending.
|
43
|
+
def single_character_display
|
44
|
+
SINGLE_CHARACTER
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns a brief version of the error description.
|
48
|
+
def short_display
|
49
|
+
"#@test_name: #{@message.split("\n")[0]}"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns a verbose version of the error description.
|
53
|
+
def long_display
|
54
|
+
location_display = filter_backtrace(location)[0]
|
55
|
+
location_display = location_display.sub(/\A(.+:\d+).*/, ' [\\1]')
|
56
|
+
"Pending:\n#{@test_name}#{location_display}:\n#{@message}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Overridden to return long_display.
|
60
|
+
def to_s
|
61
|
+
long_display
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class PendedError < StandardError
|
66
|
+
end
|
67
|
+
|
68
|
+
module AssertionsWithPend
|
69
|
+
def pend(message="Pended", &block)
|
70
|
+
if block_given?
|
71
|
+
begin
|
72
|
+
yield
|
73
|
+
rescue Exception
|
74
|
+
raise PendedError, message, $!.backtrace
|
75
|
+
end
|
76
|
+
flunk("Pending block should not be passed: #{message}")
|
77
|
+
else
|
78
|
+
raise PendedError.new(message)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class TestCase
|
84
|
+
include AssertionsWithPend
|
85
|
+
|
86
|
+
alias_method(:add_error_without_pending, :add_error)
|
87
|
+
def add_error(exception)
|
88
|
+
if exception.is_a?(PendedError)
|
89
|
+
pending = Pending.new(name, exception.backtrace, exception.message)
|
90
|
+
@_result.add_pending(pending)
|
91
|
+
else
|
92
|
+
add_error_without_pending(exception)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,53 +1,25 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
|
3
3
|
require "fileutils"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
require "test-unit-ext/attributes"
|
4
7
|
|
5
8
|
module Test
|
6
9
|
module Unit
|
7
10
|
class TestCase
|
8
11
|
class << self
|
9
|
-
def inherited(sub)
|
10
|
-
super
|
11
|
-
sub.instance_variable_set("@priority_initialized", true)
|
12
|
-
sub.instance_variable_set("@priority_table", {})
|
13
|
-
sub.priority :normal
|
14
|
-
end
|
15
|
-
|
16
|
-
def include(*args)
|
17
|
-
args.reverse_each do |mod|
|
18
|
-
super(mod)
|
19
|
-
next unless defined?(@priority_initialized)
|
20
|
-
mod.instance_methods(false).each do |name|
|
21
|
-
set_priority(name)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
alias_method :method_added_without_priority, :method_added
|
27
|
-
def method_added(name)
|
28
|
-
method_added_without_priority(name)
|
29
|
-
set_priority(name) if defined?(@priority_initialized)
|
30
|
-
end
|
31
|
-
|
32
12
|
def priority(name, *tests)
|
33
13
|
singleton_class = (class << self; self; end)
|
34
14
|
priority_check_method = priority_check_method_name(name)
|
35
15
|
unless singleton_class.private_method_defined?(priority_check_method)
|
36
16
|
raise ArgumentError, "unknown priority: #{name}"
|
37
17
|
end
|
38
|
-
|
39
|
-
@current_priority = name
|
40
|
-
else
|
41
|
-
tests.each do |test|
|
42
|
-
set_priority(test, name)
|
43
|
-
end
|
44
|
-
end
|
18
|
+
attribute(:priority, name, {:keep => true}, *tests)
|
45
19
|
end
|
46
20
|
|
47
21
|
def need_to_run?(test_name)
|
48
|
-
|
49
|
-
priority = @priority_table[normalized_test_name]
|
50
|
-
return true unless priority
|
22
|
+
priority = (attributes(test_name) || {})[:priority] || :normal
|
51
23
|
__send__(priority_check_method_name(priority), test_name)
|
52
24
|
end
|
53
25
|
|
@@ -56,10 +28,6 @@ module Test
|
|
56
28
|
"run_priority_#{priority_name}?"
|
57
29
|
end
|
58
30
|
|
59
|
-
def normalize_test_name(test_name)
|
60
|
-
"test_#{test_name.to_s.sub(/^test_/, '')}"
|
61
|
-
end
|
62
|
-
|
63
31
|
def set_priority(name, priority=@current_priority)
|
64
32
|
@priority_table[normalize_test_name(name)] = priority
|
65
33
|
end
|
@@ -93,9 +61,9 @@ module Test
|
|
93
61
|
!previous_test_success? or self.class.need_to_run?(@method_name)
|
94
62
|
end
|
95
63
|
|
96
|
-
alias_method :
|
64
|
+
alias_method :run_without_priority, :run
|
97
65
|
def run(result, &block)
|
98
|
-
|
66
|
+
run_without_priority(result, &block)
|
99
67
|
ensure
|
100
68
|
if passed?
|
101
69
|
FileUtils.touch(passed_file)
|
@@ -111,18 +79,22 @@ module Test
|
|
111
79
|
|
112
80
|
def result_dir
|
113
81
|
components = [".test-result", self.class.name, @method_name.to_s]
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
82
|
+
parent_directories = [File.dirname($0),
|
83
|
+
File.join(File.dirname(__FILE__), ".."),
|
84
|
+
Dir.pwd]
|
85
|
+
if Process.respond_to?(:uid)
|
86
|
+
parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
|
87
|
+
end
|
88
|
+
parent_directories.each do |parent_directory|
|
89
|
+
dir = File.expand_path(File.join(parent_directory, *components))
|
90
|
+
begin
|
91
|
+
FileUtils.mkdir_p(dir)
|
92
|
+
return dir
|
93
|
+
rescue Errno::EACCES
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
raise Errno::EACCES, parent_directories.join(", ")
|
126
98
|
end
|
127
99
|
|
128
100
|
def passed_file
|
@@ -150,14 +122,14 @@ module Test
|
|
150
122
|
end
|
151
123
|
end
|
152
124
|
|
153
|
-
alias_method :
|
125
|
+
alias_method :run_without_priority_support, :run
|
154
126
|
def run(*args, &block)
|
155
127
|
priority_mode = @@priority_mode
|
156
128
|
if priority_mode
|
157
129
|
@original_tests = @tests
|
158
130
|
apply_priority
|
159
131
|
end
|
160
|
-
|
132
|
+
run_without_priority_support(*args, &block)
|
161
133
|
ensure
|
162
134
|
@tests = @original_tests if priority_mode
|
163
135
|
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "test/unit/failure"
|
3
|
+
require "test/unit/error"
|
4
|
+
require "test/unit/testresult"
|
5
|
+
require "test/unit/testsuite"
|
6
|
+
require "test/unit/autorunner"
|
7
|
+
|
8
|
+
module Test
|
9
|
+
module Unit
|
10
|
+
module XMLReportable
|
11
|
+
include ERB::Util
|
12
|
+
|
13
|
+
def to_xml
|
14
|
+
<<-XML.gsub(/\s*(\n <\/test>|\n<\/result>)/m, "\\1")
|
15
|
+
<result>
|
16
|
+
<test_case>
|
17
|
+
<name>#{h(@test.class.name)}</name>
|
18
|
+
<description/>
|
19
|
+
</test_case>
|
20
|
+
<test>
|
21
|
+
<name>#{h(@test.method_name)}</name>
|
22
|
+
<description/>
|
23
|
+
#{options_xml}
|
24
|
+
</test>
|
25
|
+
<status>#{h(status_name)}</status>
|
26
|
+
<detail>#{h(message)}</detail>
|
27
|
+
<elapsed>#{h(elapsed_time)}</elapsed>
|
28
|
+
#{backtrace_xml}
|
29
|
+
</result>
|
30
|
+
XML
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def options_xml
|
35
|
+
@test.attributes.collect do |key, value|
|
36
|
+
<<-XML
|
37
|
+
<option>
|
38
|
+
<name>#{h(key)}</name>
|
39
|
+
<value>#{h(value)}</value>
|
40
|
+
</option>
|
41
|
+
XML
|
42
|
+
end.join
|
43
|
+
end
|
44
|
+
|
45
|
+
def backtrace_xml
|
46
|
+
entries = backtrace_entries_xml
|
47
|
+
if entries.empty?
|
48
|
+
""
|
49
|
+
else
|
50
|
+
<<-XML
|
51
|
+
<backtrace>
|
52
|
+
#{entries.join.rstrip}
|
53
|
+
</backtrace>
|
54
|
+
XML
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def backtrace_entries_xml
|
59
|
+
location.collect do |location|
|
60
|
+
file, line, info = location.split(/:(\d+):/)
|
61
|
+
<<-XML
|
62
|
+
<entry>
|
63
|
+
<file>#{h(file)}</file>
|
64
|
+
<line>#{h(line)}</line>
|
65
|
+
<info>#{h(info.to_s.strip)}</info>
|
66
|
+
</entry>
|
67
|
+
XML
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Success
|
73
|
+
include XMLReportable
|
74
|
+
|
75
|
+
attr_reader :test, :elapsed_time
|
76
|
+
def initialize(test, elapsed_time)
|
77
|
+
@test = test
|
78
|
+
@elapsed_time = elapsed_time
|
79
|
+
end
|
80
|
+
|
81
|
+
def message
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def location
|
86
|
+
[]
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_name
|
90
|
+
@test.name
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_case_name
|
94
|
+
/\((.*)\)\z/ =~ test_name
|
95
|
+
$1
|
96
|
+
end
|
97
|
+
|
98
|
+
def status_name
|
99
|
+
"success"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Failure
|
104
|
+
include XMLReportable
|
105
|
+
|
106
|
+
attr_accessor :test, :elapsed_time
|
107
|
+
|
108
|
+
def status_name
|
109
|
+
"failure"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Error
|
114
|
+
include XMLReportable
|
115
|
+
|
116
|
+
attr_accessor :test, :elapsed_time
|
117
|
+
|
118
|
+
def status_name
|
119
|
+
"error"
|
120
|
+
end
|
121
|
+
|
122
|
+
def location
|
123
|
+
filter_backtrace(@exception.backtrace)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class TestCase
|
128
|
+
alias_method(:run_without_success_notify, :run)
|
129
|
+
def run(result, &block)
|
130
|
+
@_start_time = Time.now
|
131
|
+
run_result = run_without_success_notify(result, &block)
|
132
|
+
result.add_success(Success.new(self, Time.now - @_start_time)) if passed?
|
133
|
+
run_result
|
134
|
+
end
|
135
|
+
|
136
|
+
alias_method(:add_failure_without_test_case_set, :add_failure)
|
137
|
+
def add_failure(*args)
|
138
|
+
add_failure_without_test_case_set(*args)
|
139
|
+
failure = @_result.failures.last
|
140
|
+
failure.test = self
|
141
|
+
failure.elapsed_time = Time.now - @_start_time
|
142
|
+
end
|
143
|
+
|
144
|
+
alias_method(:add_error_without_test_case_set, :add_error)
|
145
|
+
def add_error(*args)
|
146
|
+
add_error_without_test_case_set(*args)
|
147
|
+
error = @_result.errors.last
|
148
|
+
error.test = self
|
149
|
+
error.elapsed_time = Time.now - @_start_time
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class TestResult
|
154
|
+
attr_reader :failures, :errors
|
155
|
+
|
156
|
+
alias_method(:initialize_without_successes, :initialize)
|
157
|
+
def initialize
|
158
|
+
initialize_without_successes
|
159
|
+
@successes = []
|
160
|
+
@logs = []
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_success(success)
|
164
|
+
@logs << success
|
165
|
+
@successes << success
|
166
|
+
end
|
167
|
+
|
168
|
+
alias_method(:add_failure_without_logs_store, :add_failure)
|
169
|
+
def add_failure(failure)
|
170
|
+
@logs << failure
|
171
|
+
add_failure_without_logs_store(failure)
|
172
|
+
end
|
173
|
+
|
174
|
+
alias_method(:add_error_without_logs_store, :add_error)
|
175
|
+
def add_error(error)
|
176
|
+
@logs << error
|
177
|
+
add_error_without_logs_store(error)
|
178
|
+
end
|
179
|
+
|
180
|
+
def to_xml
|
181
|
+
return "<report/>" if @logs.empty?
|
182
|
+
xml = @logs.collect {|log| log.to_xml.gsub(/^/, " ")}.join
|
183
|
+
"<report>\n#{xml}</report>\n"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
class TestSuite
|
188
|
+
attr_reader :result
|
189
|
+
|
190
|
+
alias_method(:run_without_keep_result, :run)
|
191
|
+
def run(result, &block)
|
192
|
+
@result = result
|
193
|
+
run_without_keep_result(result, &block)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
class AutoRunner
|
198
|
+
alias_method(:options_without_xml_report_support, :options)
|
199
|
+
def options
|
200
|
+
opt = options_without_xml_report_support
|
201
|
+
@xml_report_support_option_added ||= false
|
202
|
+
unless @xml_report_support_option_added
|
203
|
+
@xml_report_file = nil
|
204
|
+
opt.on('--xml-report=FILE',
|
205
|
+
"Output test report in XML to FILE.") do |file|
|
206
|
+
@xml_report_file = file
|
207
|
+
end
|
208
|
+
end
|
209
|
+
opt
|
210
|
+
end
|
211
|
+
|
212
|
+
alias_method(:run_without_xml_report_support, :run)
|
213
|
+
def run
|
214
|
+
passed = run_without_xml_report_support
|
215
|
+
if @xml_report_file
|
216
|
+
File.open(@xml_report_file, "w") do |f|
|
217
|
+
f.print(@suite.result.to_xml)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
passed
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require "test-unit-ext/version"
|
4
|
+
require "test-unit-ext/color"
|
5
|
+
require "test-unit-ext/colorized-runner"
|
6
|
+
require "test-unit-ext/diff"
|
7
|
+
require "test-unit-ext/always-show-result"
|
8
|
+
require "test-unit-ext/attributes"
|
9
|
+
require "test-unit-ext/priority"
|
10
|
+
require "test-unit-ext/backtrace-filter"
|
11
|
+
require "test-unit-ext/long-display-for-emacs"
|
12
|
+
require "test-unit-ext/xml-report"
|
13
|
+
require "test-unit-ext/assertions"
|
14
|
+
require "test-unit-ext/pending"
|
15
|
+
require "test-unit-ext/omission"
|
16
|
+
require "test-unit-ext/notification"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
4
|
+
html_dir = File.join(top, "html")
|
5
|
+
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
css = "base.css"
|
9
|
+
kcode = "utf8"
|
10
|
+
|
11
|
+
options = [
|
12
|
+
"-I#{File.join(top, 'misc')}",
|
13
|
+
"-S",
|
14
|
+
"rd2",
|
15
|
+
"-rrd/rd2html-lib",
|
16
|
+
"--out-code=#{kcode}",
|
17
|
+
proc do |f|
|
18
|
+
"--html-title=#{File.basename(f)}"
|
19
|
+
end,
|
20
|
+
# proc do |f|
|
21
|
+
# "--with-css=#{css}"
|
22
|
+
# end,
|
23
|
+
proc do |f|
|
24
|
+
f
|
25
|
+
end
|
26
|
+
]
|
27
|
+
|
28
|
+
Dir[File.join(top, "*.{ja,en}")].each do |f|
|
29
|
+
if /(README|NEWS)\.(ja|en)\z/ =~ f
|
30
|
+
args = options.collect do |x|
|
31
|
+
if x.respond_to?(:call)
|
32
|
+
x.call(f)
|
33
|
+
else
|
34
|
+
x
|
35
|
+
end
|
36
|
+
end
|
37
|
+
output_base = File.basename(f).downcase.sub(/(ja|en)\z/, "html.\\1")
|
38
|
+
File.open(File.join(html_dir, output_base), "w") do |out|
|
39
|
+
out.puts(`ruby #{args.flatten.join(' ')}`)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift("./lib")
|
4
|
+
$LOAD_PATH.unshift("./test")
|
5
|
+
|
6
|
+
require "test-unit-ext"
|
7
|
+
|
8
|
+
Dir.glob("test/**/test_*.rb") do |test|
|
9
|
+
begin
|
10
|
+
require test
|
11
|
+
rescue LoadError
|
12
|
+
puts "Can't load: #{test}: #{$!.message}"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test-unit-ext'
|
2
|
+
|
3
|
+
class TestAttributes < Test::Unit::TestCase
|
4
|
+
class TestStack < Test::Unit::TestCase
|
5
|
+
class << self
|
6
|
+
def suite
|
7
|
+
Test::Unit::TestSuite.new(name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Stack
|
12
|
+
def initialize
|
13
|
+
@data = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def push(data)
|
17
|
+
@data.push(data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def peek
|
21
|
+
@data[-2]
|
22
|
+
end
|
23
|
+
|
24
|
+
def empty?
|
25
|
+
@data.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def size
|
29
|
+
@data.size + 11
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup
|
34
|
+
@stack = Stack.new
|
35
|
+
end
|
36
|
+
|
37
|
+
attribute :category, :accessor
|
38
|
+
def test_peek
|
39
|
+
@stack.push(1)
|
40
|
+
@stack.push(2)
|
41
|
+
assert_equal(2, @stack.peek)
|
42
|
+
end
|
43
|
+
|
44
|
+
attribute :bug, 1234
|
45
|
+
def test_bug_1234
|
46
|
+
assert_equal(0, @stack.size)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_no_attributes
|
50
|
+
assert(@stack.empty?)
|
51
|
+
@stack.push(1)
|
52
|
+
assert(!@stack.empty?)
|
53
|
+
assert_equal(1, @stack.size)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_set_attributes
|
58
|
+
test_for_bug_1234 = TestStack.new("test_bug_1234")
|
59
|
+
assert_equal({:bug => 1234}, test_for_bug_1234.attributes)
|
60
|
+
|
61
|
+
test_no_attributes = TestStack.new("test_no_attributes")
|
62
|
+
assert_equal({}, test_no_attributes.attributes)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_show_attributes
|
66
|
+
assert_stack_size_line = search_line('assert_equal(0, @stack.size)')
|
67
|
+
assert_peek_line = search_line('assert_equal(2, @stack.peek)')
|
68
|
+
first_arg_end_line = search_line("\"+ 11\"],")
|
69
|
+
method_name = "test_show_attributes"
|
70
|
+
assert_result(["Failure:\n" \
|
71
|
+
"test_peek(TestAttributes::TestStack)\n" \
|
72
|
+
" category: accessor\n" \
|
73
|
+
"#{__FILE__}:#{assert_peek_line}:in `test_peek'\n" \
|
74
|
+
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
75
|
+
"<2> expected but was\n" \
|
76
|
+
"<1>.\n" \
|
77
|
+
"\n" \
|
78
|
+
"diff:\n" \
|
79
|
+
"- 2\n" \
|
80
|
+
"+ 1",
|
81
|
+
"Failure:\n" \
|
82
|
+
"test_bug_1234(TestAttributes::TestStack)\n" \
|
83
|
+
" bug: 1234\n" \
|
84
|
+
"#{__FILE__}:#{assert_stack_size_line}:in `test_bug_1234'\n" \
|
85
|
+
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
86
|
+
"<0> expected but was\n" \
|
87
|
+
"<11>.\n" \
|
88
|
+
"\n" \
|
89
|
+
"diff:\n" \
|
90
|
+
"- 0\n" \
|
91
|
+
"+ 11"],
|
92
|
+
[],
|
93
|
+
["test_peek", "test_bug_1234"])
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_not_show_attributes
|
97
|
+
assert_line = search_line('assert_equal(1, @stack.size')
|
98
|
+
first_arg_end_line = search_line("\"+ 12\"],")
|
99
|
+
method_name = "test_not_show_attributes"
|
100
|
+
assert_result(["Failure:\n" \
|
101
|
+
"test_no_attributes(TestAttributes::TestStack)\n" \
|
102
|
+
"#{__FILE__}:#{assert_line}:in `test_no_attributes'\n" \
|
103
|
+
"#{__FILE__}:#{first_arg_end_line}:in `#{method_name}':\n" \
|
104
|
+
"<1> expected but was\n" \
|
105
|
+
"<12>.\n" \
|
106
|
+
"\n" \
|
107
|
+
"diff:\n" \
|
108
|
+
"- 1\n" \
|
109
|
+
"+ 12"],
|
110
|
+
[],
|
111
|
+
["test_no_attributes"])
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
def search_line(pattern)
|
116
|
+
if pattern.is_a?(String)
|
117
|
+
pattern = /#{Regexp.escape(pattern)}/
|
118
|
+
end
|
119
|
+
File.open(__FILE__) do |file|
|
120
|
+
while line = file.gets
|
121
|
+
return file.lineno if pattern =~ line
|
122
|
+
end
|
123
|
+
end
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def assert_result(failure_results, error_results, names)
|
128
|
+
tests = names.collect {|name| TestStack.new(name)}
|
129
|
+
result = Test::Unit::TestResult.new
|
130
|
+
mark = /\A#{Regexp.escape(__FILE__)}:#{__LINE__ + 1}/
|
131
|
+
tests.each {|test| test.run(result) {}}
|
132
|
+
failures = result.instance_variable_get("@failures")
|
133
|
+
errors = result.instance_variable_get("@errors")
|
134
|
+
failures.each {|f| f.location.reject! {|l| mark =~ l}}
|
135
|
+
assert_equal([failure_results, error_results],
|
136
|
+
[failures.collect {|failure| failure.long_display},
|
137
|
+
errors.collect {|error| error.long_display}])
|
138
|
+
end
|
139
|
+
end
|