trace-util-adv 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Advanced TraceUtils tutorial.pdf +0 -0
- data/CHANGELOG +4 -8
- data/{lib/TODO.txt → TODO.txt} +8 -0
- data/VERSION +1 -1
- data/lib/action_handler/action_handler.rb +40 -0
- data/lib/{action_handler.rb → action_handler/action_handler_registration.rb} +3 -41
- data/lib/appenders/appender.rb +1 -13
- data/lib/appenders/appender_mappings.rb +13 -0
- data/lib/appenders/base_appender.rb +2 -11
- data/lib/appenders/file_appender.rb +21 -13
- data/lib/appenders/include.rb +4 -0
- data/lib/appenders/types/README-NOTE.txt +2 -0
- data/lib/appenders/{html_appender.rb → types/html_appender.rb} +4 -20
- data/lib/appenders/{logger_appender.rb → types/logger_appender.rb} +0 -0
- data/lib/appenders/{stream_appender.rb → types/stream_appender.rb} +0 -0
- data/lib/appenders/{template_log_appender.rb → types/template_log_appender.rb} +0 -0
- data/lib/appenders/{xml_appender.rb → types/xml_appender.rb} +1 -1
- data/lib/extensions/array_extensions.rb +42 -0
- data/lib/extensions/hash_extensions.rb +181 -0
- data/lib/extensions/hash_rule_extensions.rb +50 -0
- data/lib/extensions/include.rb +1 -0
- data/lib/extensions/nilclass_extensions.rb +10 -0
- data/lib/extensions/object_extensions.rb +19 -0
- data/lib/extensions/string_extensions.rb +35 -0
- data/lib/extensions/symbol_extensions.rb +30 -0
- data/lib/filters/composite/composite_class_filter.rb +25 -0
- data/lib/filters/composite/composite_module_filter.rb +53 -0
- data/lib/filters/executor/filter_exec.rb +74 -0
- data/lib/filters/filter.rb +43 -0
- data/lib/filters/filter_factory.rb +1 -1
- data/lib/filters/filter_mappings.rb +36 -0
- data/lib/filters/{tracing_filter.rb → filter_registration.rb} +6 -49
- data/lib/filters/filter_use.rb +10 -0
- data/lib/filters/include.rb +8 -0
- data/lib/filters/list/README-NOTE.txt +1 -0
- data/lib/filters/list/list_instance_var_filter.rb +27 -0
- data/lib/filters/{message_filters.rb → msg_context/message_context_filters.rb} +3 -12
- data/lib/filters/simple/argument_filter.rb +24 -0
- data/lib/filters/simple/class_filter.rb +15 -0
- data/lib/filters/simple/instance_var_filter.rb +25 -0
- data/lib/filters/simple/method_filter.rb +17 -0
- data/lib/filters/simple/module_filter.rb +14 -0
- data/lib/{templates/trace_output_handler.rb → output_handler/output_handler.rb} +0 -0
- data/lib/rules/rule_mappings.rb +10 -0
- data/lib/{rule_match.rb → rules/rule_match.rb} +5 -3
- data/lib/targets/README-NOTE.txt +2 -0
- data/lib/targets/file_target.rb +65 -0
- data/lib/targets/stream_target.rb +9 -0
- data/lib/targets/string_target.rb +9 -0
- data/lib/templates/base_template.rb +3 -2
- data/lib/templates/html_template.rb +1 -2
- data/lib/templates/include.rb +2 -0
- data/lib/templates/string_template.rb +24 -25
- data/lib/templates/template_mappings.rb +10 -0
- data/lib/templates/xml_template.rb +28 -29
- data/lib/trace-util-adv.rb +24 -4
- data/lib/{trace_calls.rb → trace_calls/trace_calls.rb} +0 -0
- data/lib/trace_calls/trace_configuration.rb +29 -0
- data/lib/{trace_ext.rb → trace_calls/trace_ext.rb} +10 -9
- data/test/{test_action_handler.rb → action_handler/test_action_handler.rb} +1 -5
- data/test/action_handler/test_create_action_handler.rb +31 -0
- data/test/appenders/test_appender_filters.rb +0 -0
- data/test/appenders/test_appender_tracers.rb +56 -0
- data/test/appenders/test_create_appender.rb +49 -0
- data/test/{test_html_appender.rb → appenders/test_html_appender.rb} +3 -7
- data/test/appenders/test_stream_appender.rb +41 -0
- data/test/appenders/test_template_log_appender.rb +18 -0
- data/test/{test_xml_appender.rb → appenders/test_xml_appender.rb} +0 -0
- data/test/extensions/test_filters_creation.rb +36 -0
- data/test/extensions/test_hash_extensions.rb +208 -0
- data/test/extensions/test_hash_filter_extensions.rb +65 -0
- data/test/extensions/test_set_context.rb +94 -0
- data/test/extensions/test_string_extensions.rb +55 -0
- data/test/extensions/test_symbol_extensions.rb +35 -0
- data/test/{test_filters_chain.rb → filters/chain/test_filters_chain.rb} +2 -1
- data/test/filters/composite/test_composite_class_filter.rb +78 -0
- data/test/filters/composite/test_composite_module_filter.rb +82 -0
- data/test/filters/composite/test_composite_var_filter.rb +103 -0
- data/test/filters/executor/test_filter_exec.rb +80 -0
- data/test/filters/msg_context/test_custom_filters.rb +54 -0
- data/test/filters/simple/test_base_filter.rb +56 -0
- data/test/filters/simple/test_class_filter.rb +75 -0
- data/test/filters/simple/test_instancevar_filter.rb +82 -0
- data/test/filters/simple/test_method_filter.rb +77 -0
- data/test/filters/simple/test_module_filter.rb +63 -0
- data/test/samples/include.rb +1 -0
- data/test/samples/sample_classes.rb +23 -0
- data/test/samples/sample_composite_filters.rb +50 -0
- data/test/samples/sample_filters.rb +58 -0
- data/test/sandbox/matcher.rb +7 -0
- data/test/sandbox/sandbox.rb +25 -0
- data/test/{test_xml_gen.rb → sandbox/test_xml_gen.rb} +0 -0
- data/test/trace_calls/test_configure_.rb +70 -0
- data/test/trace_calls/tracing/test_html_tracing.rb +20 -0
- data/test/trace_calls/tracing/test_logger_tracing.rb +18 -0
- data/test/trace_calls/tracing/test_stream_tracing.rb +17 -0
- data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +18 -0
- data/test/trace_calls/tracing/test_xml_tracing.rb +18 -0
- data/test/tracers/test_create_tracers.rb +46 -0
- data/test/tracers/test_exec_tracers.rb +11 -0
- data/trace-util-adv.gemspec +91 -32
- metadata +91 -32
- data/lib/core_extensions.rb +0 -101
- data/lib/filters/base_filters.rb +0 -178
- data/lib/filters/composite_filters.rb +0 -71
- data/lib/output_templates.rb +0 -5
- data/lib/sample_filters.rb +0 -97
- data/lib/trace_appenders.rb +0 -9
- data/lib/trace_filters.rb +0 -4
- data/test/test_appender.rb +0 -29
- data/test/test_file_appender.rb +0 -32
- data/test/test_filters.rb +0 -112
- data/test/test_filters_create.rb +0 -28
- data/test/test_special_filters.rb +0 -78
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'extensions/core_extensions'
|
2
|
+
require 'filters/base_filters'
|
3
|
+
require 'rules/hash_rule_extensions'
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
|
7
|
+
class TestHashExtensions < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
## Nothing really
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_map
|
17
|
+
mapper = {:x => 1, :y => 2, :default => 3}
|
18
|
+
result = mapper.map(:x)
|
19
|
+
assert_equal result, 1, ":x Should result in 1"
|
20
|
+
result = mapper.map(:w)
|
21
|
+
assert_equal result, 3, ":w Should result in default 3"
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_method_full_name
|
25
|
+
my_instance_variables = {:template_path => 'taglibs/rapid_core.dryml'}
|
26
|
+
context_hash = {:class_name => "Alpha::Beta::Gamma", :method_name => "meth_a", :vars => [my_instance_variables], :args => {:a => 7} }
|
27
|
+
context.set_context context_hash
|
28
|
+
result = context.full_method_name
|
29
|
+
assert_equal result, 'Alpha::Beta::Gamma.meth_a', "Should result in 'Alpha::Beta::Gamma.meth_a'"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_rules_allow_action_include
|
33
|
+
rule = {:include => ['a']}
|
34
|
+
result = rule.rules_allow_action('a')
|
35
|
+
assert_equal result, :include, "Should include a"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_rules_allow_action_yield
|
39
|
+
rule = {:include => ['a']}
|
40
|
+
result = rule.rules_allow_action('b')
|
41
|
+
assert_equal result, :yield, "Should yield a"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_rules_allow_action_exclude
|
45
|
+
rule = {:exclude => ['a']}
|
46
|
+
result = rule.rules_allow_action('a')
|
47
|
+
assert_equal result, :exclude, "Should exclude a"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_rules_allow_action_exclude_and_yield
|
51
|
+
rule = {:exclude_and_yield => ['a']}
|
52
|
+
result = rule.rules_allow_action('a')
|
53
|
+
assert_equal result, :exclude_and_yield, "Should exclude_an_yield a"
|
54
|
+
end
|
55
|
+
|
56
|
+
# TODO
|
57
|
+
# rule_allow_action(name) NEEDS MAJOR CLEANUP AND REFACTOR!!!
|
58
|
+
def test_rules_allow_action_include_and_yield
|
59
|
+
rule = {:include_and_yield => ['a']}
|
60
|
+
result = rule.rules_allow_action('a')
|
61
|
+
assert_equal result, :include_and_yield, "Should include_an_yield a"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_rule_list
|
65
|
+
rules = ['a']
|
66
|
+
result = rules.rule_list
|
67
|
+
assert_equal result, rules, "Should not change rule"
|
68
|
+
|
69
|
+
rules = ['a', 'b']
|
70
|
+
result = rules.rule_list
|
71
|
+
assert_equal result, rules, "Should not change rules"
|
72
|
+
|
73
|
+
rules = "a b"
|
74
|
+
result = rules.rule_list
|
75
|
+
assert_equal result, ['a', 'b'], "Should split rules"
|
76
|
+
end
|
77
|
+
|
78
|
+
# return a symbol, either - :include, :exclude or :yield (let next filter decide)
|
79
|
+
def test_rule_allow_action
|
80
|
+
rule = {:include => ['a']}
|
81
|
+
result = rule.rule_allow_action('a')
|
82
|
+
assert_equal result, :include, "Should :include"
|
83
|
+
|
84
|
+
rule = {:exclude => ['a']}
|
85
|
+
result = rule.rule_allow_action('a')
|
86
|
+
assert_equal result, :exclude, "Should :exclude"
|
87
|
+
|
88
|
+
rule = {:include_and_yield => ['a']}
|
89
|
+
result = rule.rule_allow_action('a')
|
90
|
+
assert_equal result, :include_and_yield, "Should :include_and_yield"
|
91
|
+
|
92
|
+
rule = {:exclude_and_yield => ['a']}
|
93
|
+
result = rule.rule_allow_action('a')
|
94
|
+
assert_equal result, :exclude_and_yield, "Should :exclude_and_yield"
|
95
|
+
|
96
|
+
rule = {:yield => ['a']}
|
97
|
+
result = rule.rule_allow_action('a')
|
98
|
+
assert_equal result, :yield, "Should :yield"
|
99
|
+
|
100
|
+
rule = {:include => ['a']}
|
101
|
+
result = rule.rule_allow_action('a')
|
102
|
+
assert_equal result, :include, "Should :include"
|
103
|
+
|
104
|
+
rule = {:include => ['b'], :exclude => "a"}
|
105
|
+
result = rule.rule_allow_action('a')
|
106
|
+
assert_equal result, :exclude, "Should :exclude"
|
107
|
+
|
108
|
+
rule = {:include => ['a'], :exclude => "a"}
|
109
|
+
result = rule.rule_allow_action('a')
|
110
|
+
assert_equal result, :include, "Should :include"
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_tracer
|
115
|
+
rule = {:tracer => :html}
|
116
|
+
result = rule.tracer
|
117
|
+
assert_equal result.class, Tracing::OutputTemplate::HtmlTrace, "Should result in HtmlTrace"
|
118
|
+
|
119
|
+
rule = {:tracer => :xml}
|
120
|
+
result = rule.tracer
|
121
|
+
assert_equal result.class, Tracing::OutputTemplate::XmlTrace, "Should result in XmlTrace"
|
122
|
+
|
123
|
+
rule = {:tracer => :string}
|
124
|
+
result = rule.tracer
|
125
|
+
assert_equal result.class, Tracing::OutputTemplate::StringTrace, "Should result in StringTrace"
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_appenders
|
129
|
+
config = {:appenders => []}
|
130
|
+
result = config.appenders
|
131
|
+
assert_equal result.blank?, true, "Should result in empty appender list"
|
132
|
+
|
133
|
+
config = {:appenders => :html}
|
134
|
+
result = config.appenders
|
135
|
+
assert_equal result.class, Tracing::HtmlAppender, "Should result in empty appender list"
|
136
|
+
|
137
|
+
config = {:appenders => [:xml, :html]}
|
138
|
+
result = config.appenders
|
139
|
+
assert_equal Tracing::XmlAppender, result[0].class, "Should result in xml appender"
|
140
|
+
assert_equal Tracing::HtmlAppender, result[1].class, "Should also result in html appender"
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_action_handlers
|
144
|
+
config = {:action_handlers => []}
|
145
|
+
result = config.action_handlers
|
146
|
+
assert_equal result.blank?, true, "Should result in empty action_handler list"
|
147
|
+
|
148
|
+
config = {:action_handlers => {:appenders => :html}}
|
149
|
+
result = config.action_handlers
|
150
|
+
assert_equal Tracing::HtmlAppender, result.appenders[0].class, "Should result in action handler with HtmlAppender registered"
|
151
|
+
|
152
|
+
config = {:action_handlers => {:filters => {:i_method_filter => "a,b"}}}
|
153
|
+
result = config.action_handlers
|
154
|
+
assert_equal Tracing::MethodFilter, result.filters[0].class, "Should result in action handler with MethodFilter registered"
|
155
|
+
|
156
|
+
ah1 = {:filters => {:i_method_filter => "a,b"}, :appenders => :html}
|
157
|
+
ah2 = {:filters => {:x_method_filter => "c,d"}, :appenders => :xml}
|
158
|
+
|
159
|
+
config = {:action_handlers => [ah1, ah2]}
|
160
|
+
result = config.action_handlers
|
161
|
+
assert_equal Tracing::MethodFilter, result[0].filters[0].class, "Should result in action handler with MethodFilter registered"
|
162
|
+
assert_equal Tracing::MethodFilter, result[1].filters[0].class, "Should result in action handler with MethodFilter registered"
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_create_filter
|
166
|
+
config = {:i_method_filter => "a,b"}
|
167
|
+
result = config.create_filter
|
168
|
+
assert_equal Tracing::MethodFilter, result.class, "Should result in method filter"
|
169
|
+
|
170
|
+
config = {:filters => {:i_method_filter => "a,b"}}
|
171
|
+
result = config.create_filter
|
172
|
+
assert_equal Tracing::MethodFilter, result.class, "Should result in method filter"
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_create_filter_hash
|
176
|
+
config = {:i_method_filter => "a,b"}
|
177
|
+
result = config.create_filter_hash
|
178
|
+
exp_result = {:method_filter => { :include => "a,b" } }
|
179
|
+
assert_equal exp_result, result, "Should result in :method_filter hash with :include name rules"
|
180
|
+
|
181
|
+
config = {:xy_class_filter => "a,b"}
|
182
|
+
result = config.create_filter_hash
|
183
|
+
exp_result = {:class_filter => { :exclude_and_yield => "a,b" } }
|
184
|
+
assert_equal exp_result, result, "Should result in :class_filter hash with :exclude_and_yield name rules"
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_try_create_filter_hash
|
188
|
+
config = {:i_method_filter => "a,b"}
|
189
|
+
result = config.create_filter_hash
|
190
|
+
exp_result = {:method_filter => { :include => "a,b" } }
|
191
|
+
assert_equal exp_result, result, "Should result in :method_filter hash with :include name rules"
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_filters
|
195
|
+
config = {:filters => []}
|
196
|
+
result = config.filters
|
197
|
+
assert_equal result.blank?, true, "Should result in empty filters list"
|
198
|
+
|
199
|
+
config = {:filters => {:i_method_filter => "a,b"}}
|
200
|
+
result = config.filters
|
201
|
+
assert_equal Tracing::MethodFilter, result.class, "Should result in method filter"
|
202
|
+
|
203
|
+
puts result.rules.inspect
|
204
|
+
expected = {:method_filter => {:include => "a, b"} }
|
205
|
+
assert_equal expected, result.rules, "Should result in method rules"
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'extensions/core_extensions'
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
|
5
|
+
class TestHashFilterFilter < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
## Nothing really
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_try_create_method_include_filter
|
15
|
+
hash = {:i_method_filter => 'a,b'}
|
16
|
+
filter_hash = hash.create_filter
|
17
|
+
# puts filter_hash.inspect
|
18
|
+
assert_equal filter_hash, {:method_filter => {:include => "a,b"}}, "Should create method include filter"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_try_create_method_exclude_filter
|
22
|
+
hash = {:x_method_filter => 'a,b'}
|
23
|
+
filter_hash = hash.create_filter
|
24
|
+
# puts filter_hash.inspect
|
25
|
+
assert_equal filter_hash, {:method_filter => {:exclude => "a,b"}}, "Should create method exclude filter"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_try_create_method_include_and_yield_filter
|
29
|
+
hash = {:iy_method_filter => 'a,b'}
|
30
|
+
filter_hash = hash.create_filter
|
31
|
+
# puts filter_hash.inspect
|
32
|
+
assert_equal filter_hash, {:method_filter => {:include_and_yield => "a,b"}}, "Should create method include_an_yield filter"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create_method_exclude_and_yield_filter
|
36
|
+
hash = {:xy_method_filter => 'a,b'}
|
37
|
+
filter_hash = hash.create_filter
|
38
|
+
# puts filter_hash.inspect
|
39
|
+
assert_equal filter_hash, {:method_filter => {:exclude_and_yield => "a,b"}}, "Should create method exclude_and_yield filter"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_try_create_class_exclude_and_yield_filter
|
43
|
+
hash = {:xy_class_filter => 'a,b'}
|
44
|
+
filter_hash = hash.create_filter
|
45
|
+
# puts filter_hash.inspect
|
46
|
+
assert_equal filter_hash, {:class_filter => {:exclude_and_yield => "a,b"}}, "Should create class exclude_and_yield filter"
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_try_create_module_exclude_and_yield_filter
|
50
|
+
hash = {:xy_module_filter => 'a,b'}
|
51
|
+
filter_hash = hash.create_filter
|
52
|
+
# puts filter_hash.inspect
|
53
|
+
assert_equal filter_hash, {:module_filter => {:exclude_and_yield => "a,b"}}, "Should create module exclude_and_yield filter"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_try_create_vars_exclude_and_yield_filter
|
57
|
+
hash = {:xy_vars_filter => 'a,b'}
|
58
|
+
filter_hash = hash.create_filter
|
59
|
+
# puts filter_hash.inspect
|
60
|
+
assert_equal filter_hash, {:vars_filter => {:exclude_and_yield => "a,b"}}, "Should create vars exclude_and_yield filter"
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'extensions/core_extensions'
|
2
|
+
require 'filters/base_filters'
|
3
|
+
require 'rules/hash_rule_extensions'
|
4
|
+
require "test/unit"
|
5
|
+
|
6
|
+
class Person
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
class TestHashExtensions < Test::Unit::TestCase
|
16
|
+
|
17
|
+
def setup
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
## Nothing really
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_set_context
|
25
|
+
context = {:class_name => "Hobo::Dryml", :method_name => "build_a"}.context
|
26
|
+
expected = {
|
27
|
+
:class_name =>"Dryml",
|
28
|
+
:method_name =>"build_a",
|
29
|
+
:modules =>["Hobo"],
|
30
|
+
:full_class_name =>"Hobo::Dryml",
|
31
|
+
:full_modules_name=>"Hobo",
|
32
|
+
:full_method_name =>"Hobo::Dryml.build_a"
|
33
|
+
}
|
34
|
+
|
35
|
+
assert_equal expected, context, "resulting @context not as expected"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_set_context_modules
|
39
|
+
context = {:modules => ["Hobo"], :class_name => "Dryml", :method_name => "build_a"}.context
|
40
|
+
puts "context set:" + context.inspect
|
41
|
+
expected = {
|
42
|
+
:method_name =>"build_a",
|
43
|
+
:class_name => "Dryml",
|
44
|
+
:modules =>["Hobo"],
|
45
|
+
:full_class_name =>"Hobo::Dryml",
|
46
|
+
:full_modules_name=>"Hobo",
|
47
|
+
:full_method_name =>"Hobo::Dryml.build_a"
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_equal expected, context, "resulting @context not as expected"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_set_context_instance_vars
|
54
|
+
context = {:vars => [{:a => 12, :b => "B"}]}.context
|
55
|
+
puts "context set:" + context.inspect
|
56
|
+
expected = {
|
57
|
+
:vars => [{:a => 12, :b => "B"}]
|
58
|
+
}
|
59
|
+
|
60
|
+
assert_equal expected, context, "resulting @context not as expected"
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_set_context_args
|
64
|
+
context = {:args => [{:a => 12, :b => "B"}]}.context
|
65
|
+
puts "context set:" + context.inspect
|
66
|
+
expected = {
|
67
|
+
:args => [{:a => 12, :b => "B"}]
|
68
|
+
}
|
69
|
+
|
70
|
+
assert_equal expected, context, "resulting @context not as expected"
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_set_context_block
|
74
|
+
context = {:block => true}.context
|
75
|
+
puts "context set:" + context.inspect
|
76
|
+
expected = {
|
77
|
+
:block => true
|
78
|
+
}
|
79
|
+
|
80
|
+
assert_equal expected, context, "resulting @context not as expected"
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_set_context_self
|
84
|
+
obj = Person.new "Kristian"
|
85
|
+
context = {:block => true, :self => obj}.context
|
86
|
+
puts "context set:" + context.inspect
|
87
|
+
expected = {
|
88
|
+
:self => obj
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_equal expected, context, "resulting @context not as expected"
|
92
|
+
assert_equal "Kristian", context[:self].name, "Kristian expected as person name"
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'extensions/core_extensions'
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
|
5
|
+
class TestFilter < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_split_names
|
8
|
+
names = nil
|
9
|
+
result = names.split_names
|
10
|
+
expected = ["alpha", "beta"]
|
11
|
+
assert_equal nil, result, "No names should result in nil"
|
12
|
+
|
13
|
+
names = "alpha, beta"
|
14
|
+
result = names.split_names
|
15
|
+
expected = ["alpha", "beta"]
|
16
|
+
assert_equal expected, result, "Should be split into list of names"
|
17
|
+
|
18
|
+
names = "alpha beta"
|
19
|
+
result = names.split_names
|
20
|
+
expected = ["alpha", "beta"]
|
21
|
+
assert_equal expected, result, "Should be split into list of names"
|
22
|
+
|
23
|
+
names = "alpha , beta"
|
24
|
+
result = names.split_names
|
25
|
+
expected = ["alpha", "beta"]
|
26
|
+
assert_equal expected, result, "Should be split into list of names"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_modules
|
30
|
+
name = "Alpha::Beta::Gamma"
|
31
|
+
result = name.modules
|
32
|
+
expected = ["Alpha","Beta"]
|
33
|
+
assert_equal expected, result, "Should be split into list of module names"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_class_name
|
37
|
+
name = "Alpha::Beta"
|
38
|
+
result = name.class_name
|
39
|
+
expected = "Beta"
|
40
|
+
assert_equal expected, result, "Should be last part of module name"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_in_module?(module_name)
|
44
|
+
name = "Alpha::Beta"
|
45
|
+
result = name.in_module?("Alpha")
|
46
|
+
expected = true
|
47
|
+
assert_equal expected, result, "Should be in module"
|
48
|
+
|
49
|
+
result = name.in_module?("Gamma")
|
50
|
+
expected = true
|
51
|
+
assert_equal expected, result, "Should NOT be in module"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'extensions/core_extensions'
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
|
5
|
+
class TestSymbolExtensions < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
## Nothing really
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_prefix
|
15
|
+
prefixed_symbol = :test.prefix(:xy)
|
16
|
+
assert_equal prefixed_symbol, :xy_test, "Should result in :xy_test"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_trace_class
|
20
|
+
result = :xml.trace_class
|
21
|
+
assert_equal result, Tracing::OutputTemplate::XmlTrace, ":xml Should result in XmlTrace"
|
22
|
+
end
|
23
|
+
|
24
|
+
def appender_class
|
25
|
+
result = :xml.trace_class
|
26
|
+
assert_equal result, Tracing::XmlAppender, ":xml Should result in XmlTrace"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_rule
|
30
|
+
result = :i.rule
|
31
|
+
assert_equal result, :include, ":i Should result in :include"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -70,9 +70,10 @@ class TestFilter < Test::Unit::TestCase
|
|
70
70
|
names_A = %w{blip blop}
|
71
71
|
names_B = "blip blop"
|
72
72
|
names_C = "blip, blop"
|
73
|
-
|
74
73
|
bfil = {:xmethod_filter => names_B}
|
75
74
|
|
75
|
+
my_method_filter = {:xmethod_filter => "method_a, method b"}
|
76
|
+
|
76
77
|
# method_filter_A = Tracing::Filter.create_filter({:imethod_filter => names_A})
|
77
78
|
method_filter_B = Tracing::Filter.create_filter(bfil)
|
78
79
|
# method_filter_C = Tracing::Filter.create_filter({:imethod_filter => names_C})
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'filters/filter_exec'
|
2
|
+
require 'extensions/core_extensions'
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
Class_composite_filter_A = {
|
6
|
+
# id of composite rule set
|
7
|
+
:name => 'Template stuff',
|
8
|
+
:default => :exclude,
|
9
|
+
:classes => [{
|
10
|
+
:names => [/Dryml/],
|
11
|
+
:method_rules => {
|
12
|
+
:include => [/build.*/, 'exec'],
|
13
|
+
:exclude => ['add'],
|
14
|
+
:default => :exclude
|
15
|
+
}
|
16
|
+
}]
|
17
|
+
}
|
18
|
+
|
19
|
+
class TestCompositeFilter < Test::Unit::TestCase
|
20
|
+
|
21
|
+
def test_composite_class_filter_hash_to_class
|
22
|
+
composite_filter = Class_composite_filter_A
|
23
|
+
result = composite_filter.filter_class
|
24
|
+
assert_equal Tracing::CompositeClassFilter, result, "Should result in composite class filter"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_composite_class_filter_hash_to_class
|
28
|
+
composite_filter = Class_composite_filter_A
|
29
|
+
result = composite_filter.create_filter
|
30
|
+
assert_equal Tracing::CompositeClassFilter, result.class, "Should result in composite class filter"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_composite_class_filter_from_hash
|
35
|
+
composite_filter = Class_composite_filter_A
|
36
|
+
config = {:filters => composite_filter}
|
37
|
+
result = config.filters
|
38
|
+
assert_equal Tracing::CompositeClassFilter, result.class, "Should result in method filter"
|
39
|
+
end
|
40
|
+
|
41
|
+
# see allow_action in CompositeClassFilter, refactor :yield, :include .. as return values!?
|
42
|
+
def test_composite_class_filter__class_and_method_match
|
43
|
+
composite_filter = Class_composite_filter_A
|
44
|
+
|
45
|
+
context = {}
|
46
|
+
context.set_context :class_name => "Hobo::Dryml", :method_name => "build_a"
|
47
|
+
|
48
|
+
options = {:filters => composite_filter}
|
49
|
+
exec = Tracing::Filter::Executor.new(options)
|
50
|
+
result = exec.filters_allow?('msg', context)
|
51
|
+
assert_equal true, result, "Filter should allow passage"
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_composite_class_filter__class_not_match
|
55
|
+
composite_filter = Class_composite_filter_A
|
56
|
+
|
57
|
+
context = {}
|
58
|
+
context.set_context :class_name => 'Blip::Blap'
|
59
|
+
|
60
|
+
options = {:filters => composite_filter}
|
61
|
+
exec = Tracing::Filter::Executor.new(options)
|
62
|
+
result = exec.filters_allow?('msg', context)
|
63
|
+
assert_equal false, result, "Filter should NOT allow passage"
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_composite_class_filter__method_excluded
|
67
|
+
composite_filter = Class_composite_filter_A
|
68
|
+
|
69
|
+
context = {}
|
70
|
+
context.set_context :class_name => "Hobo::Dryml", :method_name => "add_it"
|
71
|
+
|
72
|
+
options = {:filters => composite_filter}
|
73
|
+
exec = Tracing::Filter::Executor.new(options)
|
74
|
+
result = exec.filters_allow?('msg', context)
|
75
|
+
assert_equal false, result, "Filter should NOT allow passage"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'filters/filter_exec'
|
2
|
+
require 'extensions/core_extensions'
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
Module_composite_filter_A = {
|
6
|
+
# id of composite rule set
|
7
|
+
:name => 'dryml_filter',
|
8
|
+
:modules => [{
|
9
|
+
:names => ['Hobo::Dryml', /Dryml/],
|
10
|
+
:class_rules => {
|
11
|
+
:include => [/Template.*/, 'DRYMLBuilder'],
|
12
|
+
:exclude => ['Taglib'],
|
13
|
+
:default => :include
|
14
|
+
},
|
15
|
+
:method_rules => {
|
16
|
+
:include => [/blip.*/, 'blap'],
|
17
|
+
:exclude => ['add_it'],
|
18
|
+
:default => :include
|
19
|
+
}
|
20
|
+
}]
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
class TestCompositeModuleFilter < Test::Unit::TestCase
|
25
|
+
|
26
|
+
def test_composite_module_filter_hash_to_module
|
27
|
+
composite_filter = Module_composite_filter_A
|
28
|
+
result = composite_filter.filter_module
|
29
|
+
assert_equal Tracing::CompositeModuleFilter, result, "Should result in composite module filter"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_composite_module_filter_hash_to_module
|
33
|
+
composite_filter = Module_composite_filter_A
|
34
|
+
result = composite_filter.create_filter
|
35
|
+
assert_equal Tracing::CompositeModuleFilter, result.class, "Should result in composite module filter"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_composite_module_filter_from_hash
|
39
|
+
composite_filter = Module_composite_filter_A
|
40
|
+
config = {:filters => composite_filter}
|
41
|
+
result = config.filters
|
42
|
+
assert_equal Tracing::CompositeModuleFilter, result.class, "Should result in composite module filter"
|
43
|
+
end
|
44
|
+
|
45
|
+
# see allow_action in CompositeModuleFilter, refactor :yield, :include .. as return values!?
|
46
|
+
def test_composite_module_filter__module_and_method_match
|
47
|
+
composite_filter = Module_composite_filter_A
|
48
|
+
|
49
|
+
context = {}
|
50
|
+
context.set_context :modules => ["Hobo", "Dryml"], :method_name => "build_a" #, :class_name => "Dryml"
|
51
|
+
|
52
|
+
options = {:filters => composite_filter}
|
53
|
+
exec = Tracing::Filter::Executor.new(options)
|
54
|
+
result = exec.filters_allow?('msg', context)
|
55
|
+
assert_equal true, result, "Filter should allow passage"
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_composite_module_filter__module_not_match
|
60
|
+
composite_filter = Module_composite_filter_A
|
61
|
+
|
62
|
+
context = {}
|
63
|
+
context.set_context :modules => ['Blip', 'Blap']
|
64
|
+
|
65
|
+
options = {:filters => composite_filter}
|
66
|
+
exec = Tracing::Filter::Executor.new(options)
|
67
|
+
result = exec.filters_allow?('msg', context)
|
68
|
+
assert_equal false, result, "Filter should NOT allow passage"
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_composite_module_filter__method_excluded
|
72
|
+
composite_filter = Module_composite_filter_A
|
73
|
+
|
74
|
+
context = {}
|
75
|
+
context.set_context :modules => ["Hobo", "Dryml"], :method_name => "add_it"
|
76
|
+
|
77
|
+
options = {:filters => composite_filter}
|
78
|
+
exec = Tracing::Filter::Executor.new(options)
|
79
|
+
result = exec.filters_allow?('msg', context)
|
80
|
+
assert_equal false, result, "Filter should NOT allow passage"
|
81
|
+
end
|
82
|
+
end
|