valo-rcov 0.8.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/BLURB +111 -0
  2. data/LICENSE +53 -0
  3. data/Rakefile +88 -0
  4. data/THANKS +96 -0
  5. data/bin/rcov +500 -0
  6. data/doc/readme_for_api +41 -0
  7. data/doc/readme_for_emacs +64 -0
  8. data/doc/readme_for_rake +62 -0
  9. data/doc/readme_for_vim +47 -0
  10. data/editor-extensions/rcov.el +131 -0
  11. data/editor-extensions/rcov.vim +38 -0
  12. data/ext/rcovrt/1.8/callsite.c +216 -0
  13. data/ext/rcovrt/1.8/rcovrt.c +287 -0
  14. data/ext/rcovrt/1.9/callsite.c +234 -0
  15. data/ext/rcovrt/1.9/rcovrt.c +264 -0
  16. data/ext/rcovrt/extconf.rb +21 -0
  17. data/lib/rcov.rb +1009 -0
  18. data/lib/rcov/formatters.rb +15 -0
  19. data/lib/rcov/formatters/base_formatter.rb +168 -0
  20. data/lib/rcov/formatters/full_text_report.rb +55 -0
  21. data/lib/rcov/formatters/html_coverage.rb +255 -0
  22. data/lib/rcov/formatters/html_erb_template.rb +128 -0
  23. data/lib/rcov/formatters/text_coverage_diff.rb +199 -0
  24. data/lib/rcov/formatters/text_report.rb +36 -0
  25. data/lib/rcov/formatters/text_summary.rb +15 -0
  26. data/lib/rcov/lowlevel.rb +145 -0
  27. data/lib/rcov/rcovtask.rb +156 -0
  28. data/lib/rcov/templates/detail.html.erb +78 -0
  29. data/lib/rcov/templates/index.html.erb +76 -0
  30. data/lib/rcov/templates/screen.css +165 -0
  31. data/lib/rcov/version.rb +10 -0
  32. data/setup.rb +1588 -0
  33. data/test/assets/sample_01.rb +7 -0
  34. data/test/assets/sample_02.rb +5 -0
  35. data/test/assets/sample_03.rb +20 -0
  36. data/test/assets/sample_04.rb +10 -0
  37. data/test/assets/sample_05-new.rb +17 -0
  38. data/test/assets/sample_05-old.rb +13 -0
  39. data/test/assets/sample_05.rb +17 -0
  40. data/test/call_site_analyzer_test.rb +171 -0
  41. data/test/code_coverage_analyzer_test.rb +184 -0
  42. data/test/file_statistics_test.rb +471 -0
  43. data/test/functional_test.rb +89 -0
  44. data/test/turn_off_rcovrt.rb +4 -0
  45. metadata +107 -0
@@ -0,0 +1,7 @@
1
+ a = 1
2
+ if a == 2
3
+ b = 1
4
+ else
5
+ b = 2
6
+ end
7
+ 10.times{ b += 1 }
@@ -0,0 +1,5 @@
1
+ module Rcov; module Test; module Temporary; module Sample02
2
+ def self.foo(a,b)
3
+ a + b
4
+ end
5
+ end end end end
@@ -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,10 @@
1
+ $: << File.dirname(__FILE__)
2
+ require 'sample_03'
3
+
4
+ klass = Rcov::Test::Temporary::Sample03
5
+ obj = klass.new
6
+ obj.f1
7
+ obj.f2
8
+ obj.f3
9
+ #klass.g1 uncovered
10
+ klass.g2
@@ -0,0 +1,17 @@
1
+ def d(x)
2
+ 4*x
3
+ end
4
+
5
+ def a
6
+ b 10
7
+ end
8
+
9
+ def b(x)
10
+ x*10
11
+ end
12
+
13
+ def c(x)
14
+ 3*x
15
+ end
16
+
17
+ a()
@@ -0,0 +1,13 @@
1
+ def a
2
+ b 10
3
+ end
4
+
5
+ def b(x)
6
+ x*10
7
+ end
8
+
9
+ def c(x)
10
+ 3*x
11
+ end
12
+
13
+ a()
@@ -0,0 +1,17 @@
1
+ def d(x)
2
+ 4*x
3
+ end
4
+
5
+ def a
6
+ b 10
7
+ end
8
+
9
+ def b(x)
10
+ x*10
11
+ end
12
+
13
+ def c(x)
14
+ 3*x
15
+ end
16
+
17
+ a()
@@ -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,184 @@
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)
51
+ analyzer.reset
52
+ assert_equal(nil, analyzer.data(sample_file))
53
+ assert_equal([], analyzer.analyzed_files)
54
+ end
55
+
56
+ def test_script_lines_workaround_detects_correctly
57
+ analyzer = Rcov::CodeCoverageAnalyzer.new
58
+ lines = ["puts a", "foo", "bar"] * 3
59
+ coverage = [true] * 3 + [false] * 6
60
+ counts = [1] * 3 + [0] * 6
61
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
62
+ script_lines_workaround(lines, coverage, counts)
63
+ end
64
+
65
+ assert_equal(["puts a", "foo", "bar"], nlines)
66
+ assert_equal([true, true, true], ncoverage)
67
+ assert_equal([1, 1, 1], ncounts)
68
+ end
69
+
70
+ def test_script_lines_workaround_no_false_positives
71
+ analyzer = Rcov::CodeCoverageAnalyzer.new
72
+ lines = ["puts a", "foo", "bar"] * 2 + ["puts a", "foo", "baz"]
73
+ coverage = [true] * 9
74
+ counts = [1] * 9
75
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
76
+ script_lines_workaround(lines, coverage, counts)
77
+ end
78
+ assert_equal(lines, nlines)
79
+ assert_equal(coverage, ncoverage)
80
+ assert_equal(counts, ncounts)
81
+ end
82
+
83
+ def test_differential_coverage_data
84
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
85
+ lines = File.readlines(sample_file)
86
+ analyzer = Rcov::CodeCoverageAnalyzer.new
87
+ analyzer.run_hooked{ load sample_file }
88
+ line_info, cov_info, count_info = analyzer.data(sample_file)
89
+ assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) if RUBY_VERSION =~ /1.9/
90
+
91
+ analyzer.reset
92
+ #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/) }
93
+
94
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
95
+ analyzer.run_hooked{ load sample_file }
96
+ line_info, cov_info, count_info = analyzer.data(sample_file)
97
+ assert_equal([8, 1, 0, 0, 0], count_info) unless RUBY_VERSION =~ /1.9/
98
+ assert_equal([4, 1, 0, 0, 4], count_info) if RUBY_VERSION =~ /1.9/
99
+
100
+ analyzer.reset
101
+ assert_equal([], analyzer.analyzed_files)
102
+ analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
103
+ line_info, cov_info, count_info = analyzer.data(sample_file)
104
+ assert_equal([0, 1, 1, 1, 0], count_info) unless RUBY_VERSION =~ /1.9/
105
+ assert_equal([0, 2, 1, 0, 0], count_info) if RUBY_VERSION =~ /1.9/
106
+ analyzer.run_hooked do
107
+ 10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
108
+ end
109
+ line_info, cov_info, count_info = analyzer.data(sample_file)
110
+ assert_equal([0, 11, 11, 11, 0], count_info)
111
+ 10.times{ analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) } }
112
+ line_info, cov_info, count_info = analyzer.data(sample_file)
113
+ assert_equal([0, 21, 21, 21, 0], count_info)
114
+
115
+ count_info2 = nil
116
+ 10.times do |i|
117
+ analyzer.run_hooked do
118
+ Rcov::Test::Temporary::Sample02.foo(1, 1)
119
+ line_info, cov_info, count_info = analyzer.data(sample_file) if i == 3
120
+ line_info2, cov_info2, count_info2 = analyzer.data(sample_file)
121
+ end
122
+ end
123
+ assert_equal([0, 25, 25, 25, 0], count_info)
124
+ assert_equal([0, 31, 31, 31, 0], count_info2)
125
+ end
126
+
127
+ def test_nested_analyzer_blocks
128
+ a1 = Rcov::CodeCoverageAnalyzer.new
129
+ a2 = Rcov::CodeCoverageAnalyzer.new
130
+
131
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
132
+ load sample_file
133
+
134
+ a1.run_hooked do
135
+ 100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
136
+ a2.run_hooked do
137
+ 10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
138
+ end
139
+ 100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
140
+ end
141
+
142
+ a2.run_hooked do
143
+ 100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
144
+ 10.times{ a1.run_hooked { Rcov::Test::Temporary::Sample02.foo(1, 1) } }
145
+ end
146
+
147
+ a1.install_hook
148
+ Rcov::Test::Temporary::Sample02.foo(1, 1)
149
+ a1.remove_hook
150
+
151
+ a2.install_hook
152
+ Rcov::Test::Temporary::Sample02.foo(1, 1)
153
+ a2.remove_hook
154
+
155
+ _, _, counts1 = a1.data(sample_file)
156
+ _, _, counts2 = a2.data(sample_file)
157
+ assert_equal([0, 221, 221, 221, 0], counts1)
158
+ assert_equal([0, 121, 121, 121, 0], counts2)
159
+ end
160
+
161
+ def test_reset
162
+ a1 = Rcov::CodeCoverageAnalyzer.new
163
+
164
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
165
+ load sample_file
166
+
167
+ a1.run_hooked do
168
+ 100.times do |i|
169
+ Rcov::Test::Temporary::Sample02.foo(1, 1)
170
+ a1.reset if i == 49
171
+ end
172
+ end
173
+
174
+ assert_equal([0, 50, 50, 50, 0], a1.data(sample_file)[2])
175
+ end
176
+
177
+ def test_compute_raw_difference
178
+ first = {"a" => [1,1,1,1,1]}
179
+ last = {"a" => [2,1,5,2,1], "b" => [1,2,3,4,5]}
180
+ a = Rcov::CodeCoverageAnalyzer.new
181
+ assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
182
+ a.instance_eval{ compute_raw_data_difference(first, last)} )
183
+ end
184
+ end