relevance-rcov 0.9.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/BLURB +111 -0
- data/LICENSE +53 -0
- data/Rakefile +94 -0
- data/THANKS +110 -0
- data/bin/rcov +514 -0
- data/doc/readme_for_api.markdown +22 -0
- data/doc/readme_for_emacs.markdown +52 -0
- data/doc/readme_for_rake.markdown +51 -0
- data/doc/readme_for_vim.markdown +34 -0
- data/editor-extensions/rcov.el +131 -0
- data/editor-extensions/rcov.vim +38 -0
- data/ext/java/src/CallsiteHook.java +137 -0
- data/ext/java/src/CoverageHook.java +117 -0
- data/ext/java/src/RcovHook.java +9 -0
- data/ext/java/src/RcovrtService.java +130 -0
- data/lib/rcov.rb +33 -0
- data/lib/rcov/call_site_analyzer.rb +225 -0
- data/lib/rcov/code_coverage_analyzer.rb +268 -0
- data/lib/rcov/coverage_info.rb +36 -0
- data/lib/rcov/differential_analyzer.rb +116 -0
- data/lib/rcov/file_statistics.rb +334 -0
- data/lib/rcov/formatters.rb +13 -0
- data/lib/rcov/formatters/base_formatter.rb +173 -0
- data/lib/rcov/formatters/failure_report.rb +15 -0
- data/lib/rcov/formatters/full_text_report.rb +48 -0
- data/lib/rcov/formatters/html_coverage.rb +274 -0
- data/lib/rcov/formatters/html_erb_template.rb +62 -0
- data/lib/rcov/formatters/text_coverage_diff.rb +193 -0
- data/lib/rcov/formatters/text_report.rb +32 -0
- data/lib/rcov/formatters/text_summary.rb +11 -0
- data/lib/rcov/lowlevel.rb +146 -0
- data/lib/rcov/rcovtask.rb +155 -0
- data/lib/rcov/templates/detail.html.erb +64 -0
- data/lib/rcov/templates/index.html.erb +93 -0
- data/lib/rcov/templates/jquery-1.3.2.min.js +19 -0
- data/lib/rcov/templates/jquery.tablesorter.min.js +15 -0
- data/lib/rcov/templates/print.css +12 -0
- data/lib/rcov/templates/rcov.js +42 -0
- data/lib/rcov/templates/screen.css +270 -0
- data/lib/rcov/version.rb +10 -0
- data/lib/rcovrt.jar +0 -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/assets/sample_06.rb +8 -0
- data/test/call_site_analyzer_test.rb +171 -0
- data/test/code_coverage_analyzer_test.rb +219 -0
- data/test/file_statistics_test.rb +471 -0
- data/test/functional_test.rb +91 -0
- data/test/turn_off_rcovrt.rb +4 -0
- metadata +115 -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,219 @@
|
|
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 RUBY_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, 3, 0, 0, 1, 0, 33], count_info) if RUBY_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_if_elsif_reports_correctly
|
86
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_06.rb")
|
87
|
+
lines = File.readlines(sample_file)
|
88
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
89
|
+
analyzer.run_hooked{ load sample_file }
|
90
|
+
assert_equal(lines, SCRIPT_LINES__[sample_file][0, lines.size])
|
91
|
+
assert(analyzer.analyzed_files.include?(sample_file))
|
92
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
93
|
+
assert_equal(lines, line_info)
|
94
|
+
assert_equal([true, true, false, true, true, false, false, false], cov_info) unless RUBY_PLATFORM == "java"
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_differential_coverage_data
|
98
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
|
99
|
+
lines = File.readlines(sample_file)
|
100
|
+
analyzer = Rcov::CodeCoverageAnalyzer.new
|
101
|
+
analyzer.run_hooked{ load sample_file }
|
102
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
103
|
+
assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) if RUBY_VERSION =~ /1.9/
|
104
|
+
|
105
|
+
analyzer.reset
|
106
|
+
#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/) }
|
107
|
+
|
108
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
109
|
+
analyzer.run_hooked{ load sample_file }
|
110
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
111
|
+
if RUBY_PLATFORM == "java"
|
112
|
+
assert_equal([8, 3, 0, 0, 0], count_info)
|
113
|
+
else
|
114
|
+
assert_equal([8, 1, 0, 0, 0], count_info) unless RUBY_VERSION =~ /1.9/
|
115
|
+
assert_equal([4, 1, 0, 0, 4], count_info) if RUBY_VERSION =~ /1.9/
|
116
|
+
end
|
117
|
+
|
118
|
+
analyzer.reset
|
119
|
+
assert_equal([], analyzer.analyzed_files)
|
120
|
+
analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
121
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
122
|
+
if RUBY_PLATFORM == "java"
|
123
|
+
assert_equal([0, 1, 3, 1, 0], count_info) unless RUBY_VERSION =~ /1.9/
|
124
|
+
else
|
125
|
+
assert_equal([0, 1, 1, 1, 0], count_info) unless RUBY_VERSION =~ /1.9/
|
126
|
+
assert_equal([0, 2, 1, 0, 0], count_info) if RUBY_VERSION =~ /1.9/
|
127
|
+
end
|
128
|
+
analyzer.run_hooked do
|
129
|
+
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
130
|
+
end
|
131
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
132
|
+
assert_equal([0, 11, 33, 11, 0], count_info) if RUBY_PLATFORM == "java"
|
133
|
+
assert_equal([0, 11, 11, 11, 0], count_info) unless RUBY_PLATFORM == "java"
|
134
|
+
10.times{ analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) } }
|
135
|
+
line_info, cov_info, count_info = analyzer.data(sample_file)
|
136
|
+
assert_equal([0, 21, 63, 21, 0], count_info) if RUBY_PLATFORM == "java"
|
137
|
+
assert_equal([0, 21, 21, 21, 0], count_info) unless RUBY_PLATFORM == "java"
|
138
|
+
|
139
|
+
count_info2 = nil
|
140
|
+
10.times do |i|
|
141
|
+
analyzer.run_hooked do
|
142
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
143
|
+
line_info, cov_info, count_info = analyzer.data(sample_file) if i == 3
|
144
|
+
line_info2, cov_info2, count_info2 = analyzer.data(sample_file)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
if RUBY_PLATFORM == "java"
|
148
|
+
assert_equal([0, 25, 75, 25, 0], count_info)
|
149
|
+
assert_equal([0, 31, 93, 31, 0], count_info2)
|
150
|
+
else
|
151
|
+
assert_equal([0, 25, 25, 25, 0], count_info)
|
152
|
+
assert_equal([0, 31, 31, 31, 0], count_info2)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_nested_analyzer_blocks
|
157
|
+
a1 = Rcov::CodeCoverageAnalyzer.new
|
158
|
+
a2 = Rcov::CodeCoverageAnalyzer.new
|
159
|
+
|
160
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
161
|
+
load sample_file
|
162
|
+
|
163
|
+
a1.run_hooked do
|
164
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
165
|
+
a2.run_hooked do
|
166
|
+
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
167
|
+
end
|
168
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
169
|
+
end
|
170
|
+
|
171
|
+
a2.run_hooked do
|
172
|
+
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
|
173
|
+
10.times{ a1.run_hooked { Rcov::Test::Temporary::Sample02.foo(1, 1) } }
|
174
|
+
end
|
175
|
+
|
176
|
+
a1.install_hook
|
177
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
178
|
+
a1.remove_hook
|
179
|
+
|
180
|
+
a2.install_hook
|
181
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
182
|
+
a2.remove_hook
|
183
|
+
|
184
|
+
_, _, counts1 = a1.data(sample_file)
|
185
|
+
_, _, counts2 = a2.data(sample_file)
|
186
|
+
if RUBY_PLATFORM == "java"
|
187
|
+
assert_equal([0, 221, 663, 221, 0], counts1)
|
188
|
+
assert_equal([0, 121, 363, 121, 0], counts2)
|
189
|
+
else
|
190
|
+
assert_equal([0, 221, 221, 221, 0], counts1)
|
191
|
+
assert_equal([0, 121, 121, 121, 0], counts2)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_reset
|
196
|
+
a1 = Rcov::CodeCoverageAnalyzer.new
|
197
|
+
|
198
|
+
sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
|
199
|
+
load sample_file
|
200
|
+
|
201
|
+
a1.run_hooked do
|
202
|
+
100.times do |i|
|
203
|
+
Rcov::Test::Temporary::Sample02.foo(1, 1)
|
204
|
+
a1.reset if i == 49
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
assert_equal([0, 50, 50, 50, 0], a1.data(sample_file)[2]) unless RUBY_PLATFORM == "java"
|
209
|
+
assert_equal([0, 50, 150, 50, 0], a1.data(sample_file)[2]) if RUBY_PLATFORM == "java"
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_compute_raw_difference
|
213
|
+
first = {"a" => [1,1,1,1,1]}
|
214
|
+
last = {"a" => [2,1,5,2,1], "b" => [1,2,3,4,5]}
|
215
|
+
a = Rcov::CodeCoverageAnalyzer.new
|
216
|
+
assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
|
217
|
+
a.instance_eval{ compute_raw_data_difference(first, last)} )
|
218
|
+
end
|
219
|
+
end
|