rcov 0.8.1.2.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/BLURB +2 -40
  2. data/LICENSE +2 -5
  3. data/Rakefile +32 -106
  4. data/THANKS +14 -0
  5. data/bin/rcov +277 -1090
  6. data/doc/readme_for_api.markdown +22 -0
  7. data/doc/readme_for_emacs.markdown +52 -0
  8. data/doc/readme_for_rake.markdown +51 -0
  9. data/doc/readme_for_vim.markdown +34 -0
  10. data/{rcov.el → editor-extensions/rcov.el} +0 -0
  11. data/{rcov.vim → editor-extensions/rcov.vim} +0 -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 +12 -2
  17. data/lib/rcov.rb +13 -968
  18. data/lib/rcov/call_site_analyzer.rb +225 -0
  19. data/lib/rcov/code_coverage_analyzer.rb +268 -0
  20. data/lib/rcov/coverage_info.rb +36 -0
  21. data/lib/rcov/differential_analyzer.rb +116 -0
  22. data/lib/rcov/file_statistics.rb +334 -0
  23. data/lib/rcov/formatters.rb +13 -0
  24. data/lib/rcov/formatters/base_formatter.rb +173 -0
  25. data/lib/rcov/formatters/failure_report.rb +15 -0
  26. data/lib/rcov/formatters/full_text_report.rb +48 -0
  27. data/lib/rcov/formatters/html_coverage.rb +274 -0
  28. data/lib/rcov/formatters/html_erb_template.rb +62 -0
  29. data/lib/rcov/formatters/text_coverage_diff.rb +193 -0
  30. data/lib/rcov/formatters/text_report.rb +32 -0
  31. data/lib/rcov/formatters/text_summary.rb +11 -0
  32. data/lib/rcov/lowlevel.rb +16 -17
  33. data/lib/rcov/rcovtask.rb +21 -22
  34. data/lib/rcov/templates/detail.html.erb +64 -0
  35. data/lib/rcov/templates/index.html.erb +93 -0
  36. data/lib/rcov/templates/jquery-1.3.2.min.js +19 -0
  37. data/lib/rcov/templates/jquery.tablesorter.min.js +15 -0
  38. data/lib/rcov/templates/print.css +12 -0
  39. data/lib/rcov/templates/rcov.js +42 -0
  40. data/lib/rcov/templates/screen.css +270 -0
  41. data/lib/rcov/version.rb +5 -8
  42. data/setup.rb +5 -2
  43. data/test/{sample_01.rb → assets/sample_01.rb} +0 -0
  44. data/test/{sample_02.rb → assets/sample_02.rb} +0 -0
  45. data/test/{sample_03.rb → assets/sample_03.rb} +0 -0
  46. data/test/{sample_04.rb → assets/sample_04.rb} +0 -0
  47. data/test/{sample_05-new.rb → assets/sample_05-new.rb} +0 -0
  48. data/test/{sample_05-old.rb → assets/sample_05-old.rb} +0 -0
  49. data/test/{sample_05.rb → assets/sample_05.rb} +0 -0
  50. data/test/{test_CallSiteAnalyzer.rb → call_site_analyzer_test.rb} +57 -81
  51. data/test/{test_CodeCoverageAnalyzer.rb → code_coverage_analyzer_test.rb} +71 -35
  52. data/test/{test_FileStatistics.rb → file_statistics_test.rb} +34 -36
  53. data/test/{test_functional.rb → functional_test.rb} +21 -35
  54. metadata +91 -69
  55. data/CHANGES +0 -177
  56. data/LEGAL +0 -36
  57. data/README.API +0 -42
  58. data/README.emacs +0 -64
  59. data/README.en +0 -130
  60. data/README.rake +0 -62
  61. data/README.rant +0 -68
  62. data/README.vim +0 -47
  63. data/Rantfile +0 -76
  64. data/ext/rcovrt/callsite.c +0 -242
  65. data/ext/rcovrt/rcovrt.c +0 -329
  66. data/lib/rcov/rant.rb +0 -87
  67. data/lib/rcov/report.rb +0 -1236
  68. data/mingw-rbconfig.rb +0 -174
data/lib/rcov/version.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  # rcov Copyright (c) 2004-2006 Mauricio Fernandez <mfp@acm.org>
2
2
  #
3
- # See LEGAL and LICENSE for licensing information.
3
+ # See LICENSE for licensing information.
4
4
 
5
5
  module Rcov
6
-
7
- VERSION = "0.8.1.2"
8
- RELEASE_DATE = "2007-11-22"
9
- RCOVRT_ABI = [2,0,0]
10
- UPSTREAM_URL = "http://eigenclass.org/hiki/rcov"
11
-
6
+ VERSION = "0.9.3"
7
+ RELEASE_DATE = "2009-09-25"
8
+ RCOVRT_ABI = [2,0,0]
9
+ UPSTREAM_URL = "http://github.com/relevance/rcov"
12
10
  end
13
- # vi: set sw=2:
data/setup.rb CHANGED
@@ -1255,7 +1255,7 @@ class Installer
1255
1255
  alias setup_dir_lib noop
1256
1256
 
1257
1257
  def setup_dir_ext(rel)
1258
- make if extdir?(curr_srcdir())
1258
+ make if extdir?(curr_srcdir()) and File.exist?("#{curr_srcdir()}/Makefile")
1259
1259
  end
1260
1260
 
1261
1261
  alias setup_dir_data noop
@@ -1288,7 +1288,10 @@ class Installer
1288
1288
  if /\Aruby/ =~ File.basename(old.cmd)
1289
1289
  Shebang.new(config('rubypath'), old.args)
1290
1290
  elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
1291
- Shebang.new(config('rubypath'), old.args[1..-1])
1291
+ puts "Skipping shebang rename"
1292
+ # We don't want this to happen anymore, it doesn't make sense
1293
+ # Shebang.new(config('rubypath'), old.args[1..-1])
1294
+ old
1292
1295
  else
1293
1296
  return old unless config('shebang') == 'all'
1294
1297
  Shebang.new(config('rubypath'))
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,11 +1,8 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
1
2
 
3
+ class TestCallSiteAnalyzer < Test::Unit::TestCase
2
4
 
3
- require 'test/unit'
4
- require 'rcov'
5
-
6
- class Test_CallSiteAnalyzer < Test::Unit::TestCase
7
-
8
- sample_file = File.join(File.dirname(__FILE__), "sample_03.rb")
5
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_03.rb")
9
6
  load sample_file
10
7
 
11
8
  def setup
@@ -14,40 +11,54 @@ class Test_CallSiteAnalyzer < Test::Unit::TestCase
14
11
  end
15
12
 
16
13
  def verify_callsites_equal(expected, actual)
17
- callsites = expected.inject({}) do |s,(backtrace, count)|
14
+ callsites = expected.inject({}) do |s,(backtrace, count)|
18
15
  unless $".any?{|x| %r{\brcovrt\b} =~ x}
19
16
  backtrace = backtrace.map{|_, mid, file, line| [nil, mid, file, line] }
20
17
  end
18
+ backtrace[0][2] = File.expand_path(backtrace[0][2])
21
19
  s[Rcov::CallSiteAnalyzer::CallSite.new(backtrace)] = count
22
20
  s
23
21
  end
24
- assert_equal(callsites, actual)
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)
25
33
  end
26
34
 
27
35
  def verify_defsite_equal(expected, actual)
28
- assert_equal(Rcov::CallSiteAnalyzer::DefSite.new(*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)
29
40
  end
30
41
 
31
42
  def test_callsite_compute_raw_difference
32
- src = [
43
+ src = [
33
44
  { ["Foo", "foo"] => {"bar" => 1},
34
- ["Foo", "bar"] => {"baz" => 10} },
35
- { ["Foo", "foo"] => ["foo.rb", 10] }
45
+ ["Foo", "bar"] => {"baz" => 10} },
46
+ { ["Foo", "foo"] => ["foo.rb", 10] }
36
47
  ]
37
- dst = [
48
+ dst = [
38
49
  { ["Foo", "foo"] => {"bar" => 1, "fubar" => 10},
39
50
  ["Foo", "baz"] => {"baz" => 10} },
40
51
  { ["Foo", "foo"] => ["fooredef.rb", 10],
41
52
  ["Foo", "baz"] => ["foo.rb", 20]}
42
53
  ]
43
- expected = [
54
+ expected = [
44
55
  { ["Foo", "foo"] => {"fubar" => 10},
45
56
  ["Foo", "baz"] => {"baz" => 10} },
46
57
  { ["Foo", "foo"] => ["fooredef.rb", 10],
47
- ["Foo", "baz"] => ["foo.rb", 20] }
58
+ ["Foo", "baz"] => ["foo.rb", 20] }
48
59
  ]
49
-
50
- assert_equal(expected,
60
+
61
+ assert_equal(expected,
51
62
  @a.instance_eval{ compute_raw_data_difference(src, dst) } )
52
63
  end
53
64
 
@@ -62,55 +73,40 @@ class Test_CallSiteAnalyzer < Test::Unit::TestCase
62
73
 
63
74
  def test_basic_defsite_recording
64
75
  @a.run_hooked{ @o.f1 }
65
- verify_defsite_equal(["./test/sample_03.rb", 3],
66
- @a.defsite("Rcov::Test::Temporary::Sample03", "f1"))
67
- verify_defsite_equal(["./test/sample_03.rb", 7],
68
- @a.defsite("Rcov::Test::Temporary::Sample03", "f2"))
69
- verify_defsite_equal(["./test/sample_03.rb", 7],
70
- @a.defsite("Rcov::Test::Temporary::Sample03#f2"))
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"))
71
79
  end
72
80
 
73
81
  def test_basic_callsite_recording
74
82
  @a.run_hooked{ @o.f1 }
75
83
  assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
76
84
  assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
77
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
78
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
79
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
80
- @a.callsites("Rcov::Test::Temporary::Sample03#f2"))
81
- #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
82
- # @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
83
- #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
84
- # @a.callsites("Rcov::Test::Temporary::Sample03#f2"))
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"))
85
87
  end
86
88
 
87
89
  def test_basic_callsite_recording_API
88
90
  @a.run_hooked{ @o.f1 }
89
91
  assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
90
92
  assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
91
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
92
- "./test/sample_03.rb", 4]] => 10},
93
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
94
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
95
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
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"))
96
95
  callsites = @a.callsites("Rcov::Test::Temporary::Sample03", "f2")
97
96
  callsite = callsites.keys[0]
98
- assert_equal("./test/sample_03.rb", callsite.file)
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
99
  assert_equal(4, callsite.line)
100
100
  assert_equal(:f1, callsite.calling_method)
101
101
  end
102
-
103
-
102
+
103
+
104
104
  def test_basic_callsite_recording_with_singleton_classes
105
105
  @a.run_hooked{ @o.class.g1 }
106
106
  assert(@a.analyzed_classes.include?("#<Class:Rcov::Test::Temporary::Sample03>"))
107
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,
109
- :g1, "./test/sample_03.rb", 15]] => 10},
110
- @a.callsites("Rcov::Test::Temporary::Sample03.g2"))
111
- verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end,
112
- :g1, "./test/sample_03.rb", 15]] => 10},
113
- @a.callsites("#<Class:Rcov::Test::Temporary::Sample03>","g2"))
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"))
114
110
  end
115
111
 
116
112
 
@@ -118,24 +114,17 @@ class Test_CallSiteAnalyzer < Test::Unit::TestCase
118
114
  @a.run_hooked{ @o.f1 }
119
115
  assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
120
116
  assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
121
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
122
- "./test/sample_03.rb", 4]] => 10},
123
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
117
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
124
118
 
125
119
  @a.run_hooked{ @o.f1 }
126
120
  assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
127
121
  assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
128
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
129
- "./test/sample_03.rb", 4]] => 20},
130
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
131
-
122
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 20}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
123
+
132
124
  @a.run_hooked{ @o.f3 }
133
125
  assert_equal(%w[f1 f2 f3], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
134
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
135
- "./test/sample_03.rb", 4]] => 120,
136
- [[Rcov::Test::Temporary::Sample03, :f3,
137
- "./test/sample_03.rb", 11]]=>100 },
138
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
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"))
139
128
  end
140
129
 
141
130
  def test_reset
@@ -146,50 +135,37 @@ class Test_CallSiteAnalyzer < Test::Unit::TestCase
146
135
  end
147
136
  assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
148
137
  assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
149
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
150
- "./test/sample_03.rb", 4]] => 10},
151
- @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
152
-
138
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
153
139
  end
154
140
 
155
141
  def test_nested_callsite_recording
156
142
  a = Rcov::CallSiteAnalyzer.new
157
143
  b = Rcov::CallSiteAnalyzer.new
158
- a.run_hooked do
144
+ a.run_hooked do
159
145
  b.run_hooked { @o.f1 }
160
146
  assert(b.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
161
147
  assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
162
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
163
- "./test/sample_03.rb", 4]] => 10},
164
- b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
148
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
165
149
 
166
150
  @o.f1
167
151
  assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
168
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
169
- "./test/sample_03.rb", 4]] => 10},
170
- b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
171
-
152
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 10}, b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
153
+
172
154
  assert(a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
173
155
  assert_equal(%w[f1 f2], a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
174
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
175
- "./test/sample_03.rb", 4]] => 20},
176
- a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
156
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/assets/sample_03.rb", 4]] => 20}, a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
177
157
  end
158
+
178
159
  b.run_hooked{ @o.f3 }
179
160
  assert_equal(%w[f1 f2 f3], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
180
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
181
- "./test/sample_03.rb", 4]] => 110,
182
- [[Rcov::Test::Temporary::Sample03, :f3,
183
- "./test/sample_03.rb", 11]]=>100 },
184
- b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
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"))
185
163
  end
186
164
 
187
165
  def test_expand_name
188
166
  assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo#foo") })
189
167
  assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo", "foo") })
190
- assert_equal(["#<Class:Foo>", "foo"],
191
- @a.instance_eval{ expand_name("Foo.foo") })
192
- assert_equal(["#<Class:Foo>", "foo"],
193
- @a.instance_eval{ expand_name("#<Class: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") })
194
170
  end
195
171
  end
@@ -1,9 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
1
2
 
2
- require 'test/unit'
3
- require 'rcov'
4
-
5
- class Test_CodeCoverageAnalyzer < Test::Unit::TestCase
6
- LINES = <<-EOF.to_a
3
+ class TestCodeCoverageAnalyzer < Test::Unit::TestCase
4
+ LINES = <<-EOF.split "\n"
7
5
  puts 1
8
6
  if foo
9
7
  bar
@@ -26,7 +24,7 @@ EOF
26
24
  def test_refine_coverage_info
27
25
  analyzer = Rcov::CodeCoverageAnalyzer.new
28
26
  cover = [1, 1, nil, nil, 0, 5, 5, 5, 0]
29
- line_info, marked_info,
27
+ line_info, marked_info,
30
28
  count_info = analyzer.instance_eval{ refine_coverage_info(LINES, cover) }
31
29
  assert_equal(LINES, line_info)
32
30
  assert_equal([true] * 2 + [false] * 3 + [true] * 3 + [false], marked_info)
@@ -39,17 +37,19 @@ EOF
39
37
  end
40
38
 
41
39
  def test_raw_coverage_info
42
- sample_file = File.join(File.dirname(__FILE__), "sample_01.rb")
40
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
43
41
  lines = File.readlines(sample_file)
44
42
  analyzer = Rcov::CodeCoverageAnalyzer.new
45
43
  analyzer.run_hooked{ load sample_file }
46
-
44
+
47
45
  assert_equal(lines, SCRIPT_LINES__[sample_file][0, lines.size])
48
46
  assert(analyzer.analyzed_files.include?(sample_file))
49
47
  line_info, cov_info, count_info = analyzer.data(sample_file)
50
48
  assert_equal(lines, line_info)
51
49
  assert_equal([true, true, false, false, true, false, true], cov_info)
52
- assert_equal([1, 2, 0, 0, 1, 0, 11], count_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
53
  analyzer.reset
54
54
  assert_equal(nil, analyzer.data(sample_file))
55
55
  assert_equal([], analyzer.analyzed_files)
@@ -60,10 +60,10 @@ EOF
60
60
  lines = ["puts a", "foo", "bar"] * 3
61
61
  coverage = [true] * 3 + [false] * 6
62
62
  counts = [1] * 3 + [0] * 6
63
- nlines, ncoverage, ncounts = analyzer.instance_eval do
63
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
64
64
  script_lines_workaround(lines, coverage, counts)
65
65
  end
66
-
66
+
67
67
  assert_equal(["puts a", "foo", "bar"], nlines)
68
68
  assert_equal([true, true, true], ncoverage)
69
69
  assert_equal([1, 1, 1], ncounts)
@@ -74,7 +74,7 @@ EOF
74
74
  lines = ["puts a", "foo", "bar"] * 2 + ["puts a", "foo", "baz"]
75
75
  coverage = [true] * 9
76
76
  counts = [1] * 9
77
- nlines, ncoverage, ncounts = analyzer.instance_eval do
77
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
78
78
  script_lines_workaround(lines, coverage, counts)
79
79
  end
80
80
  assert_equal(lines, nlines)
@@ -82,55 +82,85 @@ EOF
82
82
  assert_equal(counts, ncounts)
83
83
  end
84
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
+
85
97
  def test_differential_coverage_data
86
- sample_file = File.join(File.dirname(__FILE__), "sample_01.rb")
98
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_01.rb")
87
99
  lines = File.readlines(sample_file)
88
100
  analyzer = Rcov::CodeCoverageAnalyzer.new
89
101
  analyzer.run_hooked{ load sample_file }
90
102
  line_info, cov_info, count_info = analyzer.data(sample_file)
91
- assert_equal([1, 2, 0, 0, 1, 0, 11], count_info)
92
-
103
+ assert_equal([1, 2, 0, 0, 1, 0, 11], count_info) if RUBY_VERSION =~ /1.9/
104
+
93
105
  analyzer.reset
94
-
95
- sample_file = File.join(File.dirname(__FILE__), "sample_02.rb")
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")
96
109
  analyzer.run_hooked{ load sample_file }
97
110
  line_info, cov_info, count_info = analyzer.data(sample_file)
98
- assert_equal([8, 1, 0, 0, 0], count_info)
99
-
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
+
100
118
  analyzer.reset
101
119
  assert_equal([], analyzer.analyzed_files)
102
120
  analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
103
121
  line_info, cov_info, count_info = analyzer.data(sample_file)
104
- assert_equal([0, 1, 1, 1, 0], count_info)
105
- analyzer.run_hooked do
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
106
129
  10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
107
130
  end
108
131
  line_info, cov_info, count_info = analyzer.data(sample_file)
109
- assert_equal([0, 11, 11, 11, 0], count_info)
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"
110
134
  10.times{ analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) } }
111
135
  line_info, cov_info, count_info = analyzer.data(sample_file)
112
- assert_equal([0, 21, 21, 21, 0], count_info)
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"
113
138
 
114
139
  count_info2 = nil
115
140
  10.times do |i|
116
- analyzer.run_hooked do
141
+ analyzer.run_hooked do
117
142
  Rcov::Test::Temporary::Sample02.foo(1, 1)
118
143
  line_info, cov_info, count_info = analyzer.data(sample_file) if i == 3
119
144
  line_info2, cov_info2, count_info2 = analyzer.data(sample_file)
120
145
  end
121
146
  end
122
- assert_equal([0, 25, 25, 25, 0], count_info)
123
- assert_equal([0, 31, 31, 31, 0], count_info2)
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
124
154
  end
125
155
 
126
156
  def test_nested_analyzer_blocks
127
157
  a1 = Rcov::CodeCoverageAnalyzer.new
128
158
  a2 = Rcov::CodeCoverageAnalyzer.new
129
159
 
130
- sample_file = File.join(File.dirname(__FILE__), "sample_02.rb")
160
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
131
161
  load sample_file
132
-
133
- a1.run_hooked do
162
+
163
+ a1.run_hooked do
134
164
  100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
135
165
  a2.run_hooked do
136
166
  10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
@@ -153,16 +183,21 @@ EOF
153
183
 
154
184
  _, _, counts1 = a1.data(sample_file)
155
185
  _, _, counts2 = a2.data(sample_file)
156
- assert_equal([0, 221, 221, 221, 0], counts1)
157
- assert_equal([0, 121, 121, 121, 0], counts2)
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
158
193
  end
159
194
 
160
195
  def test_reset
161
196
  a1 = Rcov::CodeCoverageAnalyzer.new
162
197
 
163
- sample_file = File.join(File.dirname(__FILE__), "sample_02.rb")
198
+ sample_file = File.join(File.dirname(__FILE__), "assets/sample_02.rb")
164
199
  load sample_file
165
-
200
+
166
201
  a1.run_hooked do
167
202
  100.times do |i|
168
203
  Rcov::Test::Temporary::Sample02.foo(1, 1)
@@ -170,14 +205,15 @@ EOF
170
205
  end
171
206
  end
172
207
 
173
- assert_equal([0, 50, 50, 50, 0], a1.data(sample_file)[2])
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"
174
210
  end
175
211
 
176
212
  def test_compute_raw_difference
177
213
  first = {"a" => [1,1,1,1,1]}
178
214
  last = {"a" => [2,1,5,2,1], "b" => [1,2,3,4,5]}
179
215
  a = Rcov::CodeCoverageAnalyzer.new
180
- assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
216
+ assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
181
217
  a.instance_eval{ compute_raw_data_difference(first, last)} )
182
218
  end
183
219
  end