utilrb 2.0.2.b2 → 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.boring +40 -0
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/CMakeLists.txt +18 -0
- data/Gemfile +3 -0
- data/Makefile +8 -0
- data/Manifest.txt +0 -8
- data/{README.rd → README.md} +11 -7
- data/Rakefile +16 -63
- data/benchmarks/validate_options.rb +79 -0
- data/ext/utilrb/extconf.rb +1 -17
- data/ext/utilrb/utilrb.cc +0 -23
- data/lib/utilrb/column_formatter.rb +8 -5
- data/lib/utilrb/common.rb +1 -6
- data/lib/utilrb/enumerable/uniq.rb +2 -8
- data/lib/utilrb/event_loop.rb +5 -10
- data/lib/utilrb/kernel/load_dsl_file.rb +1 -2
- data/lib/utilrb/kernel/options.rb +25 -29
- data/lib/utilrb/logger/hierarchy.rb +0 -1
- data/lib/utilrb/logger/io.rb +3 -3
- data/lib/utilrb/logger/root.rb +12 -6
- data/lib/utilrb/module/ancestor_p.rb +0 -12
- data/lib/utilrb/module/is_singleton.rb +6 -0
- data/lib/utilrb/module/singleton_class_p.rb +14 -0
- data/lib/utilrb/object/attribute.rb +33 -65
- data/lib/utilrb/object/singleton_class.rb +1 -20
- data/lib/utilrb/pkgconfig.rb +21 -10
- data/lib/utilrb/socket/tcp_server.rb +2 -2
- data/lib/utilrb/spawn.rb +1 -1
- data/lib/utilrb/test.rb +65 -0
- data/lib/utilrb/thread_pool.rb +11 -13
- data/lib/utilrb/timepoints.rb +15 -0
- data/lib/utilrb/value_set.rb +10 -1
- data/lib/utilrb/version.rb +4 -0
- data/lib/utilrb/weakref.rb +11 -12
- data/lib/utilrb/yard.rb +0 -111
- data/lib/utilrb.rb +6 -1
- data/lib/yard-utilrb.rb +1 -0
- data/manifest.xml +19 -0
- data/package.xml +29 -0
- data/utilrb.gemspec +27 -0
- metadata +56 -107
- data/ext/utilrb/proc.c +0 -39
- data/ext/utilrb/readline.c +0 -52
- data/ext/utilrb/weakref.cc +0 -143
- data/lib/utilrb/models/inherited_enumerable.rb +0 -341
- data/lib/utilrb/models/registration.rb +0 -115
- data/lib/utilrb/module/inherited_enumerable.rb +0 -6
- data/lib/utilrb/objectstats.rb +0 -193
- data/lib/utilrb/ruby_object_graph.rb +0 -384
- data/test/data/test_pkgconfig.pc +0 -9
- data/test/data/test_pkgconfig_empty.pc +0 -10
- data/test/test_array.rb +0 -15
- data/test/test_config.rb +0 -4
- data/test/test_dir.rb +0 -22
- data/test/test_enumerable.rb +0 -119
- data/test/test_event_loop.rb +0 -407
- data/test/test_exception.rb +0 -38
- data/test/test_gc.rb +0 -34
- data/test/test_hash.rb +0 -102
- data/test/test_kernel.rb +0 -300
- data/test/test_logger.rb +0 -204
- data/test/test_misc.rb +0 -42
- data/test/test_models.rb +0 -212
- data/test/test_module.rb +0 -126
- data/test/test_object.rb +0 -77
- data/test/test_objectstats.rb +0 -26
- data/test/test_pkgconfig.rb +0 -84
- data/test/test_proc.rb +0 -31
- data/test/test_set.rb +0 -19
- data/test/test_thread_pool.rb +0 -409
- data/test/test_time.rb +0 -47
- data/test/test_unbound_method.rb +0 -23
- data/test/test_weakref.rb +0 -81
data/test/test_kernel.rb
DELETED
@@ -1,300 +0,0 @@
|
|
1
|
-
require './test/test_config'
|
2
|
-
require 'flexmock'
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
require 'utilrb/kernel'
|
6
|
-
|
7
|
-
require 'flexmock/test_unit'
|
8
|
-
|
9
|
-
class TC_Kernel < Test::Unit::TestCase
|
10
|
-
# Do NOT move this block. Some tests are checking the error lines in the
|
11
|
-
# backtraces
|
12
|
-
DSL_EXEC_BLOCK = Proc.new do
|
13
|
-
real_method
|
14
|
-
if KnownConstant != 10
|
15
|
-
raise ArgumentError, "invalid constant value"
|
16
|
-
end
|
17
|
-
class Submod::Klass
|
18
|
-
def my_method
|
19
|
-
end
|
20
|
-
end
|
21
|
-
name('test')
|
22
|
-
unknown_method()
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_validate_options
|
26
|
-
valid_options = [ :a, :b, :c ]
|
27
|
-
valid_test = { :a => 1, :c => 2 }
|
28
|
-
invalid_test = { :k => nil }
|
29
|
-
assert_nothing_raised(ArgumentError) { validate_options(valid_test, valid_options) }
|
30
|
-
assert_raise(ArgumentError) { validate_options(invalid_test, valid_options) }
|
31
|
-
|
32
|
-
check_array = validate_options( valid_test, valid_options )
|
33
|
-
assert_equal( valid_test, check_array )
|
34
|
-
check_empty_array = validate_options( nil, valid_options )
|
35
|
-
assert_equal( {}, check_empty_array )
|
36
|
-
|
37
|
-
# Check default value settings
|
38
|
-
default_values = { :a => nil, :b => nil, :c => nil, :d => 15, :e => [] }
|
39
|
-
new_options = nil
|
40
|
-
assert_nothing_raised(ArgumentError) { new_options = validate_options(valid_test, default_values) }
|
41
|
-
assert_equal(15, new_options[:d])
|
42
|
-
assert_equal([], new_options[:e])
|
43
|
-
assert( !new_options.has_key?(:b) )
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_arity_of_methods
|
47
|
-
object = Class.new do
|
48
|
-
def arity_1(a); end
|
49
|
-
def arity_any(*a); end
|
50
|
-
def arity_1_more(a, *b); end
|
51
|
-
end.new
|
52
|
-
|
53
|
-
assert_nothing_raised { check_arity(object.method(:arity_1), 1) }
|
54
|
-
assert_raises(ArgumentError) { check_arity(object.method(:arity_1), 0) }
|
55
|
-
assert_raises(ArgumentError) { check_arity(object.method(:arity_1), 2) }
|
56
|
-
|
57
|
-
assert_nothing_raised { check_arity(object.method(:arity_any), 0) }
|
58
|
-
assert_nothing_raised { check_arity(object.method(:arity_any), 2) }
|
59
|
-
|
60
|
-
assert_nothing_raised { check_arity(object.method(:arity_1_more), 1) }
|
61
|
-
assert_raises(ArgumentError) { check_arity(object.method(:arity_1_more), 0) }
|
62
|
-
assert_nothing_raised { check_arity(object.method(:arity_1_more), 2) }
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_arity_of_blocks
|
66
|
-
check_arity(Proc.new { bla }, 0)
|
67
|
-
check_arity(Proc.new { bla }, 1)
|
68
|
-
check_arity(Proc.new { bla }, 2)
|
69
|
-
|
70
|
-
assert_raises(ArgumentError) { check_arity(Proc.new { |arg| bla }, 0) }
|
71
|
-
check_arity(Proc.new { |arg| bla }, 1)
|
72
|
-
assert_raises(ArgumentError) { check_arity(Proc.new { |arg| bla }, 2) }
|
73
|
-
|
74
|
-
assert_raises(ArgumentError) { check_arity(Proc.new { |arg, *args| bla }, 0) }
|
75
|
-
check_arity(Proc.new { |arg, *args| bla }, 1)
|
76
|
-
check_arity(Proc.new { |arg, *args| bla }, 2)
|
77
|
-
|
78
|
-
check_arity(Proc.new { |*args| bla }, 0)
|
79
|
-
check_arity(Proc.new { |*args| bla }, 1)
|
80
|
-
check_arity(Proc.new { |*args| bla }, 2)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_arity_of_lambdas
|
84
|
-
check_arity(lambda { bla }, 0)
|
85
|
-
assert_raises(ArgumentError) { check_arity(lambda { bla }, 1) }
|
86
|
-
assert_raises(ArgumentError) { check_arity(lambda { bla }, 2) }
|
87
|
-
|
88
|
-
assert_raises(ArgumentError) { check_arity(lambda { |arg| bla }, 0) }
|
89
|
-
check_arity(lambda { |arg| bla }, 1)
|
90
|
-
assert_raises(ArgumentError) { check_arity(lambda { |arg| bla }, 2) }
|
91
|
-
|
92
|
-
assert_raises(ArgumentError) { check_arity(lambda { |arg, *args| bla }, 0) }
|
93
|
-
check_arity(lambda { |arg, *args| bla }, 1)
|
94
|
-
check_arity(lambda { |arg, *args| bla }, 2)
|
95
|
-
|
96
|
-
check_arity(lambda { |*args| bla }, 0)
|
97
|
-
check_arity(lambda { |*args| bla }, 1)
|
98
|
-
check_arity(lambda { |*args| bla }, 2)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_with_module
|
102
|
-
obj = Object.new
|
103
|
-
c0, c1 = nil
|
104
|
-
mod0 = Module.new do
|
105
|
-
const_set(:Const, c0 = Object.new)
|
106
|
-
end
|
107
|
-
mod1 = Module.new do
|
108
|
-
const_set(:Const, c1 = Object.new)
|
109
|
-
end
|
110
|
-
|
111
|
-
eval_string = "Const"
|
112
|
-
const_val = obj.with_module(mod0, mod1, eval_string)
|
113
|
-
assert_equal(c0, const_val)
|
114
|
-
const_val = obj.with_module(mod1, mod0, eval_string)
|
115
|
-
assert_equal(c1, const_val)
|
116
|
-
|
117
|
-
const_val = obj.with_module(mod0, mod1) { Const }
|
118
|
-
assert_equal(c0, const_val)
|
119
|
-
const_val = obj.with_module(mod1, mod0) { Const }
|
120
|
-
assert_equal(c1, const_val)
|
121
|
-
|
122
|
-
assert_raises(NameError) { Const }
|
123
|
-
end
|
124
|
-
|
125
|
-
module Mod
|
126
|
-
module Submod
|
127
|
-
class Klass
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
const_set(:KnownConstant, 10)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_eval_dsl_file
|
135
|
-
obj = Class.new do
|
136
|
-
def real_method_called?; !!@real_method_called end
|
137
|
-
def name(value)
|
138
|
-
end
|
139
|
-
def real_method
|
140
|
-
@real_method_called = true
|
141
|
-
end
|
142
|
-
end.new
|
143
|
-
|
144
|
-
Tempfile.open('test_eval_dsl_file') do |io|
|
145
|
-
io.puts <<-EOD
|
146
|
-
real_method
|
147
|
-
if KnownConstant != 10
|
148
|
-
raise ArgumentError, "invalid constant value"
|
149
|
-
end
|
150
|
-
class Submod::Klass
|
151
|
-
def my_method
|
152
|
-
end
|
153
|
-
end
|
154
|
-
name('test')
|
155
|
-
unknown_method()
|
156
|
-
EOD
|
157
|
-
io.flush
|
158
|
-
|
159
|
-
begin
|
160
|
-
eval_dsl_file(io.path, obj, [], false)
|
161
|
-
assert(obj.real_method_called?, "the block has not been evaluated")
|
162
|
-
flunk("did not raise NameError for KnownConstant")
|
163
|
-
rescue NameError => e
|
164
|
-
assert e.message =~ /KnownConstant/, e.message
|
165
|
-
assert e.backtrace.first =~ /#{io.path}:2/, "wrong backtrace when checking constant resolution: #{e.backtrace.join("\n")}"
|
166
|
-
end
|
167
|
-
|
168
|
-
begin
|
169
|
-
eval_dsl_file(io.path, obj, [Mod], false)
|
170
|
-
flunk("did not raise NoMethodError for unknown_method")
|
171
|
-
rescue NoMethodError => e
|
172
|
-
assert e.message =~ /unknown_method/
|
173
|
-
assert e.backtrace.first =~ /#{io.path}:10/, "wrong backtrace when checking method resolution: #{e.backtrace.join("\n")}"
|
174
|
-
end
|
175
|
-
|
176
|
-
# instance_methods returns strings on 1.8 and symbols on 1.9. Conver
|
177
|
-
# to strings to have the right assertion on both
|
178
|
-
methods = Mod::Submod::Klass.instance_methods(false).map(&:to_s)
|
179
|
-
assert(methods.include?('my_method'), "the 'class K' statement did not refer to the already defined class")
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_dsl_exec
|
184
|
-
obj = Class.new do
|
185
|
-
def real_method_called?; !!@real_method_called end
|
186
|
-
def name(value)
|
187
|
-
end
|
188
|
-
def real_method
|
189
|
-
@real_method_called = true
|
190
|
-
end
|
191
|
-
end.new
|
192
|
-
|
193
|
-
begin
|
194
|
-
dsl_exec(obj, [], false, &DSL_EXEC_BLOCK)
|
195
|
-
assert(obj.real_method_called?, "the block has not been evaluated")
|
196
|
-
flunk("did not raise NameError for KnownConstant")
|
197
|
-
rescue NameError => e
|
198
|
-
assert e.message =~ /KnownConstant/, e.message
|
199
|
-
expected = "test_kernel.rb:14"
|
200
|
-
assert e.backtrace.first =~ /#{expected}/, "wrong backtrace when checking constant resolution: #{e.backtrace.join("\n")}, expected #{expected}"
|
201
|
-
end
|
202
|
-
|
203
|
-
begin
|
204
|
-
dsl_exec(obj, [Mod], false, &DSL_EXEC_BLOCK)
|
205
|
-
flunk("did not raise NoMethodError for unknown_method")
|
206
|
-
rescue NoMethodError => e
|
207
|
-
assert e.message =~ /unknown_method/
|
208
|
-
expected = "test_kernel.rb:22"
|
209
|
-
assert e.backtrace.first =~ /#{expected}/, "wrong backtrace when checking method resolution: #{e.backtrace[0]}, expected #{expected}"
|
210
|
-
end
|
211
|
-
|
212
|
-
# instance_methods returns strings on 1.8 and symbols on 1.9. Conver
|
213
|
-
# to strings to have the right assertion on both
|
214
|
-
methods = Mod::Submod::Klass.instance_methods(false).map(&:to_s)
|
215
|
-
assert(methods.include?('my_method'), "the 'class K' statement did not refer to the already defined class")
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_load_dsl_file_loaded_features_behaviour
|
219
|
-
eval_context = Class.new do
|
220
|
-
attr_reader :real_method_call_count
|
221
|
-
def initialize
|
222
|
-
@real_method_call_count = 0
|
223
|
-
end
|
224
|
-
def real_method
|
225
|
-
@real_method_call_count += 1
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
Tempfile.open('test_eval_dsl_file') do |io|
|
230
|
-
io.puts <<-EOD
|
231
|
-
real_method
|
232
|
-
EOD
|
233
|
-
io.flush
|
234
|
-
|
235
|
-
obj = eval_context.new
|
236
|
-
assert(Kernel.load_dsl_file(io.path, obj, [], false))
|
237
|
-
assert_equal(1, obj.real_method_call_count)
|
238
|
-
assert($LOADED_FEATURES.include?(io.path))
|
239
|
-
assert(!Kernel.load_dsl_file(io.path, obj, [], false))
|
240
|
-
assert_equal(1, obj.real_method_call_count)
|
241
|
-
|
242
|
-
$LOADED_FEATURES.delete(io.path)
|
243
|
-
end
|
244
|
-
|
245
|
-
Tempfile.open('test_eval_dsl_file') do |io|
|
246
|
-
io.puts <<-EOD
|
247
|
-
raise
|
248
|
-
EOD
|
249
|
-
io.flush
|
250
|
-
|
251
|
-
obj = eval_context.new
|
252
|
-
assert(!$LOADED_FEATURES.include?(io.path))
|
253
|
-
assert_raises(RuntimeError) { Kernel.load_dsl_file(io.path, obj, [], false) }
|
254
|
-
assert(!$LOADED_FEATURES.include?(io.path))
|
255
|
-
assert_equal(0, obj.real_method_call_count)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
Utilrb.require_ext('is_singleton?') do
|
260
|
-
def test_is_singleton
|
261
|
-
klass = Class.new
|
262
|
-
singl_klass = (class << klass; self end)
|
263
|
-
obj = klass.new
|
264
|
-
|
265
|
-
assert(!klass.is_singleton?)
|
266
|
-
assert(!obj.is_singleton?)
|
267
|
-
assert(singl_klass.is_singleton?)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_poll
|
272
|
-
flexmock(Kernel).should_receive(:sleep).with(2).twice
|
273
|
-
counter = 0
|
274
|
-
Kernel.poll(2) do
|
275
|
-
counter += 1
|
276
|
-
if counter > 2
|
277
|
-
break
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_wait_until
|
283
|
-
flexmock(Kernel).should_receive(:sleep).with(2).twice
|
284
|
-
counter = 0
|
285
|
-
Kernel.wait_until(2) do
|
286
|
-
counter += 1
|
287
|
-
counter > 2
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_wait_while
|
292
|
-
flexmock(Kernel).should_receive(:sleep).with(2).twice
|
293
|
-
counter = 0
|
294
|
-
Kernel.wait_while(2) do
|
295
|
-
counter += 1
|
296
|
-
counter <= 2
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
data/test/test_logger.rb
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
require './test/test_config'
|
2
|
-
require 'utilrb/logger'
|
3
|
-
require 'flexmock/test_unit'
|
4
|
-
|
5
|
-
class TC_Logger < Test::Unit::TestCase
|
6
|
-
module Root
|
7
|
-
extend Logger::Root('TC_Logger', Logger::INFO)
|
8
|
-
|
9
|
-
module Child
|
10
|
-
extend Logger::Hierarchy
|
11
|
-
end
|
12
|
-
class Klass
|
13
|
-
extend Logger::Hierarchy
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
Root.reset_own_logger
|
19
|
-
Root::Child.reset_own_logger
|
20
|
-
super
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_logger_root
|
24
|
-
assert Root.respond_to?(:logger)
|
25
|
-
assert Root.logger
|
26
|
-
assert_equal Logger::INFO, Root.logger.level
|
27
|
-
assert_equal 'TC_Logger', Root.logger.progname
|
28
|
-
|
29
|
-
assert Root.respond_to?(:warn)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_logger_hierarchy
|
33
|
-
child = Root::Child
|
34
|
-
assert child.respond_to?(:logger)
|
35
|
-
assert child.logger
|
36
|
-
assert_same Root.logger, child.logger
|
37
|
-
assert child.respond_to?(:warn)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_logger_hierarchy_on_anonymous_classes
|
41
|
-
child = Class.new(Root::Klass)
|
42
|
-
assert_same Root.logger, child.logger
|
43
|
-
assert child.respond_to?(:warn)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_logger_hierarchy_on_instances_of_anonymous_classes
|
47
|
-
child_m = Class.new(Root::Klass) do
|
48
|
-
include Logger::Hierarchy
|
49
|
-
end
|
50
|
-
child = child_m.new
|
51
|
-
assert_same Root.logger, child.logger
|
52
|
-
assert child.respond_to?(:warn)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_logger_hierarchy_on_classes_that_have_almost_a_class_name
|
56
|
-
child_m = Class.new(Root::Klass) do
|
57
|
-
include Logger::Hierarchy
|
58
|
-
def self.name
|
59
|
-
"A::NonExistent::Constant::Name"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
child = child_m.new
|
63
|
-
assert_same Root.logger, child.logger
|
64
|
-
assert child.respond_to?(:warn)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_logger_hierarch_make_own
|
68
|
-
child = Root::Child
|
69
|
-
assert_same Root.logger, child.logger
|
70
|
-
|
71
|
-
child.make_own_logger('child', Logger::DEBUG)
|
72
|
-
assert_not_same Root.logger, child.logger
|
73
|
-
assert_equal "child", child.logger.progname
|
74
|
-
assert_equal Logger::DEBUG, child.logger.level
|
75
|
-
assert_equal "TC_Logger", Root.logger.progname
|
76
|
-
assert_equal Logger::INFO, Root.logger.level
|
77
|
-
|
78
|
-
assert child.has_own_logger?
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_logger_hierarch_make_own_propagates_to_children
|
82
|
-
child = Root::Child
|
83
|
-
assert_same Root.logger, child.logger
|
84
|
-
Root.make_own_logger('root', Logger::DEBUG)
|
85
|
-
assert_same Root.logger, child.logger
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_logger_hierarch_reset_own
|
89
|
-
child = Root::Child
|
90
|
-
child.make_own_logger('child', Logger::DEBUG)
|
91
|
-
assert_not_same Root.logger, child.logger
|
92
|
-
child.reset_own_logger
|
93
|
-
test_logger_hierarchy
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_logger_nest_size
|
97
|
-
logger = Logger.new(StringIO.new)
|
98
|
-
logger.formatter = flexmock
|
99
|
-
logger.formatter.should_receive(:call).with(any, any, any, "msg0").once.ordered
|
100
|
-
logger.formatter.should_receive(:call).with(any, any, any, " msg1").once.ordered
|
101
|
-
logger.formatter.should_receive(:call).with(any, any, any, " msg2").once.ordered
|
102
|
-
logger.formatter.should_receive(:call).with(any, any, any, "msg3").once.ordered
|
103
|
-
logger.nest_size = 0
|
104
|
-
logger.warn("msg0")
|
105
|
-
logger.nest_size = 3
|
106
|
-
logger.warn("msg1")
|
107
|
-
logger.nest_size = 1
|
108
|
-
logger.warn("msg2")
|
109
|
-
logger.nest_size = 0
|
110
|
-
logger.warn("msg3")
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_logger_nest
|
114
|
-
logger = Logger.new(StringIO.new)
|
115
|
-
logger.formatter = flexmock
|
116
|
-
logger.formatter.should_receive(:call).with(any, any, any, "msg0").once.ordered
|
117
|
-
logger.formatter.should_receive(:call).with(any, any, any, " msg1").once.ordered
|
118
|
-
logger.formatter.should_receive(:call).with(any, any, any, " msg2").once.ordered
|
119
|
-
logger.formatter.should_receive(:call).with(any, any, any, " msg3").once.ordered
|
120
|
-
logger.formatter.should_receive(:call).with(any, any, any, "msg4").once.ordered
|
121
|
-
logger.warn("msg0")
|
122
|
-
logger.nest(2) do
|
123
|
-
logger.warn("msg1")
|
124
|
-
logger.nest(1) do
|
125
|
-
logger.warn("msg2")
|
126
|
-
end
|
127
|
-
logger.warn("msg3")
|
128
|
-
end
|
129
|
-
logger.warn("msg4")
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_logger_io
|
133
|
-
logger = flexmock
|
134
|
-
io = Logger::LoggerIO.new(logger, :uncommon_level)
|
135
|
-
|
136
|
-
logger.should_receive(:uncommon_level).with("msg0").once.ordered
|
137
|
-
logger.should_receive(:uncommon_level).with("msg1 msg2").once.ordered
|
138
|
-
io.puts "msg0"
|
139
|
-
io.print "msg1"
|
140
|
-
io.puts " msg2"
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
module HierarchyTest
|
145
|
-
def self.logger; "root_logger" end
|
146
|
-
class HierarchyTest
|
147
|
-
extend Logger::Hierarchy
|
148
|
-
extend Logger::Forward
|
149
|
-
end
|
150
|
-
|
151
|
-
module A
|
152
|
-
extend Logger::Hierarchy
|
153
|
-
extend Logger::Forward
|
154
|
-
|
155
|
-
class B
|
156
|
-
extend Logger::Hierarchy
|
157
|
-
include Logger::Hierarchy
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
module HierarchyTestForSubclass
|
163
|
-
def self.logger; "other_logger" end
|
164
|
-
class HierarchyTest < HierarchyTest::HierarchyTest
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
module NotALoggingModule
|
169
|
-
class HierarchyTest < HierarchyTest::HierarchyTest
|
170
|
-
end
|
171
|
-
class NoLogger
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_hierarchy_can_resolve_parent_logger_with_identical_name
|
176
|
-
assert_equal "root_logger", HierarchyTest::HierarchyTest.logger
|
177
|
-
end
|
178
|
-
def test_hierarchy_can_resolve_parent_logger_in_subclasses_where_the_subclass_parent_module_is_not_providing_a_logger
|
179
|
-
assert_equal "root_logger", NotALoggingModule::HierarchyTest.logger
|
180
|
-
end
|
181
|
-
def test_hierarchy_resolves_the_parent_module_first_even_in_subclasses
|
182
|
-
assert_equal "other_logger", HierarchyTestForSubclass::HierarchyTest.logger
|
183
|
-
end
|
184
|
-
def test_hierarchy_raises_if_no_parent_logger_can_be_found
|
185
|
-
assert_raises(Logger::Hierarchy::NoParentLogger) { NotALoggingModule::NoLogger.extend Logger::Hierarchy }
|
186
|
-
end
|
187
|
-
|
188
|
-
module RootModule
|
189
|
-
end
|
190
|
-
def test_hierarchy_raises_if_hierarchy_is_called_on_a_root_module
|
191
|
-
assert_raises(Logger::Hierarchy::NoParentLogger) { RootModule.extend Logger::Hierarchy }
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_instance_resolves_to_class_logger
|
195
|
-
klass = Class.new(HierarchyTest::HierarchyTest)
|
196
|
-
klass.send(:include, Logger::Hierarchy)
|
197
|
-
obj = klass.new
|
198
|
-
assert_equal "root_logger", obj.logger
|
199
|
-
end
|
200
|
-
def test_instance_resolves_to_own_logger_if_set
|
201
|
-
a_logger = HierarchyTest::A.make_own_logger
|
202
|
-
assert_same a_logger, HierarchyTest::A::B.logger
|
203
|
-
end
|
204
|
-
end
|
data/test/test_misc.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require './test/test_config'
|
2
|
-
|
3
|
-
class TC_Misc < Test::Unit::TestCase
|
4
|
-
def test_super_idiom
|
5
|
-
base = Class.new do
|
6
|
-
attr_reader :base
|
7
|
-
def initialize
|
8
|
-
super if defined? super
|
9
|
-
@base = true
|
10
|
-
end
|
11
|
-
end
|
12
|
-
assert_nothing_raised { base.new }
|
13
|
-
|
14
|
-
derived = Class.new(base) do
|
15
|
-
attr_reader :derived
|
16
|
-
def initialize
|
17
|
-
super if defined? super
|
18
|
-
@derived = true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
obj = nil
|
22
|
-
assert_nothing_raised { obj = derived.new }
|
23
|
-
assert( obj.base )
|
24
|
-
assert( obj.derived )
|
25
|
-
|
26
|
-
mod = Module.new do
|
27
|
-
attr_reader :module
|
28
|
-
def initialize
|
29
|
-
super if defined? super
|
30
|
-
@module = true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
obj = nil
|
34
|
-
base.class_eval { include mod }
|
35
|
-
|
36
|
-
assert_nothing_raised { obj = derived.new }
|
37
|
-
assert( obj.base )
|
38
|
-
assert( obj.module )
|
39
|
-
assert( obj.derived )
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|