source_route 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/examples/show_task_trace_in_rails.rb +16 -0
- data/lib/source_route/formats/html.rb +3 -1
- data/lib/source_route/formats/html_template.slim +13 -7
- data/lib/source_route/tp_filter.rb +29 -0
- data/lib/source_route/tp_result.rb +7 -9
- data/lib/source_route/version.rb +1 -1
- data/lib/source_route/wrapper.rb +10 -40
- data/lib/source_route.rb +5 -2
- data/test/source_route_test.rb +174 -0
- data/test/tp_filter_test.rb +55 -0
- metadata +8 -5
- data/test/wrapper_test.rb +0 -170
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98f0bf5a3ce05c2070f9f3f2873ef6db029c79c4
|
4
|
+
data.tar.gz: b830a4923f7e9f31da43e40802660e6a70ecd0d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b8dcd4d530e5e6d50c37536f699885c641e02011f41718c524883117584c8e77b93bde220712d829e110f085439013e37c5242a54cf649bfe7a90bbd1170c98
|
7
|
+
data.tar.gz: b54647f405cbd24fdc41eb338c29f4b04b53086766d7bb8ec68e1013aa24c8a044dd7f9c37111d201a7ea9ab309b3cf658e240321004b06c135bcf6a65922288
|
data/README.md
CHANGED
@@ -77,8 +77,10 @@ see more usage in examples.
|
|
77
77
|
|
78
78
|
### TODO
|
79
79
|
|
80
|
-
|
80
|
+
No need filter event on html when event is single. see html output file in test.
|
81
|
+
|
82
|
+
Reorganize the call and return in html template. maybe make some additional work to insert return data of call when return event is open.
|
81
83
|
|
82
|
-
|
84
|
+
Add debug option to provider more verbose messages of what has happened
|
83
85
|
|
84
86
|
When we record both call end return event, it's better to combine them togother into one, so we can get call order from call event and also get return value from return event
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Usage: copying following in your Rakefile under rails root
|
2
|
+
|
3
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
4
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
5
|
+
|
6
|
+
require File.expand_path('../config/application', __FILE__)
|
7
|
+
|
8
|
+
SourceRoute.enable 'WantedClass' do
|
9
|
+
# output_format :console # optional
|
10
|
+
end
|
11
|
+
|
12
|
+
Rails.application.load_tasks
|
13
|
+
|
14
|
+
at_exit do
|
15
|
+
SourceRoute.build_html_output
|
16
|
+
end
|
@@ -10,8 +10,10 @@ module SourceRoute
|
|
10
10
|
template_path = File.expand_path "../html_template.slim", __FILE__
|
11
11
|
slim_template = Slim::Template.new(template_path)
|
12
12
|
|
13
|
+
filename = results.condition.result_config[:filename] ||
|
14
|
+
"#{Time.now.strftime('%H%M')}-source-route.html"
|
13
15
|
html_output_str = slim_template.render(results)
|
14
|
-
File.open(
|
16
|
+
File.open(filename, 'w') do |f|
|
15
17
|
f << html_output_str
|
16
18
|
end
|
17
19
|
end
|
@@ -19,13 +19,15 @@ html
|
|
19
19
|
|
20
20
|
.data-collect
|
21
21
|
/ dont use local_trace_data.to_json, because ActiveSupport override it and can introduce unexpected crash for some data
|
22
|
-
#trace-data
|
22
|
+
#trace-data(data-trace="#{JSON.dump(local_trace_data)}" data-tp-events="#{JSON.dump(@condition.events)}")
|
23
23
|
|
24
24
|
.container(ng-controller="MainCtrl")
|
25
25
|
.top-header
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
|
27
|
+
.btn-group
|
28
|
+
button(ng-click="traceFilter.event = undefined") ALL
|
29
|
+
button.btn-link(ng-bind="event" ng-click="traceFilter.event = event" ng-repeat="event in tpEvents")
|
30
|
+
|
29
31
|
.trace-flow
|
30
32
|
.row
|
31
33
|
.left-info.col-sm-4
|
@@ -33,7 +35,7 @@ html
|
|
33
35
|
button.btn.btn-default(ng-click="selectKlass(klass)")
|
34
36
|
span(ng-bind="klass")
|
35
37
|
.center-info.col-sm-6
|
36
|
-
.well.well-lg(ng-repeat="trace in traces | filter:
|
38
|
+
.well.well-lg(ng-repeat="trace in traces | filter:traceFilter")
|
37
39
|
|
38
40
|
.header(ng-click="showMoreDetail = !showMoreDetail")
|
39
41
|
span(ng-bind="trace.defined_class")
|
@@ -68,7 +70,11 @@ html
|
|
68
70
|
javascript:
|
69
71
|
sourceRoute = angular.module('SourceRoute', [])
|
70
72
|
sourceRoute.controller('MainCtrl', function($scope) {
|
73
|
+
$scope.traceFilter = {}
|
71
74
|
$scope.traces = angular.element("#trace-data").data('trace')
|
75
|
+
|
76
|
+
$scope.tpEvents = angular.element("#trace-data").data('tp-events')
|
77
|
+
|
72
78
|
// it is possible to prevent dirty check on definedClasses after it was generated
|
73
79
|
$scope.definedClasses = _.uniq(_.map($scope.traces, 'defined_class'))
|
74
80
|
var all_counter = 'ALL ' + $scope.traces.length
|
@@ -76,9 +82,9 @@ html
|
|
76
82
|
|
77
83
|
$scope.selectKlass = function(klass) {
|
78
84
|
if (klass == all_counter) {
|
79
|
-
$scope.
|
85
|
+
$scope.traceFilter.defined_class = undefined
|
80
86
|
} else {
|
81
|
-
$scope.
|
87
|
+
$scope.traceFilter.defined_class = klass
|
82
88
|
}
|
83
89
|
}
|
84
90
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SourceRoute
|
2
|
+
|
3
|
+
class TpFilter
|
4
|
+
def initialize(condition)
|
5
|
+
@condition = condition
|
6
|
+
end
|
7
|
+
|
8
|
+
# to improve performance, we didnt assign tp as instance variable
|
9
|
+
def block_it?(tp)
|
10
|
+
return true if negative_check(tp)
|
11
|
+
return false if positive_check(tp)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def negative_check(tp)
|
16
|
+
@condition.negatives.any? do |method_key, value|
|
17
|
+
tp.send(method_key).to_s =~ Regexp.new(value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def positive_check(tp)
|
22
|
+
return true if @condition.positive == {}
|
23
|
+
@condition.positive.any? do |method_key, value|
|
24
|
+
tp.send(method_key).to_s =~ Regexp.new(value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -2,6 +2,9 @@ module SourceRoute
|
|
2
2
|
|
3
3
|
class TpResult
|
4
4
|
|
5
|
+
Config = Struct.new(:format, :show_additional_attrs,
|
6
|
+
:include_local_var, :include_instance_var, :filename)
|
7
|
+
|
5
8
|
# see event description in TracePoint API Doc
|
6
9
|
DEFAULT_ATTRS = {
|
7
10
|
call: [:defined_class, :method_id],
|
@@ -20,22 +23,17 @@ module SourceRoute
|
|
20
23
|
}
|
21
24
|
|
22
25
|
def initialize(wrapper)
|
23
|
-
@logger = Logger.new(STDOUT)
|
24
26
|
@wrapper = wrapper
|
25
27
|
|
26
|
-
@
|
28
|
+
@config = @wrapper.condition.result_config
|
27
29
|
|
28
30
|
@tp_events = @wrapper.condition.events
|
29
|
-
if @tp_events.length > 1 and @output_config[:selected_attrs]
|
30
|
-
@logger.warn 'selected_attrs was ignored, cause watched event was more than one '
|
31
|
-
@output_config[:selected_attrs] = nil
|
32
|
-
end
|
33
31
|
end
|
34
32
|
|
35
33
|
def output_attributes(event)
|
36
|
-
attrs =
|
34
|
+
attrs = DEFAULT_ATTRS[event] + Array(@config.show_additional_attrs)
|
37
35
|
attrs.push(:event) if @tp_events.size > 1
|
38
|
-
attrs
|
36
|
+
attrs.uniq
|
39
37
|
end
|
40
38
|
|
41
39
|
def build(trace_point_instance)
|
@@ -48,7 +46,7 @@ module SourceRoute
|
|
48
46
|
|
49
47
|
def output(tp_ins)
|
50
48
|
|
51
|
-
format = @
|
49
|
+
format = @config.format
|
52
50
|
format = format.to_sym if format.respond_to? :to_sym
|
53
51
|
|
54
52
|
case format
|
data/lib/source_route/version.rb
CHANGED
data/lib/source_route/wrapper.rb
CHANGED
@@ -6,45 +6,28 @@ module SourceRoute
|
|
6
6
|
TRACE_POINT_METHODS = [:defined_class, :method_id, :path, :lineno]
|
7
7
|
|
8
8
|
attr_accessor :condition, :tp, :tp_attrs_results
|
9
|
-
attr_accessor :output_include_local_variables, :output_include_instance_variables
|
10
9
|
|
11
|
-
Condition = Struct.new(:events, :
|
10
|
+
Condition = Struct.new(:events, :negatives, :positive, :result_config)
|
12
11
|
|
13
12
|
class Condition
|
14
13
|
|
15
14
|
TRACE_POINT_METHODS.each do |m|
|
16
|
-
define_method m do
|
17
|
-
positive[m] = v.to_s
|
15
|
+
define_method m do |*v|
|
16
|
+
positive[m] = v.map(&:to_s).join('|')
|
18
17
|
end
|
19
18
|
|
20
19
|
define_method "#{m}_not" do |v|
|
21
|
-
|
20
|
+
negatives[m] = v.map(&:to_s).join('|')
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
def event(*v)
|
26
|
-
# why need self? without self, the events will not really changed, why?. seems a bug in
|
25
|
+
# why need self? without self, the events will not really changed, why?. seems a bug in Struct
|
27
26
|
self.events = v.map(&:to_sym) unless v == []
|
28
27
|
end
|
29
28
|
|
30
29
|
def output_format(data = nil, &block)
|
31
|
-
result_config
|
32
|
-
block
|
33
|
-
else
|
34
|
-
data
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def selected_attrs(*attr)
|
39
|
-
result_config[:selected_attrs] = attr
|
40
|
-
end
|
41
|
-
|
42
|
-
def output_include_local_variables
|
43
|
-
result_config[:include_local_var] = true
|
44
|
-
end
|
45
|
-
|
46
|
-
def output_include_instance_variables
|
47
|
-
result_config[:include_instance_var] = true
|
30
|
+
result_config.format = block_given? ? block : data
|
48
31
|
end
|
49
32
|
|
50
33
|
end
|
@@ -53,37 +36,24 @@ module SourceRoute
|
|
53
36
|
reset
|
54
37
|
end
|
55
38
|
|
56
|
-
# output_format can be console, html
|
57
39
|
def reset
|
58
40
|
@tp.disable if @tp
|
59
41
|
@condition = Condition.new([:call], {}, {},
|
60
|
-
|
61
|
-
selected_attrs: nil,
|
62
|
-
include_local_var: false,
|
63
|
-
include_instance_var: false
|
64
|
-
})
|
42
|
+
TpResult::Config.new('silence', [], false, false))
|
65
43
|
@tp_attrs_results = []
|
66
44
|
self
|
67
45
|
end
|
68
46
|
|
69
|
-
|
70
47
|
def trace
|
71
48
|
# dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace
|
72
49
|
tp_result = TpResult.new(self)
|
50
|
+
tp_filter = TpFilter.new(condition)
|
73
51
|
|
74
52
|
track = TracePoint.new *condition.events do |tp|
|
75
|
-
# todo: it's better to change the break check to condition methods to make more flexible
|
76
|
-
negative_break = condition.negative.any? do |method_key, value|
|
77
|
-
tp.send(method_key).to_s =~ Regexp.new(value)
|
78
|
-
end
|
79
|
-
next if negative_break
|
80
53
|
|
81
|
-
|
82
|
-
tp.send(method_key).to_s !~ Regexp.new(value)
|
83
|
-
end
|
84
|
-
next if positive_break
|
54
|
+
next if tp_filter.block_it?(tp)
|
85
55
|
|
86
|
-
unless condition
|
56
|
+
unless condition.result_config.format.is_a? Proc
|
87
57
|
ret_data = tp_result.build(tp)
|
88
58
|
tp_attrs_results.push(ret_data)
|
89
59
|
end
|
data/lib/source_route.rb
CHANGED
@@ -7,7 +7,7 @@ require 'awesome_print'
|
|
7
7
|
require "source_route/version"
|
8
8
|
require "source_route/wrapper"
|
9
9
|
require "source_route/tp_result"
|
10
|
-
|
10
|
+
require "source_route/tp_filter"
|
11
11
|
|
12
12
|
module SourceRoute
|
13
13
|
extend self
|
@@ -27,7 +27,10 @@ module SourceRoute
|
|
27
27
|
def enable(match = nil, &block)
|
28
28
|
wrapper.reset
|
29
29
|
|
30
|
-
|
30
|
+
if match
|
31
|
+
wrapper.condition.method_id(match)
|
32
|
+
wrapper.condition.defined_class(match)
|
33
|
+
end
|
31
34
|
|
32
35
|
wrapper.condition.instance_eval(&block) if block_given?
|
33
36
|
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SourceRouteTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@wrapper = SourceRoute::Wrapper.instance
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
SourceRoute.reset
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_enable_return_true
|
16
|
+
@source_route = SourceRoute.enable /nnnonsense/
|
17
|
+
assert @source_route
|
18
|
+
assert_equal @wrapper, SourceRoute.wrapper
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_catch_call_event
|
22
|
+
SourceRoute.enable do
|
23
|
+
event :call
|
24
|
+
method_id /nonsense/
|
25
|
+
output_format :test
|
26
|
+
end
|
27
|
+
SampleApp.new.nonsense
|
28
|
+
|
29
|
+
assert @wrapper.tp
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_show_addtional_attrs
|
33
|
+
SourceRoute.enable 'nonsense' do
|
34
|
+
result_config.show_additional_attrs = :path
|
35
|
+
end
|
36
|
+
SampleApp.new.nonsense
|
37
|
+
|
38
|
+
assert_includes @wrapper.tp_attrs_results.first[:path], 'test'
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_match_class_name_by_first_parameter
|
42
|
+
@source_route = SourceRoute.enable 'SampleApp'
|
43
|
+
SampleApp.new.nonsense
|
44
|
+
|
45
|
+
assert @wrapper.tp_attrs_results.size > 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_match_class_name
|
49
|
+
@source_route = SourceRoute.enable do
|
50
|
+
defined_class :SampleApp
|
51
|
+
end
|
52
|
+
|
53
|
+
SampleApp.new.nonsense
|
54
|
+
assert @wrapper.tp_attrs_results.size > 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_source_route_with_one_parameter
|
58
|
+
@source_route = SourceRoute.enable 'nonsense'
|
59
|
+
SampleApp.new.nonsense
|
60
|
+
|
61
|
+
ret_value = @wrapper.tp_attrs_results.last
|
62
|
+
assert_equal SampleApp, ret_value[:defined_class]
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_wrapper_reset
|
66
|
+
SourceRoute.enable 'nonsense'
|
67
|
+
SampleApp.new.nonsense
|
68
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
69
|
+
|
70
|
+
SourceRoute.reset
|
71
|
+
SampleApp.new.nonsense
|
72
|
+
|
73
|
+
assert_equal 0, @wrapper.tp_attrs_results.size
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_source_route_with_block_only
|
77
|
+
paths = []
|
78
|
+
SourceRoute.enable 'nonsense' do
|
79
|
+
SampleApp.new.nonsense
|
80
|
+
output_format do |tp|
|
81
|
+
paths.push tp.path
|
82
|
+
end
|
83
|
+
end
|
84
|
+
SampleApp.new.nonsense
|
85
|
+
|
86
|
+
assert_equal 0, @wrapper.tp_attrs_results.size
|
87
|
+
assert_equal 1, paths.size
|
88
|
+
assert_includes paths.first, 'sample_app'
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_trace_with_c_call
|
92
|
+
SourceRoute.trace event: :c_call do
|
93
|
+
'abc'.upcase
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_equal 2, @wrapper.tp_attrs_results.size
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_trace_without_first_hash_option
|
100
|
+
SourceRoute.trace output_format: :test do
|
101
|
+
SampleApp.new.nonsense
|
102
|
+
end
|
103
|
+
assert @wrapper.tp_attrs_results.size > 0
|
104
|
+
refute @wrapper.tp.enabled?
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_trace_two_events
|
108
|
+
SourceRoute.enable 'nonsense' do
|
109
|
+
event :call, :return
|
110
|
+
end
|
111
|
+
SampleApp.new.nonsense
|
112
|
+
assert_equal 2, @wrapper.tp_attrs_results.size
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_show_local_variables
|
116
|
+
SourceRoute.enable 'nonsense_with_params' do
|
117
|
+
result_config.include_local_var = true
|
118
|
+
output_format :console
|
119
|
+
end
|
120
|
+
|
121
|
+
SampleApp.new.nonsense_with_params(88)
|
122
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
123
|
+
|
124
|
+
ret_value = @wrapper.tp_attrs_results.last
|
125
|
+
|
126
|
+
assert_equal 88, ret_value[:local_var][:param1]
|
127
|
+
assert_equal nil, ret_value[:local_var][:param2]
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_track_local_var_when_event_is_return
|
131
|
+
SourceRoute.enable 'nonsense_with_params' do
|
132
|
+
event :return
|
133
|
+
result_config.include_local_var = true
|
134
|
+
end
|
135
|
+
|
136
|
+
SampleApp.new.nonsense_with_params(88)
|
137
|
+
assert_equal 1, @wrapper.tp_attrs_results.size
|
138
|
+
|
139
|
+
ret_value_for_return_event = @wrapper.tp_attrs_results.last
|
140
|
+
assert_equal 88, ret_value_for_return_event[:local_var][:param1]
|
141
|
+
assert_equal 5, ret_value_for_return_event[:local_var][:param2]
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_show_instance_vars
|
145
|
+
@source_route = SourceRoute.enable 'nonsense' do
|
146
|
+
result_config.include_instance_var = true
|
147
|
+
end
|
148
|
+
|
149
|
+
SampleApp.new('ins sure').nonsense_with_instance_var
|
150
|
+
|
151
|
+
assert_equal 2, @wrapper.tp_attrs_results.size
|
152
|
+
ret_value = @wrapper.tp_attrs_results.pop
|
153
|
+
|
154
|
+
assert_equal 'ins sure', ret_value[:instance_var][:@sample]
|
155
|
+
end
|
156
|
+
|
157
|
+
# Nothing has tested really when run rake cause ENV['ignore_html_generation'] was set to true
|
158
|
+
def test_html_format_output_only
|
159
|
+
@source_route = SourceRoute.enable do
|
160
|
+
defined_class 'SampleApp'
|
161
|
+
result_config.include_instance_var = true
|
162
|
+
result_config.include_local_var = true
|
163
|
+
end
|
164
|
+
|
165
|
+
SampleApp.new.init_cool_app
|
166
|
+
|
167
|
+
if ENV['ignore_html_generation'] == 'true'
|
168
|
+
# do nothing. it was set in Rakefile, so rake test will not generate html file
|
169
|
+
else
|
170
|
+
SourceRoute.build_html_output
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module SourceRoute
|
4
|
+
class Devise; end
|
5
|
+
class Warden; end
|
6
|
+
class User; end
|
7
|
+
|
8
|
+
FakeTp = Struct.new(:method_id, :defined_class, :lineno)
|
9
|
+
|
10
|
+
class TpFilterTest < Minitest::Test
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@devise_tp = FakeTp.new(:auth, Devise, 5)
|
14
|
+
@warden_tp = FakeTp.new(:auth, Warden, 6)
|
15
|
+
@user_tp = FakeTp.new(:new, User, 8)
|
16
|
+
@tps = [@devise_tp, @warden_tp, @user_tp]
|
17
|
+
@result_config = TpResult::Config.new('silence', [], false, false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_filter_method_not_auth
|
21
|
+
cond = Wrapper::Condition.new([:call], {method_id: 'auth'}, {}, @result_config)
|
22
|
+
@tp_filter = TpFilter.new(cond)
|
23
|
+
filtered = @tps.reject { |tp| @tp_filter.block_it?(tp) }
|
24
|
+
assert_equal [@user_tp], filtered
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_filter_class_is_admin
|
28
|
+
cond = Wrapper::Condition.new([:call], {}, {defined_class: 'Admin'}, @result_config)
|
29
|
+
@tp_filter = TpFilter.new(cond)
|
30
|
+
filtered = @tps.reject { |tp| @tp_filter.block_it?(tp) }
|
31
|
+
assert_equal [], filtered
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_filter_method_is_auth
|
35
|
+
cond = Wrapper::Condition.new([:call], {}, {method_id: 'auth'}, @result_config)
|
36
|
+
@tp_filter = TpFilter.new(cond)
|
37
|
+
filtered = @tps.reject { |tp| @tp_filter.block_it?(tp) }
|
38
|
+
assert_equal [@devise_tp, @warden_tp], filtered
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_filter_method_is_new_class_is_devise
|
42
|
+
cond = Wrapper::Condition.new([:call], {}, {defined_class: 'Devise', method_id: 'new'}, @result_config)
|
43
|
+
@tp_filter = TpFilter.new(cond)
|
44
|
+
filtered = @tps.reject { |tp| @tp_filter.block_it?(tp) }
|
45
|
+
assert_equal [@devise_tp, @user_tp], filtered
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_filter_class_is_devise_or_warden
|
49
|
+
cond = Wrapper::Condition.new([:call], {}, {defined_class: 'Warden|User'}, @result_config)
|
50
|
+
@tp_filter = TpFilter.new(cond)
|
51
|
+
filtered = @tps.reject { |tp| @tp_filter.block_it?(tp) }
|
52
|
+
assert_equal [@warden_tp, @user_tp], filtered
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: source_route
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- raykin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -136,17 +136,20 @@ files:
|
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
138
|
- examples/show_init_files_when_rails_server_start.rb
|
139
|
+
- examples/show_task_trace_in_rails.rb
|
139
140
|
- lib/source_route.rb
|
140
141
|
- lib/source_route/formats/html.rb
|
141
142
|
- lib/source_route/formats/html_template.slim
|
143
|
+
- lib/source_route/tp_filter.rb
|
142
144
|
- lib/source_route/tp_result.rb
|
143
145
|
- lib/source_route/version.rb
|
144
146
|
- lib/source_route/wrapper.rb
|
145
147
|
- source_route.gemspec
|
146
148
|
- test/fake_app.rb
|
147
149
|
- test/sample_app.rb
|
150
|
+
- test/source_route_test.rb
|
148
151
|
- test/test_helper.rb
|
149
|
-
- test/
|
152
|
+
- test/tp_filter_test.rb
|
150
153
|
homepage: http://github.com/raykin/source-route
|
151
154
|
licenses:
|
152
155
|
- MIT
|
@@ -174,6 +177,6 @@ summary: Wrapper of TracePoint.
|
|
174
177
|
test_files:
|
175
178
|
- test/fake_app.rb
|
176
179
|
- test/sample_app.rb
|
180
|
+
- test/source_route_test.rb
|
177
181
|
- test/test_helper.rb
|
178
|
-
- test/
|
179
|
-
has_rdoc:
|
182
|
+
- test/tp_filter_test.rb
|
data/test/wrapper_test.rb
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module SourceRoute
|
4
|
-
class WrapperTest < Minitest::Test
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@wrapper = Wrapper.instance
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
SourceRoute.reset
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_enable_return_true
|
17
|
-
@source_route = SourceRoute.enable /nnnonsense/
|
18
|
-
assert @source_route
|
19
|
-
assert_equal @wrapper, SourceRoute.wrapper
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_catch_call_event
|
23
|
-
SourceRoute.enable do
|
24
|
-
event :call
|
25
|
-
method_id /nonsense/
|
26
|
-
output_format :test
|
27
|
-
end
|
28
|
-
SampleApp.new.nonsense
|
29
|
-
|
30
|
-
assert @wrapper.tp
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_catch_class_name_by_first_parameter
|
34
|
-
skip
|
35
|
-
# not supported yet
|
36
|
-
@source_route = SourceRoute.enable 'sampleapp'
|
37
|
-
SampleApp.new.nonsense
|
38
|
-
|
39
|
-
assert @wrapper.tp_attrs_results.size > 0
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_match_class_name
|
43
|
-
@source_route = SourceRoute.enable do
|
44
|
-
defined_class :SampleApp
|
45
|
-
end
|
46
|
-
|
47
|
-
SampleApp.new.nonsense
|
48
|
-
assert @wrapper.tp_attrs_results.size > 0
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_source_route_with_one_parameter
|
52
|
-
@source_route = SourceRoute.enable 'nonsense'
|
53
|
-
SampleApp.new.nonsense
|
54
|
-
|
55
|
-
ret_value = @wrapper.tp_attrs_results.last
|
56
|
-
assert_equal SampleApp, ret_value[:defined_class]
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_wrapper_reset
|
60
|
-
SourceRoute.enable 'nonsense'
|
61
|
-
SampleApp.new.nonsense
|
62
|
-
assert_equal 1, @wrapper.tp_attrs_results.size
|
63
|
-
|
64
|
-
SourceRoute.reset
|
65
|
-
SampleApp.new.nonsense
|
66
|
-
|
67
|
-
assert_equal 0, @wrapper.tp_attrs_results.size
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_source_route_with_block_only
|
71
|
-
paths = []
|
72
|
-
SourceRoute.enable 'nonsense' do
|
73
|
-
SampleApp.new.nonsense
|
74
|
-
output_format do |tp|
|
75
|
-
paths.push tp.path
|
76
|
-
end
|
77
|
-
end
|
78
|
-
SampleApp.new.nonsense
|
79
|
-
|
80
|
-
assert_equal 0, @wrapper.tp_attrs_results.size
|
81
|
-
assert_equal 1, paths.size
|
82
|
-
assert_includes paths.first, 'sample_app'
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_trace_with_c_call
|
86
|
-
SourceRoute.trace event: :c_call do
|
87
|
-
'abc'.upcase
|
88
|
-
end
|
89
|
-
|
90
|
-
assert_equal 2, @wrapper.tp_attrs_results.size
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_trace_without_first_hash_option
|
94
|
-
SourceRoute.trace output_format: :test do
|
95
|
-
SampleApp.new.nonsense
|
96
|
-
end
|
97
|
-
assert @wrapper.tp_attrs_results.size > 0
|
98
|
-
refute @wrapper.tp.enabled?
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_trace_two_events
|
102
|
-
SourceRoute.enable 'nonsense' do
|
103
|
-
event :call, :return
|
104
|
-
end
|
105
|
-
SampleApp.new.nonsense
|
106
|
-
assert_equal 2, @wrapper.tp_attrs_results.size
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_show_local_variables
|
110
|
-
SourceRoute.enable 'nonsense_with_params' do
|
111
|
-
output_include_local_variables
|
112
|
-
output_format :console
|
113
|
-
end
|
114
|
-
|
115
|
-
SampleApp.new.nonsense_with_params(88)
|
116
|
-
assert_equal 1, @wrapper.tp_attrs_results.size
|
117
|
-
|
118
|
-
ret_value = @wrapper.tp_attrs_results.last
|
119
|
-
|
120
|
-
assert_equal 88, ret_value[:local_var][:param1]
|
121
|
-
assert_equal nil, ret_value[:local_var][:param2]
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_track_local_var_when_event_is_return
|
125
|
-
SourceRoute.enable 'nonsense_with_params' do
|
126
|
-
event :return
|
127
|
-
output_include_local_variables
|
128
|
-
end
|
129
|
-
|
130
|
-
SampleApp.new.nonsense_with_params(88)
|
131
|
-
assert_equal 1, @wrapper.tp_attrs_results.size
|
132
|
-
|
133
|
-
ret_value_for_return_event = @wrapper.tp_attrs_results.last
|
134
|
-
assert_equal 88, ret_value_for_return_event[:local_var][:param1]
|
135
|
-
assert_equal 5, ret_value_for_return_event[:local_var][:param2]
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_show_instance_vars
|
139
|
-
@source_route = SourceRoute.enable 'nonsense' do
|
140
|
-
output_include_instance_variables
|
141
|
-
end
|
142
|
-
|
143
|
-
SampleApp.new('ins sure').nonsense_with_instance_var
|
144
|
-
|
145
|
-
assert_equal 2, @wrapper.tp_attrs_results.size
|
146
|
-
ret_value = @wrapper.tp_attrs_results.pop
|
147
|
-
|
148
|
-
assert_equal 'ins sure', ret_value[:instance_var][:@sample]
|
149
|
-
end
|
150
|
-
|
151
|
-
# Nothing has tested really when run rake cause ENV['ignore_html_generation'] was set to true
|
152
|
-
def test_html_format_output_only
|
153
|
-
@source_route = SourceRoute.enable do
|
154
|
-
defined_class 'SampleApp'
|
155
|
-
output_include_instance_variables
|
156
|
-
output_include_local_variables
|
157
|
-
end
|
158
|
-
|
159
|
-
SampleApp.new.init_cool_app
|
160
|
-
|
161
|
-
if ENV['ignore_html_generation'] == 'true'
|
162
|
-
# do nothing. it was set in Rakefile, so rake test will not generate html file
|
163
|
-
else
|
164
|
-
SourceRoute.build_html_output
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|