trace-util-adv 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/TODO.txt +18 -2
  2. data/VERSION +1 -1
  3. data/lib/appenders/appender.rb +1 -1
  4. data/lib/appenders/base_appender.rb +18 -20
  5. data/lib/appenders/include.rb +2 -2
  6. data/lib/appenders/types/html_appender.rb +1 -1
  7. data/lib/appenders/types/logger_appender.rb +1 -1
  8. data/lib/appenders/types/xml_appender.rb +1 -1
  9. data/lib/extensions/hash_extensions.rb +41 -19
  10. data/lib/extensions/hash_rule_extensions.rb +4 -0
  11. data/lib/extensions/symbol_extensions.rb +7 -5
  12. data/lib/filters/composite/composite_class_filter.rb +1 -0
  13. data/lib/filters/composite/composite_module_filter.rb +1 -0
  14. data/lib/filters/executor/filter_exec.rb +6 -2
  15. data/lib/filters/filter.rb +12 -17
  16. data/lib/filters/filter_factory.rb +1 -1
  17. data/lib/filters/filter_mappings.rb +4 -2
  18. data/lib/filters/include.rb +4 -8
  19. data/lib/filters/list/list_instance_var_filter.rb +1 -0
  20. data/lib/filters/name_filter.rb +13 -0
  21. data/lib/filters/simple/argument_filter.rb +2 -1
  22. data/lib/filters/simple/class_filter.rb +1 -1
  23. data/lib/filters/simple/instance_var_filter.rb +9 -6
  24. data/lib/filters/simple/method_filter.rb +1 -0
  25. data/lib/filters/simple/module_filter.rb +6 -3
  26. data/lib/rules/rule_match.rb +5 -4
  27. data/lib/targets/file_target.rb +11 -0
  28. data/lib/templates/base_template.rb +11 -12
  29. data/lib/templates/html_template.rb +35 -36
  30. data/lib/templates/string_template.rb +0 -1
  31. data/lib/templates/template_mappings.rb +4 -4
  32. data/lib/templates/xml_template.rb +0 -1
  33. data/lib/trace-util-adv.rb +36 -20
  34. data/lib/trace_calls/trace_ext.rb +4 -17
  35. data/test/action_handler/include.rb +4 -0
  36. data/test/action_handler/test_action_handler.rb +1 -2
  37. data/test/action_handler/test_create_action_handler.rb +6 -9
  38. data/test/appenders/include.rb +4 -0
  39. data/test/appenders/test_appender_templates.rb +57 -0
  40. data/test/appenders/test_create_appender.rb +9 -10
  41. data/test/extensions/include.rb +4 -0
  42. data/test/extensions/test_filters_creation.rb +4 -28
  43. data/test/extensions/test_hash_extensions.rb +44 -47
  44. data/test/extensions/test_hash_filter_extensions.rb +46 -29
  45. data/test/extensions/test_set_context.rb +9 -11
  46. data/test/extensions/test_string_extensions.rb +1 -3
  47. data/test/extensions/test_symbol_extensions.rb +2 -4
  48. data/test/filters/chain/test_filters_chain.rb +1 -51
  49. data/test/filters/composite/test_composite_class_filter.rb +1 -3
  50. data/test/filters/composite/test_composite_module_filter.rb +1 -3
  51. data/test/filters/composite/test_composite_var_filter.rb +8 -11
  52. data/test/filters/executor/test_filter_exec.rb +1 -3
  53. data/test/filters/include.rb +8 -0
  54. data/test/filters/msg_context/test_custom_filters.rb +13 -14
  55. data/test/filters/simple/test_base_filter.rb +8 -6
  56. data/test/filters/simple/test_class_filter.rb +1 -3
  57. data/test/filters/simple/test_instancevar_filter.rb +5 -9
  58. data/test/filters/simple/test_method_filter.rb +4 -9
  59. data/test/filters/simple/test_module_filter.rb +13 -10
  60. data/test/samples/sample_composite_filters.rb +15 -12
  61. data/test/targets/test_create_targets.rb +21 -0
  62. data/test/templates/include.rb +4 -0
  63. data/test/templates/test_create_templates.rb +23 -0
  64. data/test/templates/test_exec_templates.rb +6 -0
  65. data/test/trace_calls/include.rb +4 -0
  66. data/test/trace_calls/test_configure_.rb +17 -14
  67. data/test/trace_calls/tracing/test_html_tracing.rb +2 -3
  68. data/test/trace_calls/tracing/test_logger_tracing.rb +5 -4
  69. data/test/trace_calls/tracing/test_stream_tracing.rb +2 -3
  70. data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +2 -3
  71. data/test/trace_calls/tracing/test_xml_tracing.rb +2 -3
  72. data/trace-util-adv.gemspec +14 -6
  73. metadata +13 -5
  74. data/test/appenders/test_appender_tracers.rb +0 -56
  75. data/test/tracers/test_create_tracers.rb +0 -46
  76. data/test/tracers/test_exec_tracers.rb +0 -11
@@ -1,7 +1,4 @@
1
- require 'extensions/core_extensions'
2
- require 'filters/base_filters'
3
- require 'rules/hash_rule_extensions'
4
- require "test/unit"
1
+ require "include"
5
2
 
6
3
  class Person
7
4
  attr_accessor :name
@@ -56,38 +53,39 @@ class TestHashExtensions < Test::Unit::TestCase
56
53
  expected = {
57
54
  :vars => [{:a => 12, :b => "B"}]
58
55
  }
59
-
56
+
60
57
  assert_equal expected, context, "resulting @context not as expected"
61
58
  end
62
-
59
+
63
60
  def test_set_context_args
64
61
  context = {:args => [{:a => 12, :b => "B"}]}.context
65
62
  puts "context set:" + context.inspect
66
63
  expected = {
67
64
  :args => [{:a => 12, :b => "B"}]
68
65
  }
69
-
66
+
70
67
  assert_equal expected, context, "resulting @context not as expected"
71
68
  end
72
-
69
+
73
70
  def test_set_context_block
74
71
  context = {:block => true}.context
75
72
  puts "context set:" + context.inspect
76
73
  expected = {
77
74
  :block => true
78
75
  }
79
-
76
+
80
77
  assert_equal expected, context, "resulting @context not as expected"
81
78
  end
82
-
79
+
83
80
  def test_set_context_self
84
81
  obj = Person.new "Kristian"
85
82
  context = {:block => true, :self => obj}.context
86
83
  puts "context set:" + context.inspect
87
84
  expected = {
85
+ :block => true,
88
86
  :self => obj
89
87
  }
90
-
88
+
91
89
  assert_equal expected, context, "resulting @context not as expected"
92
90
  assert_equal "Kristian", context[:self].name, "Kristian expected as person name"
93
91
  end
@@ -1,6 +1,4 @@
1
- require 'extensions/core_extensions'
2
- require "test/unit"
3
-
1
+ require "include"
4
2
 
5
3
  class TestFilter < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- require 'extensions/core_extensions'
2
- require "test/unit"
3
-
1
+ require 'include'
4
2
 
5
3
  class TestSymbolExtensions < Test::Unit::TestCase
6
4
 
@@ -18,7 +16,7 @@ class TestSymbolExtensions < Test::Unit::TestCase
18
16
 
19
17
  def test_trace_class
20
18
  result = :xml.trace_class
21
- assert_equal result, Tracing::OutputTemplate::XmlTrace, ":xml Should result in XmlTrace"
19
+ assert_equal result, Tracing::XmlTemplate, ":xml Should result in XmlTrace"
22
20
  end
23
21
 
24
22
  def appender_class
@@ -1,55 +1,5 @@
1
- require "core_extensions"
2
- require "trace_calls"
3
- require "output_templates"
4
- require "rubygems"
5
- require "duration"
6
- require "test/unit"
1
+ require "../include"
7
2
 
8
- # configure use of TraceExt
9
- module Me
10
- class My
11
-
12
- def hello
13
- puts "Hello World!"
14
- end
15
-
16
- def hi_there
17
- puts "Hi there!"
18
- end
19
-
20
- def blip
21
- puts "Blip!"
22
- end
23
-
24
- def blap
25
- puts "Blap!"
26
- end
27
-
28
- end
29
- end
30
-
31
- Method_filter_A = {
32
- :name => 'my methods',
33
- :method_rules => [{
34
- # id of method rule set
35
- :name => 'my_methods',
36
- :include => [/hi.*/],
37
- :exclude => ['hello'],
38
- :default => :yield
39
- }]
40
- }
41
-
42
- # Method_filter_B = {
43
- # :name => 'my methods',
44
- # :method_rules => [{
45
- # # id of method rule set
46
- # :name => 'my_methods',
47
- # :include => ['blip', 'blop'],
48
- # :default => :yield
49
- # }]
50
- # }
51
-
52
-
53
3
  class TestFilter < Test::Unit::TestCase
54
4
 
55
5
  attr_reader :ah1, :filters
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  Class_composite_filter_A = {
6
4
  # id of composite rule set
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  Module_composite_filter_A = {
6
4
  # id of composite rule set
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  # for specific instance_vars, match on values (after .to_s on var)
6
4
 
@@ -44,28 +42,28 @@ class TestCompositeInstanceVarFilter < Test::Unit::TestCase
44
42
  def test_composite_var_filter_hash_to_var
45
43
  composite_filter = Var_composite_filter
46
44
  result = composite_filter.filter_class
47
- assert_equal Tracing::CompositeInstanceVarFilter, result, "Should result in composite var filter"
45
+ assert_equal Tracing::ListInstanceVarFilter, result, "Should result in composite var filter"
48
46
  end
49
47
 
50
48
  def test_composite_var_filter_hash_to_var
51
49
  composite_filter = Var_composite_filter
52
50
  result = composite_filter.create_filter
53
- assert_equal Tracing::CompositeInstanceVarFilter, result.class, "Should result in composite var filter"
51
+ assert_equal Tracing::ListInstanceVarFilter, result.class, "Should result in composite var filter"
54
52
  end
55
53
 
56
54
  def test_composite_var_filter_from_hash
57
55
  composite_filter = Var_composite_filter
58
56
  config = {:filters => composite_filter}
59
57
  result = config.filters
60
- assert_equal Tracing::CompositeInstanceVarFilter, result.class, "Should result in composite var filter"
58
+ assert_equal Tracing::ListInstanceVarFilter, result.class, "Should result in composite var filter"
61
59
  end
62
60
 
63
61
  # see allow_action in CompositeInstanceVarFilter, refactor :yield, :include .. as return values!?
62
+
64
63
  def test_composite_var_filter__var_and_method_match
65
64
  composite_filter = Var_composite_filter
66
65
 
67
- context = {}
68
- context.set_context :vars => {:template_path => 'rapid'}
66
+ context = {:vars => ["template_path" => 'b/taglib/b'], :self => Obj.new('b/taglib/b')}.context
69
67
 
70
68
  options = {:filters => composite_filter}
71
69
  exec = Tracing::Filter::Executor.new(options)
@@ -76,8 +74,7 @@ class TestCompositeInstanceVarFilter < Test::Unit::TestCase
76
74
  def test_composite_var_filter__var_not_match
77
75
  composite_filter = Var_composite_filter
78
76
 
79
- context = {}
80
- context.set_context :class_name => 'Blip::Blap', :vars => ["template_path"]
77
+ context = {:class_name => 'Blip::Blap', :vars => ["template_path" => 'rapid']}
81
78
  context[:self] = Obj.new "blop"
82
79
 
83
80
  options = {:filters => composite_filter}
@@ -90,7 +87,7 @@ class TestCompositeInstanceVarFilter < Test::Unit::TestCase
90
87
  composite_filter = Var_composite_filter
91
88
 
92
89
  context = {}
93
- context.set_context :class_name => 'Blip::Blap', :vars => ["template_path"]
90
+ context.set_context :class_name => 'Blip::Blap', :vars => ["template_path" => 'blip']
94
91
  context[:self] = Obj.new "a/rapid_x"
95
92
 
96
93
  options = {:filters => composite_filter}
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  class TestFilterExec < Test::Unit::TestCase
6
4
 
@@ -0,0 +1,8 @@
1
+ require "trace-util-adv"
2
+ Require.base_path = File.dirname(__FILE__)
3
+ Require.folder "../samples"
4
+ require "test/unit"
5
+
6
+ # b = Tracing::BaseFilter.register_filters({:hash => :C})
7
+ # puts "B: #{b.inspect}"
8
+ # puts Tracing::BaseFilter.filters.inspect
@@ -1,12 +1,11 @@
1
- require 'core_extensions'
2
- require 'filters/base_filters'
3
- require 'filters/message_filters'
4
-
5
-
6
- require 'extensions/core_extensions'
7
- require "test/unit"
1
+ require '../include'
8
2
 
9
3
  class CustomNameFilter < Tracing::NameFilter
4
+
5
+ def initialize(options)
6
+ super(options)
7
+ end
8
+
10
9
  def allow?(name)
11
10
  name == options[:name]
12
11
  end
@@ -18,7 +17,7 @@ class TestSymbolExtensions < Test::Unit::TestCase
18
17
  def setup
19
18
  # Procs of this form can be used as filters inside include/exclude lists
20
19
  abc_filter = Proc.new {|name| name == 'abc' }
21
- name_filter = CustomNameFilter.new('rapid')
20
+ name_filter = CustomNameFilter.new({:name => 'rapid'})
22
21
  @meth_filter_abc = {:i_method_filter => [abc_filter], :default => :exclude}.filters
23
22
  @meth_filter_name = {:i_method_filter => [name_filter], :default => :exclude}.filters
24
23
  @meth_filter_comb = {:i_method_filter => [abc_filter, name_filter], :default => :exclude}.filters
@@ -32,18 +31,18 @@ class TestSymbolExtensions < Test::Unit::TestCase
32
31
  end
33
32
 
34
33
  def test_custom_name_filter
35
- res = @meth_filter_name.allow?("hello", @context)
36
- assert_equal true, res, "Should allow since matching method name 'abc'"
34
+ res = @meth_filter_name.allow_action("hello", @context_abc)
35
+ assert_equal :yield, res, "Should allow since matching method name 'abc'"
37
36
  end
38
37
 
39
38
  def test_custom_proc_filter
40
- res = @meth_filter_abc.allow?("hello", @context)
41
- assert_equal true, res, "Should allow since matching method name 'rapid'"
39
+ res = @meth_filter_abc.allow_action("hello", @context_rapid)
40
+ assert_equal :yield, res, "Should allow since matching method name 'rapid'"
42
41
  end
43
42
 
44
43
  def test_custom_filters
45
- @meth_filter_comb.allow?("hello", @context)
46
- assert_equal true, res, "Should allow since matching method name 'abc'"
44
+ res = @meth_filter_comb.allow_action("hello", @context_abc)
45
+ assert_equal :include, res, "Should allow since matching method name 'abc'"
47
46
  end
48
47
 
49
48
  end
@@ -1,5 +1,4 @@
1
- require 'filters/base_filters'
2
- require "test/unit"
1
+ require "../include"
3
2
 
4
3
 
5
4
  class TestBaseFilter < Test::Unit::TestCase
@@ -12,7 +11,7 @@ class TestBaseFilter < Test::Unit::TestCase
12
11
  end
13
12
 
14
13
  def test_default_name
15
- bf = Tracing::BaseFilter.new
14
+ bf = Tracing::BaseFilter.new({})
16
15
  assert_equal "Unknown filter", bf.name, "Should result name:'Unknown filter'"
17
16
  end
18
17
 
@@ -26,12 +25,15 @@ class TestBaseFilter < Test::Unit::TestCase
26
25
  assert_equal "base", bf.name, "Should result in name:'base'"
27
26
  end
28
27
 
29
- def test_register_filters
30
- bf = Tracing::BaseFilter.new({:name => 'base'})
28
+ def test_register_filters
29
+ Tracing::BaseFilter.new({:name => 'base'})
31
30
  bF = Tracing::BaseFilter
31
+
32
32
  f1 = {:x => :y}
33
33
  bF.register_filters(f1)
34
- assert_equal f1, bF.filters, "Should result in x=>y filter"
34
+ expect = {:x => :y}
35
+ assert_equal expect, bF.filters, "Should result in x=>y filter"
36
+
35
37
  f2 = {:z => :a}
36
38
  bF.register_filters(f2)
37
39
  expect = {:z=>:a, :x=>:y}
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  Class_filter = {
6
4
  :name => 'my classes',
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  InstanceVar_filter = {
6
4
  :name => 'check template path',
@@ -45,18 +43,19 @@ class TestInstanceVarFilter < Test::Unit::TestCase
45
43
  # see allow_action in InstanceVarFilter, refactor :yield, :include .. as return values!?
46
44
  def test_varfilter__class_and_varmatch
47
45
  var_filter = InstanceVar_filter
48
- context = {:class_name => "Hobo::Dryml", :vars => {"template_path" => "a/taglib/x"} }.context
46
+ context = {:class_name => "Hobo::Dryml", :vars => {"template_path" => "a/taglib/x"}, :self => Obj.new("a/taglib/x") }.context
49
47
 
50
48
  options = {:filters => var_filter}
51
49
  exec = Tracing::Filter::Executor.new(options)
52
50
  result = exec.filters_allow?('msg', context)
51
+
53
52
  assert_equal true, result, "Filter should allow passage"
54
53
  end
55
54
 
56
55
  def test_varfilter__varnot_match
57
56
  var_filter = InstanceVar_filter
58
57
 
59
- context = {:class_name => 'Blip::Blap', :vars => {"template_path" => "a/taglib/x"}, :self => Obj.new("blop") }.context
58
+ context = {:class_name => 'Blip::Blap', :vars => {"template_path" => "a/taglib/x"}, :self => Obj.new("taglib/x") }.context
60
59
 
61
60
  puts "Context:" + context.inspect
62
61
 
@@ -68,10 +67,7 @@ class TestInstanceVarFilter < Test::Unit::TestCase
68
67
 
69
68
  def test_varfilter__varexcluded
70
69
  var_filter = InstanceVar_filter
71
- context = {:class_name => 'Blip::Blap', :vars => {"template_path" => "a/taglib/x"} }.context
72
-
73
- context[:self] = Obj.new "a/rapid_x"
74
-
70
+ context = {:class_name => 'Blip::Blap', :vars => {"template_path" => "a/taglib/x"}, :self => Obj.new("a/rapid_x") }.context
75
71
 
76
72
  options = {:filters => var_filter}
77
73
  exec = Tracing::Filter::Executor.new(options)
@@ -1,6 +1,4 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  Method_filter = {
6
4
  :name => 'my methods',
@@ -41,8 +39,7 @@ class TestMethodFilter < Test::Unit::TestCase
41
39
  def test_method_filter__class_and_method_match
42
40
  composite_filter = Method_filter
43
41
 
44
- context = {}
45
- context.set_context :class_name => "Hobo::Dryml", :method_name => "build_a"
42
+ context = { :class_name => "Hobo::Dryml", :method_name => "build_a"}.context
46
43
 
47
44
  options = {:filters => composite_filter}
48
45
  exec = Tracing::Filter::Executor.new(options)
@@ -53,8 +50,7 @@ class TestMethodFilter < Test::Unit::TestCase
53
50
  def test_method_filter__method_not_match
54
51
  composite_filter = Method_filter
55
52
 
56
- context = {}
57
- context.set_context :class_name => 'Blip::Blap', :method_name => "blop"
53
+ context = { :class_name => 'Blip::Blap', :method_name => "blop"}.context
58
54
 
59
55
  options = {:filters => composite_filter}
60
56
  exec = Tracing::Filter::Executor.new(options)
@@ -65,8 +61,7 @@ class TestMethodFilter < Test::Unit::TestCase
65
61
  def test_method_filter__method_excluded
66
62
  composite_filter = Method_filter
67
63
 
68
- context = {}
69
- context.set_context :class_name => "Hobo::Dryml", :method_name => "add_it"
64
+ context = { :class_name => "Hobo::Dryml", :method_name => "add_it"}.context
70
65
 
71
66
  options = {:filters => composite_filter}
72
67
  exec = Tracing::Filter::Executor.new(options)
@@ -1,17 +1,16 @@
1
- require 'filters/filter_exec'
2
- require 'extensions/core_extensions'
3
- require "test/unit"
1
+ require "../include"
4
2
 
5
3
  Module_filter = {
6
4
  :name => 'my modules',
5
+ :default => :exclude,
7
6
  :module_rules => [{
8
7
  # id of modules rule set
9
8
  :name => ['my_modules'],
10
9
  :include => [/Hobo/],
11
10
  :exclude => [/Dryml/],
12
11
  :default => :exclude
13
- }
14
- ]}
12
+ }]
13
+ }
15
14
 
16
15
  class TestModuleFilter < Test::Unit::TestCase
17
16
 
@@ -31,6 +30,7 @@ class TestModuleFilter < Test::Unit::TestCase
31
30
  _filter = Module_filter
32
31
  config = {:filters => _filter}
33
32
  result = config.filters
33
+ puts result.inspect
34
34
  assert_equal Tracing::ModuleFilter, result.class, "Should result in module filter"
35
35
  end
36
36
 
@@ -38,8 +38,7 @@ class TestModuleFilter < Test::Unit::TestCase
38
38
  def test_module_filter__module_and_method_match
39
39
  _filter = Module_filter
40
40
 
41
- context = {}
42
- context.set_context :modules => ["Hobo"], :method_name => "build_a" #, :class_name => "Dryml"
41
+ context = { :modules => ["Hobo"], :method_name => "build_a", :class_name => "Dryml" }.context
43
42
 
44
43
  options = {:filters => _filter}
45
44
  exec = Tracing::Filter::Executor.new(options)
@@ -47,16 +46,20 @@ class TestModuleFilter < Test::Unit::TestCase
47
46
  assert_equal true, result, "Filter should allow passage"
48
47
  end
49
48
 
50
-
49
+ # TODO: Doesn't Work :(
51
50
  def test_module_filter__module_not_match
52
51
  _filter = Module_filter
53
52
 
54
- context = {}
55
- context.set_context :modules => ['Blip', 'Blap']
53
+ context = {:modules => ["Blip", "Blop"], :method_name => "build_a", :class_name => "Dryml"}.context
54
+
55
+ puts context.inspect
56
56
 
57
57
  options = {:filters => _filter}
58
58
  exec = Tracing::Filter::Executor.new(options)
59
59
  result = exec.filters_allow?('msg', context)
60
+
61
+ puts "Result:" + result.inspect
62
+
60
63
  assert_equal false, result, "Filter should NOT allow passage"
61
64
  end
62
65