rufus-treechecker 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +5 -0
- data/lib/rufus/treechecker.rb +2 -17
- data/spec/misc_spec.rb +62 -11
- metadata +1 -1
data/CHANGELOG.txt
CHANGED
data/lib/rufus/treechecker.rb
CHANGED
@@ -122,7 +122,7 @@ module Rufus
|
|
122
122
|
#
|
123
123
|
class TreeChecker
|
124
124
|
|
125
|
-
VERSION = '1.0.
|
125
|
+
VERSION = '1.0.6'
|
126
126
|
|
127
127
|
# pretty-prints the sexp tree of the given rubycode
|
128
128
|
#
|
@@ -179,12 +179,7 @@ module Rufus
|
|
179
179
|
#
|
180
180
|
def clone
|
181
181
|
|
182
|
-
|
183
|
-
tc.instance_variable_set(:@root_set, @root_set.clone)
|
184
|
-
tc.instance_variable_set(:@set, @set.clone)
|
185
|
-
tc.instance_variable_set(:@current_set, tc.instance_variable_get(:@set))
|
186
|
-
|
187
|
-
tc
|
182
|
+
Marshal.load(Marshal.dump(self))
|
188
183
|
end
|
189
184
|
|
190
185
|
# Adds a set of checks (rules) to this treechecker. Returns self.
|
@@ -220,16 +215,6 @@ module Rufus
|
|
220
215
|
@excluded_patterns = {} # 1st elt of pattern => pattern, excl_message
|
221
216
|
end
|
222
217
|
|
223
|
-
def clone
|
224
|
-
|
225
|
-
rs = RuleSet.new
|
226
|
-
rs.excluded_symbols = @excluded_symbols.dup
|
227
|
-
rs.accepted_patterns = @accepted_patterns.dup
|
228
|
-
rs.excluded_patterns = @excluded_patterns.dup
|
229
|
-
|
230
|
-
rs
|
231
|
-
end
|
232
|
-
|
233
218
|
def exclude_symbol(s, message)
|
234
219
|
|
235
220
|
@excluded_symbols[s] = (message || ":#{s} is excluded")
|
data/spec/misc_spec.rb
CHANGED
@@ -29,11 +29,10 @@ describe Rufus::TreeChecker do
|
|
29
29
|
|
30
30
|
tc1 = tc0.clone
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
attr_reader :set, :root_set
|
32
|
+
[ tc0, tc1 ].each do |tc|
|
33
|
+
class << tc
|
34
|
+
attr_reader :set, :root_set
|
35
|
+
end
|
37
36
|
end
|
38
37
|
|
39
38
|
tc1.set.object_id.should_not == tc0.set.object_id
|
@@ -43,7 +42,7 @@ describe Rufus::TreeChecker do
|
|
43
42
|
tc1.root_set.should == tc0.root_set
|
44
43
|
end
|
45
44
|
|
46
|
-
it "sets @current_set
|
45
|
+
it "sets @current_set correctly when cloning" do
|
47
46
|
|
48
47
|
tc0 = Rufus::TreeChecker.new
|
49
48
|
|
@@ -51,17 +50,69 @@ describe Rufus::TreeChecker do
|
|
51
50
|
|
52
51
|
tc1.add_rules do
|
53
52
|
exclude_def
|
53
|
+
exclude_raise
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
attr_reader :set, :root_set
|
56
|
+
[ tc0, tc1 ].each do |tc|
|
57
|
+
class << tc
|
58
|
+
attr_reader :set, :root_set
|
59
|
+
end
|
61
60
|
end
|
62
61
|
|
63
62
|
tc0.set.excluded_symbols.keys.should_not include(:defn)
|
64
63
|
tc1.set.excluded_symbols.keys.should include(:defn)
|
64
|
+
|
65
|
+
tc0.set.excluded_patterns.size.should == 0
|
66
|
+
tc1.set.excluded_patterns.size.should == 3
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does deep copy" do
|
70
|
+
|
71
|
+
tc0 = Rufus::TreeChecker.new do
|
72
|
+
|
73
|
+
exclude_fvccall :abort, :exit, :exit!
|
74
|
+
exclude_fvccall :system, :fork, :syscall, :trap, :require, :load
|
75
|
+
exclude_fvccall :at_exit
|
76
|
+
|
77
|
+
exclude_fvcall :private, :public, :protected
|
78
|
+
|
79
|
+
exclude_eval # no eval, module_eval or instance_eval
|
80
|
+
exclude_backquotes # no `rm -fR the/kitchen/sink`
|
81
|
+
exclude_alias # no alias or aliast_method
|
82
|
+
exclude_global_vars # $vars are off limits
|
83
|
+
exclude_module_tinkering # no module opening
|
84
|
+
|
85
|
+
exclude_rebinding Kernel # no 'k = Kernel'
|
86
|
+
|
87
|
+
exclude_access_to(
|
88
|
+
IO, File, FileUtils, Process, Signal, Thread, ThreadGroup)
|
89
|
+
|
90
|
+
exclude_call_to :instance_variable_get, :instance_variable_set
|
91
|
+
end
|
92
|
+
|
93
|
+
tc1 = tc0.clone
|
94
|
+
tc1.add_rules do
|
95
|
+
exclude_def
|
96
|
+
end
|
97
|
+
|
98
|
+
tc2 = tc0.clone
|
99
|
+
tc2.add_rules do
|
100
|
+
exclude_raise
|
101
|
+
end
|
102
|
+
|
103
|
+
[ tc0, tc1, tc2 ].each do |tc|
|
104
|
+
class << tc
|
105
|
+
attr_reader :set, :root_set
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
tc0.set.excluded_symbols.keys.size.should == 6
|
110
|
+
tc1.set.excluded_symbols.keys.size.should == 7
|
111
|
+
tc2.set.excluded_symbols.keys.size.should == 6
|
112
|
+
|
113
|
+
tc0.set.excluded_patterns[:fcall].size.should == 13
|
114
|
+
tc1.set.excluded_patterns[:fcall].size.should == 13
|
115
|
+
tc2.set.excluded_patterns[:fcall].size.should == 15
|
65
116
|
end
|
66
117
|
end
|
67
118
|
end
|