jsinstrument 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -162,7 +162,14 @@
162
162
  }
163
163
 
164
164
  // register the instrumented lines for current file
165
- root.%{js_object_name}.register('%{src_filename}', %{instrumented_lines}, %{instrumented_func_lines});
165
+ root.%{js_object_name}.register('%{src_filename}',
166
+ // line coverage
167
+ %{instrumented_lines},
168
+ // function coverage
169
+ %{instrumented_func_lines},
170
+ // branch coverage
171
+ %{instrumented_branch_lines}
172
+ );
166
173
  }(this);
167
174
 
168
175
 
@@ -22,7 +22,7 @@ module JSInstrument
22
22
  self.src_filename = filename
23
23
  ast = RKelly::Parser.new.parse src
24
24
  raise 'Parse source failed.' unless ast
25
- ast, instrumented_lines, instrumented_func_lines = instrument_ast ast
25
+ ast, instrumented_lines, instrumented_func_lines, instrumented_branch_lines = instrument_ast ast
26
26
  instrumented_src = ast.to_ecma
27
27
 
28
28
  inserting = File.open(File.dirname(__FILE__) + '/inserting.js').read
@@ -36,7 +36,8 @@ module JSInstrument
36
36
  batch_text: self.batch_text,
37
37
  data_compress_method: self.data_compress_method,
38
38
  instrumented_lines: instrumented_lines,
39
- instrumented_func_lines: instrumented_func_lines
39
+ instrumented_func_lines: instrumented_func_lines,
40
+ instrumented_branch_lines: instrumented_branch_lines
40
41
  }
41
42
 
42
43
  (inserting % bindings) + instrumented_src
@@ -48,11 +49,12 @@ module JSInstrument
48
49
  ast = RKelly::Visitors::ParentBuilder.new.build ast
49
50
  instrumented_lines = Set.new
50
51
  instrumented_func_lines = Set.new
52
+ instrumented_branch_lines = Set.new
51
53
  ast.each do |node|
52
54
  parent = node.parent
53
55
  line = node.line
54
- node_classname = node.class.name.split(/::/)[-1].sub('Node', '')
55
- parent_classname = parent.class.name.split(/::/)[-1].sub('Node', '')
56
+ node_classname = get_node_classname node
57
+ parent_classname = get_node_classname parent
56
58
 
57
59
  # instrument only if we can get the line no. and we haven't instrumented it
58
60
 
@@ -93,6 +95,7 @@ module JSInstrument
93
95
  end
94
96
  end
95
97
  end
98
+
96
99
  # function coverage
97
100
  #
98
101
  if line and not instrumented_func_lines.member? line
@@ -103,11 +106,31 @@ module JSInstrument
103
106
  end
104
107
  end
105
108
  end
109
+
110
+ # branch coverage
111
+ #
112
+ if line and not instrumented_branch_lines.member? line
113
+ if 'If' == parent_classname
114
+ if 'Block' == node_classname
115
+ if parent.value.eql? node
116
+ instrumented_branch_lines.add line
117
+ insert_hitbranch_in node
118
+ elsif parent.else.eql? node
119
+ instrumented_branch_lines.add line
120
+ insert_hitbranch_in node
121
+ end
122
+ end
123
+ end
124
+ end
106
125
  end
107
- [ast, instrumented_lines.sort, instrumented_func_lines.sort]
126
+ [ast, instrumented_lines.sort, instrumented_func_lines.sort, instrumented_branch_lines.sort]
108
127
  end
109
128
 
110
129
  private
130
+ def get_node_classname node
131
+ node.class.name.split(/::/)[-1].sub('Node', '')
132
+ end
133
+
111
134
  def get_hit_call line, func
112
135
  ExpressionStatementNode.new(
113
136
  FunctionCallNode.new(
@@ -152,5 +175,9 @@ module JSInstrument
152
175
  function_body_node.value.value.unshift get_hit_call(line, "hit_func")
153
176
  end
154
177
 
178
+ def insert_hitbranch_in block_node
179
+ # Block.value(SourceElement).value(array).unshift hit_func
180
+ block_node.value.value.unshift get_hit_call(block_node.line, "hit_branch")
181
+ end
155
182
  end
156
183
  end
@@ -1,3 +1,3 @@
1
1
  module JSInstrument
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsinstrument
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: