relevance-rcov 0.8.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/BLURB +149 -0
- data/CHANGES +177 -0
- data/LEGAL +36 -0
- data/LICENSE +56 -0
- data/Rakefile +93 -0
- data/THANKS +96 -0
- data/bin/rcov +560 -0
- data/doc/readme_for_api +41 -0
- data/doc/readme_for_emacs +64 -0
- data/doc/readme_for_rake +62 -0
- data/doc/readme_for_vim +47 -0
- data/editor-extensions/rcov.el +131 -0
- data/editor-extensions/rcov.vim +38 -0
- data/ext/rcovrt/1.8/callsite.c +242 -0
- data/ext/rcovrt/1.8/rcovrt.c +331 -0
- data/ext/rcovrt/1.9/callsite.c +258 -0
- data/ext/rcovrt/1.9/rcovrt.c +315 -0
- data/ext/rcovrt/extconf.rb +23 -0
- data/lib/rcov.rb +991 -0
- data/lib/rcov/lowlevel.rb +145 -0
- data/lib/rcov/rcovtask.rb +156 -0
- data/lib/rcov/report.rb +71 -0
- data/lib/rcov/rexml_extensions.rb +44 -0
- data/lib/rcov/version.rb +11 -0
- data/lib/rcov/xx.rb +754 -0
- data/setup.rb +1588 -0
- data/test/assets/sample_01.rb +7 -0
- data/test/assets/sample_02.rb +5 -0
- data/test/assets/sample_03.rb +20 -0
- data/test/assets/sample_04.rb +10 -0
- data/test/assets/sample_05-new.rb +17 -0
- data/test/assets/sample_05-old.rb +13 -0
- data/test/assets/sample_05.rb +17 -0
- data/test/call_site_analyzer_test.rb +171 -0
- data/test/code_coverage_analyzer_test.rb +188 -0
- data/test/file_statistics_test.rb +471 -0
- data/test/functional_test.rb +89 -0
- data/test/turn_off_rcovrt.rb +4 -0
- metadata +99 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module Rcov; module Test; module Temporary; class Sample03
|
3
|
+
def f1 # MUST NOT CHANGE the position or the tests will break
|
4
|
+
10.times { f2 }
|
5
|
+
end
|
6
|
+
|
7
|
+
def f2; 1 end
|
8
|
+
|
9
|
+
def f3
|
10
|
+
10.times{ f1 }
|
11
|
+
100.times{ f2 }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.g1
|
15
|
+
10.times{ g2 }
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.g2; 1 end
|
19
|
+
# safe from here ...
|
20
|
+
end end end end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestCallSiteAnalyzer < Test::Unit::TestCase
|
4
|
+
|
5
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_03.rb")
|
6
|
+
load sample_file
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@a = Rcov::CallSiteAnalyzer.new
|
10
|
+
@o = Rcov::Test::Temporary::Sample03.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def verify_callsites_equal(expected, actual)
|
14
|
+
callsites = expected.inject({}) do |s,(backtrace, count)|
|
15
|
+
unless $".any?{|x| %r{\brcovrt\b} =~ x}
|
16
|
+
backtrace = backtrace.map{|_, mid, file, line| [nil, mid, file, line] }
|
17
|
+
end
|
18
|
+
backtrace[0][2] = File.expand_path(backtrace[0][2])
|
19
|
+
s[Rcov::CallSiteAnalyzer::CallSite.new(backtrace)] = count
|
20
|
+
s
|
21
|
+
end
|
22
|
+
|
23
|
+
act_callsites = actual.inject({}) do |s, (key, value)|
|
24
|
+
#wow thats obtuse. In a callsite we have an array of arrays. We have to deep copy them because
|
25
|
+
# if we muck with the actual backtrace it messes things up for accumulation type tests.
|
26
|
+
# we have to muck with backtrace so that we can normalize file names (it's an issue between MRI and JRuby)
|
27
|
+
backtrace = key.backtrace.inject([]) {|y, val| y << val.inject([]) {|z, v2| z<< v2}}
|
28
|
+
backtrace[0][2] = File.expand_path(key.backtrace[0][2])
|
29
|
+
s[Rcov::CallSiteAnalyzer::CallSite.new(backtrace)] = value
|
30
|
+
s
|
31
|
+
end
|
32
|
+
assert_equal(callsites.to_s, act_callsites.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def verify_defsite_equal(expected, actual)
|
36
|
+
defsite = Rcov::CallSiteAnalyzer::DefSite.new(*expected)
|
37
|
+
defsite.file = File.expand_path defsite.file
|
38
|
+
actual.file = File.expand_path actual.file
|
39
|
+
assert_equal(defsite.to_s, actual.to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_callsite_compute_raw_difference
|
43
|
+
src = [
|
44
|
+
{ ["Foo", "foo"] => {"bar" => 1},
|
45
|
+
["Foo", "bar"] => {"baz" => 10} },
|
46
|
+
{ ["Foo", "foo"] => ["foo.rb", 10] }
|
47
|
+
]
|
48
|
+
dst = [
|
49
|
+
{ ["Foo", "foo"] => {"bar" => 1, "fubar" => 10},
|
50
|
+
["Foo", "baz"] => {"baz" => 10} },
|
51
|
+
{ ["Foo", "foo"] => ["fooredef.rb", 10],
|
52
|
+
["Foo", "baz"] => ["foo.rb", 20]}
|
53
|
+
]
|
54
|
+
expected = [
|
55
|
+
{ ["Foo", "foo"] => {"fubar" => 10},
|
56
|
+
["Foo", "baz"] => {"baz" => 10} },
|
57
|
+
{ ["Foo", "foo"] => ["fooredef.rb", 10],
|
58
|
+
["Foo", "baz"] => ["foo.rb", 20] }
|
59
|
+
]
|
60
|
+
|
61
|
+
assert_equal(expected,
|
62
|
+
@a.instance_eval{ compute_raw_data_difference(src, dst) } )
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_return_values_when_no_match
|
66
|
+
@a.run_hooked{ @o.f1 }
|
67
|
+
assert_equal(nil, @a.defsite("Foobar#bogus"))
|
68
|
+
assert_equal(nil, @a.defsite("Foobar", "bogus"))
|
69
|
+
assert_equal(nil, @a.callsites("Foobar", "bogus"))
|
70
|
+
assert_equal(nil, @a.callsites("Foobar.bogus"))
|
71
|
+
assert_equal(nil, @a.callsites("<Class:Foobar>", "bogus"))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_basic_defsite_recording
|
75
|
+
@a.run_hooked{ @o.f1 }
|
76
|
+
verify_defsite_equal(["./test/assets/sample_03.rb", 3], @a.defsite("Rcov::Test::Temporary::Sample03", "f1"))
|
77
|
+
verify_defsite_equal(["./test/assets/sample_03.rb", 7], @a.defsite("Rcov::Test::Temporary::Sample03", "f2"))
|
78
|
+
verify_defsite_equal(["./test/assets/sample_03.rb", 7], @a.defsite("Rcov::Test::Temporary::Sample03#f2"))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_basic_callsite_recording
|
82
|
+
@a.run_hooked{ @o.f1 }
|
83
|
+
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
84
|
+
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
85
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
86
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03#f2"))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_basic_callsite_recording_API
|
90
|
+
@a.run_hooked{ @o.f1 }
|
91
|
+
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
92
|
+
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
93
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
94
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
95
|
+
callsites = @a.callsites("Rcov::Test::Temporary::Sample03", "f2")
|
96
|
+
callsite = callsites.keys[0]
|
97
|
+
#expand path is used here to compensate for differences between JRuby and MRI
|
98
|
+
assert_equal(File.expand_path("./test/assets/sample_03.rb"), File.expand_path(callsite.file))
|
99
|
+
assert_equal(4, callsite.line)
|
100
|
+
assert_equal(:f1, callsite.calling_method)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def test_basic_callsite_recording_with_singleton_classes
|
105
|
+
@a.run_hooked{ @o.class.g1 }
|
106
|
+
assert(@a.analyzed_classes.include?("#<Class:Rcov::Test::Temporary::Sample03>"))
|
107
|
+
assert_equal(%w[g1 g2], @a.analyzed_methods("#<Class:Rcov::Test::Temporary::Sample03>"))
|
108
|
+
verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end, :g1, "./test/assets/sample_03.rb", 15]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03.g2"))
|
109
|
+
verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end, :g1, "./test/assets/sample_03.rb", 15]] => 10}, @a.callsites("#<Class:Rcov::Test::Temporary::Sample03>","g2"))
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def test_differential_callsite_recording
|
114
|
+
@a.run_hooked{ @o.f1 }
|
115
|
+
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
116
|
+
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
117
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
118
|
+
|
119
|
+
@a.run_hooked{ @o.f1 }
|
120
|
+
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
121
|
+
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
122
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 20}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
123
|
+
|
124
|
+
@a.run_hooked{ @o.f3 }
|
125
|
+
assert_equal(%w[f1 f2 f3], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
126
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 120,
|
127
|
+
[[Rcov::Test::Temporary::Sample03, :f3, "./test/assets/sample_03.rb", 11]] => 100 }, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_reset
|
131
|
+
@a.run_hooked do
|
132
|
+
10.times{ @o.f1 }
|
133
|
+
@a.reset
|
134
|
+
@o.f1
|
135
|
+
end
|
136
|
+
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
137
|
+
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
138
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_nested_callsite_recording
|
142
|
+
a = Rcov::CallSiteAnalyzer.new
|
143
|
+
b = Rcov::CallSiteAnalyzer.new
|
144
|
+
a.run_hooked do
|
145
|
+
b.run_hooked { @o.f1 }
|
146
|
+
assert(b.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
147
|
+
assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
148
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
149
|
+
|
150
|
+
@o.f1
|
151
|
+
assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
152
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
153
|
+
|
154
|
+
assert(a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
|
155
|
+
assert_equal(%w[f1 f2], a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
156
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 20}, a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
157
|
+
end
|
158
|
+
|
159
|
+
b.run_hooked{ @o.f3 }
|
160
|
+
assert_equal(%w[f1 f2 f3], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
|
161
|
+
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 110,
|
162
|
+
[[Rcov::Test::Temporary::Sample03, :f3, "./test/assets/sample_03.rb", 11]]=>100 }, b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_expand_name
|
166
|
+
assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo#foo") })
|
167
|
+
assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo", "foo") })
|
168
|
+
assert_equal(["#<Class:Foo>", "foo"], @a.instance_eval{ expand_name("Foo.foo") })
|
169
|
+
assert_equal(["#<Class:Foo>", "foo"], @a.instance_eval{ expand_name("#<Class:Foo>", "foo") })
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class TestCodeCoverageAnalyzer < Test::Unit::TestCase
|
4
|
+
LINES = <<-EOF.split "\n"
|
5
|
+
puts 1
|
6
|
+
if foo
|
7
|
+
bar
|
8
|
+
baz
|
9
|
+
end
|
10
|
+
5.times do
|
11
|
+
foo
|
12
|
+
bar if baz
|
13
|
+
end
|
14
|
+
EOF
|
15
|
+
|
16
|
+
def setup
|
17
|
+
if defined? Rcov::Test::Temporary
|
18
|
+
Rcov::Test::Temporary.constants.each do |name|
|
19
|
+
Rcov::Test::Temporary.module_eval{ remove_const(name) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_refine_coverage_info
|
25
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
26
|
+
cover = [1, 1, nil, nil, 0, 5, 5, 5, 0]
|
27
|
+
line_info, marked_info,
|
28
|
+
count_info = analyzer.instance_eval{ refine_coverage_info(LINES, cover) }
|
29
|
+
assert_equal(LINES, line_info)
|
30
|
+
assert_equal([true] * 2 + [false] * 3 + [true] * 3 + [false], marked_info)
|
31
|
+
assert_equal([1, 1, 0, 0, 0, 5, 5, 5, 0], count_info)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_analyzed_files_no_analysis
|
35
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
36
|
+
assert_equal([], analyzer.analyzed_files)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_raw_coverage_info
|
40
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
|
41
|
+
lines = File.readlines(sample_file)
|
42
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
43
|
+
analyzer.run_hooked{ load sample_file }
|
44
|
+
|
45
|
+
assert_equal(lines, SCRIPT_LINES__[sample_file][0, lines.size])
|
46
|
+
assert(analyzer.analyzed_files.include?(sample_file))
|
47
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
48
|
+
assert_equal(lines, line_info)
|
49
|
+
assert_equal([true, true, false, false, true, false, true], cov_info)
|
50
|
+
assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) unless PLATFORM =~ /java/
|
51
|
+
# JRUBY reports an if x==blah as hitting this type of line once, JRUBY also optimizes this stuff so you'd have to run with --debug to get "extra" information. MRI hits it twice.
|
52
|
+
assert_equal([1, 1, 0, 0, 1, 0, 11], count_info) if PLATFORM =~ /java/
|
53
|
+
analyzer.reset
|
54
|
+
assert_equal(nil, analyzer.data(sample_file))
|
55
|
+
assert_equal([], analyzer.analyzed_files)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_script_lines_workaround_detects_correctly
|
59
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
60
|
+
lines = ["puts a", "foo", "bar"] * 3
|
61
|
+
coverage = [true] * 3 + [false] * 6
|
62
|
+
counts = [1] * 3 + [0] * 6
|
63
|
+
nlines, ncoverage, ncounts = analyzer.instance_eval do
|
64
|
+
script_lines_workaround(lines, coverage, counts)
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_equal(["puts a", "foo", "bar"], nlines)
|
68
|
+
assert_equal([true, true, true], ncoverage)
|
69
|
+
assert_equal([1, 1, 1], ncounts)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_script_lines_workaround_no_false_positives
|
73
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
74
|
+
lines = ["puts a", "foo", "bar"] * 2 + ["puts a", "foo", "baz"]
|
75
|
+
coverage = [true] * 9
|
76
|
+
counts = [1] * 9
|
77
|
+
nlines, ncoverage, ncounts = analyzer.instance_eval do
|
78
|
+
script_lines_workaround(lines, coverage, counts)
|
79
|
+
end
|
80
|
+
assert_equal(lines, nlines)
|
81
|
+
assert_equal(coverage, ncoverage)
|
82
|
+
assert_equal(counts, ncounts)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_differential_coverage_data
|
86
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
|
87
|
+
lines = File.readlines(sample_file)
|
88
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
89
|
+
analyzer.run_hooked{ load sample_file }
|
90
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
91
|
+
assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) unless (defined? PLATFORM && PLATFORM =~ /java/) || RUBY_VERSION =~ /1.9/
|
92
|
+
# JRUBY reports an if x==blah as hitting this type of line once, JRUBY also optimizes this stuff so you'd have to run with --debug to get "extra" information. MRI hits it twice.
|
93
|
+
assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) if RUBY_VERSION =~ /1.9/
|
94
|
+
|
95
|
+
analyzer.reset
|
96
|
+
#set_trace_func proc { |event, file, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname if (file =~ /sample_02.rb/) }
|
97
|
+
|
98
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
99
|
+
analyzer.run_hooked{ load sample_file }
|
100
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
101
|
+
assert_equal([8, 1, 0, 0, 0], count_info) unless RUBY_VERSION =~ /1.9/
|
102
|
+
assert_equal([4, 1, 0, 0, 4], count_info) if RUBY_VERSION =~ /1.9/
|
103
|
+
|
104
|
+
analyzer.reset
|
105
|
+
assert_equal([], analyzer.analyzed_files)
|
106
|
+
analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
107
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
108
|
+
assert_equal([0, 1, 1, 1, 0], count_info) unless RUBY_VERSION =~ /1.9/
|
109
|
+
assert_equal([0, 2, 1, 0, 0], count_info) if RUBY_VERSION =~ /1.9/
|
110
|
+
analyzer.run_hooked do
|
111
|
+
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
112
|
+
end
|
113
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
114
|
+
assert_equal([0, 11, 11, 11, 0], count_info)
|
115
|
+
10.times{ analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) } }
|
116
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
117
|
+
assert_equal([0, 21, 21, 21, 0], count_info)
|
118
|
+
|
119
|
+
count_info2 = nil
|
120
|
+
10.times do |i|
|
121
|
+
analyzer.run_hooked do
|
122
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
123
|
+
line_info, cov_info, count_info = analyzer.data(sample_file) if i == 3
|
124
|
+
line_info2, cov_info2, count_info2 = analyzer.data(sample_file)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
assert_equal([0, 25, 25, 25, 0], count_info)
|
128
|
+
assert_equal([0, 31, 31, 31, 0], count_info2)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_nested_analyzer_blocks
|
132
|
+
a1 = Rcov::CodeCoverageAnalyzer.new
|
133
|
+
a2 = Rcov::CodeCoverageAnalyzer.new
|
134
|
+
|
135
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
136
|
+
load sample_file
|
137
|
+
|
138
|
+
a1.run_hooked do
|
139
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
140
|
+
a2.run_hooked do
|
141
|
+
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
142
|
+
end
|
143
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
144
|
+
end
|
145
|
+
|
146
|
+
a2.run_hooked do
|
147
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
148
|
+
10.times{ a1.run_hooked { Rcov::Test::Temporary::Sample02.foo(1, 1) } }
|
149
|
+
end
|
150
|
+
|
151
|
+
a1.install_hook
|
152
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
153
|
+
a1.remove_hook
|
154
|
+
|
155
|
+
a2.install_hook
|
156
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
157
|
+
a2.remove_hook
|
158
|
+
|
159
|
+
_, _, counts1 = a1.data(sample_file)
|
160
|
+
_, _, counts2 = a2.data(sample_file)
|
161
|
+
assert_equal([0, 221, 221, 221, 0], counts1)
|
162
|
+
assert_equal([0, 121, 121, 121, 0], counts2)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_reset
|
166
|
+
a1 = Rcov::CodeCoverageAnalyzer.new
|
167
|
+
|
168
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
169
|
+
load sample_file
|
170
|
+
|
171
|
+
a1.run_hooked do
|
172
|
+
100.times do |i|
|
173
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
174
|
+
a1.reset if i == 49
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
assert_equal([0, 50, 50, 50, 0], a1.data(sample_file)[2])
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_compute_raw_difference
|
182
|
+
first = {"a" => [1,1,1,1,1]}
|
183
|
+
last = {"a" => [2,1,5,2,1], "b" => [1,2,3,4,5]}
|
184
|
+
a = Rcov::CodeCoverageAnalyzer.new
|
185
|
+
assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
|
186
|
+
a.instance_eval{ compute_raw_data_difference(first, last)} )
|
187
|
+
end
|
188
|
+
end
|