Permalink
Browse files

re-organizing and cleaning up test suite to fit ruby conventions

  • Loading branch information...
1 parent 8134a2d commit 525b0730e2aa6ea87aec6d95cb967eb136186601 Aaron J. Bedra committed Jun 23, 2008
View
@@ -18,23 +18,23 @@ ENV["RCOVPATH"] = "bin/rcov"
# (really!)
desc "Create a cross-referenced code coverage report."
Rcov::RcovTask.new do |t|
- t.test_files = FileList['test/test*.rb']
+ t.test_files = FileList['test/*_test.rb']
t.ruby_opts << "-Ilib:ext/rcovrt" # in order to use this rcov
t.rcov_opts << "--xrefs" # comment to disable cross-references
t.verbose = true
end
desc "Analyze code coverage for the FileStatistics class."
Rcov::RcovTask.new(:rcov_sourcefile) do |t|
- t.test_files = FileList['test/test_file_statistics.rb']
+ t.test_files = FileList['test/file_statistics_test.rb']
t.verbose = true
t.rcov_opts << "--test-unit-only"
t.ruby_opts << "-Ilib:ext/rcovrt" # in order to use this rcov
t.output_dir = "coverage.sourcefile"
end
Rcov::RcovTask.new(:rcov_ccanalyzer) do |t|
- t.test_files = FileList['test/test_code_coverage_analyzer.rb']
+ t.test_files = FileList['test/code_coverage_analyzer_test.rb']
t.verbose = true
t.rcov_opts << "--test-unit-only"
t.ruby_opts << "-Ilib:ext/rcovrt" # in order to use this rcov
@@ -44,7 +44,7 @@ end
desc "Run the unit tests with rcovrt."
Rake::TestTask.new(:test_rcovrt => ["ext/rcovrt/rcovrt.so"]) do |t|
t.libs << "ext/rcovrt"
- t.test_files = FileList['test/test*.rb']
+ t.test_files = FileList['test/*_test.rb']
t.verbose = true
end
@@ -56,7 +56,7 @@ end
desc "Run the unit tests in pure-Ruby mode ."
Rake::TestTask.new(:test_pure_ruby) do |t|
t.libs << "ext/rcovrt"
- t.test_files = FileList['test/turn_off_rcovrt.rb', 'test/test*.rb']
+ t.test_files = FileList['test/turn_off_rcovrt.rb', 'test/*_test.rb']
t.verbose = true
end
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'rcov'
+require File.dirname(__FILE__) + '/test_helper'
class TestCallSiteAnalyzer < Test::Unit::TestCase
@@ -12,7 +11,7 @@ def setup
end
def verify_callsites_equal(expected, actual)
- callsites = expected.inject({}) do |s,(backtrace, count)|
+ callsites = expected.inject({}) do |s,(backtrace, count)|
unless $".any?{|x| %r{\brcovrt\b} =~ x}
backtrace = backtrace.map{|_, mid, file, line| [nil, mid, file, line] }
end
@@ -27,25 +26,25 @@ def verify_defsite_equal(expected, actual)
end
def test_callsite_compute_raw_difference
- src = [
+ src = [
{ ["Foo", "foo"] => {"bar" => 1},
- ["Foo", "bar"] => {"baz" => 10} },
- { ["Foo", "foo"] => ["foo.rb", 10] }
+ ["Foo", "bar"] => {"baz" => 10} },
+ { ["Foo", "foo"] => ["foo.rb", 10] }
]
- dst = [
+ dst = [
{ ["Foo", "foo"] => {"bar" => 1, "fubar" => 10},
["Foo", "baz"] => {"baz" => 10} },
{ ["Foo", "foo"] => ["fooredef.rb", 10],
["Foo", "baz"] => ["foo.rb", 20]}
]
- expected = [
+ expected = [
{ ["Foo", "foo"] => {"fubar" => 10},
["Foo", "baz"] => {"baz" => 10} },
{ ["Foo", "foo"] => ["fooredef.rb", 10],
- ["Foo", "baz"] => ["foo.rb", 20] }
+ ["Foo", "baz"] => ["foo.rb", 20] }
]
-
- assert_equal(expected,
+
+ assert_equal(expected,
@a.instance_eval{ compute_raw_data_difference(src, dst) } )
end
@@ -60,54 +59,54 @@ def test_return_values_when_no_match
def test_basic_defsite_recording
@a.run_hooked{ @o.f1 }
- verify_defsite_equal(["./test/sample_03.rb", 3],
+ verify_defsite_equal(["./test/sample_03.rb", 3],
@a.defsite("Rcov::Test::Temporary::Sample03", "f1"))
- verify_defsite_equal(["./test/sample_03.rb", 7],
+ verify_defsite_equal(["./test/sample_03.rb", 7],
@a.defsite("Rcov::Test::Temporary::Sample03", "f2"))
- verify_defsite_equal(["./test/sample_03.rb", 7],
+ verify_defsite_equal(["./test/sample_03.rb", 7],
@a.defsite("Rcov::Test::Temporary::Sample03#f2"))
end
def test_basic_callsite_recording
@a.run_hooked{ @o.f1 }
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03#f2"))
- #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
+ #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
# @a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
- #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
+ #verify_callsites_equal({["./test/sample_03.rb:4:in `f1'"] => 10},
# @a.callsites("Rcov::Test::Temporary::Sample03#f2"))
end
def test_basic_callsite_recording_API
@a.run_hooked{ @o.f1 }
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 10},
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
+ "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1, "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
callsites = @a.callsites("Rcov::Test::Temporary::Sample03", "f2")
callsite = callsites.keys[0]
assert_equal("./test/sample_03.rb", callsite.file)
assert_equal(4, callsite.line)
assert_equal(:f1, callsite.calling_method)
end
-
-
+
+
def test_basic_callsite_recording_with_singleton_classes
@a.run_hooked{ @o.class.g1 }
assert(@a.analyzed_classes.include?("#<Class:Rcov::Test::Temporary::Sample03>"))
assert_equal(%w[g1 g2], @a.analyzed_methods("#<Class:Rcov::Test::Temporary::Sample03>"))
- verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end,
- :g1, "./test/sample_03.rb", 15]] => 10},
+ verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end,
+ :g1, "./test/sample_03.rb", 15]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03.g2"))
verify_callsites_equal({[[class << Rcov::Test::Temporary::Sample03; self end,
- :g1, "./test/sample_03.rb", 15]] => 10},
+ :g1, "./test/sample_03.rb", 15]] => 10},
@a.callsites("#<Class:Rcov::Test::Temporary::Sample03>","g2"))
end
@@ -117,21 +116,21 @@ def test_differential_callsite_recording
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 10},
+ "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
@a.run_hooked{ @o.f1 }
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 20},
+ "./test/sample_03.rb", 4]] => 20},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
-
+
@a.run_hooked{ @o.f3 }
assert_equal(%w[f1 f2 f3], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
"./test/sample_03.rb", 4]] => 120,
- [[Rcov::Test::Temporary::Sample03, :f3,
+ [[Rcov::Test::Temporary::Sample03, :f3,
"./test/sample_03.rb", 11]]=>100 },
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
end
@@ -144,38 +143,38 @@ def test_reset
end
assert(@a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], @a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 10},
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
+ "./test/sample_03.rb", 4]] => 10},
@a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
end
def test_nested_callsite_recording
a = Rcov::CallSiteAnalyzer.new
b = Rcov::CallSiteAnalyzer.new
- a.run_hooked do
+ a.run_hooked do
b.run_hooked { @o.f1 }
assert(b.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 10},
+ "./test/sample_03.rb", 4]] => 10},
b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
@o.f1
assert_equal(%w[f1 f2], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 10},
+ "./test/sample_03.rb", 4]] => 10},
b.callsites("Rcov::Test::Temporary::Sample03", "f2"))
-
+
assert(a.analyzed_classes.include?("Rcov::Test::Temporary::Sample03"))
assert_equal(%w[f1 f2], a.analyzed_methods("Rcov::Test::Temporary::Sample03"))
verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
- "./test/sample_03.rb", 4]] => 20},
+ "./test/sample_03.rb", 4]] => 20},
a.callsites("Rcov::Test::Temporary::Sample03", "f2"))
end
b.run_hooked{ @o.f3 }
assert_equal(%w[f1 f2 f3], b.analyzed_methods("Rcov::Test::Temporary::Sample03"))
- verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
+ verify_callsites_equal({[[Rcov::Test::Temporary::Sample03, :f1,
"./test/sample_03.rb", 4]] => 110,
[[Rcov::Test::Temporary::Sample03, :f3,
"./test/sample_03.rb", 11]]=>100 },
@@ -185,9 +184,9 @@ def test_nested_callsite_recording
def test_expand_name
assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo#foo") })
assert_equal(["Foo", "foo"], @a.instance_eval{ expand_name("Foo", "foo") })
- assert_equal(["#<Class:Foo>", "foo"],
+ assert_equal(["#<Class:Foo>", "foo"],
@a.instance_eval{ expand_name("Foo.foo") })
- assert_equal(["#<Class:Foo>", "foo"],
+ assert_equal(["#<Class:Foo>", "foo"],
@a.instance_eval{ expand_name("#<Class:Foo>", "foo") })
end
end
@@ -1,5 +1,4 @@
-require 'test/unit'
-require 'rcov'
+require File.dirname(__FILE__) + '/test_helper'
class TestCodeCoverageAnalyzer < Test::Unit::TestCase
LINES = <<-EOF.to_a
@@ -25,7 +24,7 @@ def setup
def test_refine_coverage_info
analyzer = Rcov::CodeCoverageAnalyzer.new
cover = [1, 1, nil, nil, 0, 5, 5, 5, 0]
- line_info, marked_info,
+ line_info, marked_info,
count_info = analyzer.instance_eval{ refine_coverage_info(LINES, cover) }
assert_equal(LINES, line_info)
assert_equal([true] * 2 + [false] * 3 + [true] * 3 + [false], marked_info)
@@ -42,7 +41,7 @@ def test_raw_coverage_info
lines = File.readlines(sample_file)
analyzer = Rcov::CodeCoverageAnalyzer.new
analyzer.run_hooked{ load sample_file }
-
+
assert_equal(lines, SCRIPT_LINES__[sample_file][0, lines.size])
assert(analyzer.analyzed_files.include?(sample_file))
line_info, cov_info, count_info = analyzer.data(sample_file)
@@ -59,10 +58,10 @@ def test_script_lines_workaround_detects_correctly
lines = ["puts a", "foo", "bar"] * 3
coverage = [true] * 3 + [false] * 6
counts = [1] * 3 + [0] * 6
- nlines, ncoverage, ncounts = analyzer.instance_eval do
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
script_lines_workaround(lines, coverage, counts)
end
-
+
assert_equal(["puts a", "foo", "bar"], nlines)
assert_equal([true, true, true], ncoverage)
assert_equal([1, 1, 1], ncounts)
@@ -73,7 +72,7 @@ def test_script_lines_workaround_no_false_positives
lines = ["puts a", "foo", "bar"] * 2 + ["puts a", "foo", "baz"]
coverage = [true] * 9
counts = [1] * 9
- nlines, ncoverage, ncounts = analyzer.instance_eval do
+ nlines, ncoverage, ncounts = analyzer.instance_eval do
script_lines_workaround(lines, coverage, counts)
end
assert_equal(lines, nlines)
@@ -88,20 +87,20 @@ def test_differential_coverage_data
analyzer.run_hooked{ load sample_file }
line_info, cov_info, count_info = analyzer.data(sample_file)
assert_equal([1, 2, 0, 0, 1, 0, 11], count_info)
-
+
analyzer.reset
-
+
sample_file = File.join(File.dirname(__FILE__), "sample_02.rb")
analyzer.run_hooked{ load sample_file }
line_info, cov_info, count_info = analyzer.data(sample_file)
assert_equal([8, 1, 0, 0, 0], count_info)
-
+
analyzer.reset
assert_equal([], analyzer.analyzed_files)
analyzer.run_hooked{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
line_info, cov_info, count_info = analyzer.data(sample_file)
assert_equal([0, 1, 1, 1, 0], count_info)
- analyzer.run_hooked do
+ analyzer.run_hooked do
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
end
line_info, cov_info, count_info = analyzer.data(sample_file)
@@ -112,7 +111,7 @@ def test_differential_coverage_data
count_info2 = nil
10.times do |i|
- analyzer.run_hooked do
+ analyzer.run_hooked do
Rcov::Test::Temporary::Sample02.foo(1, 1)
line_info, cov_info, count_info = analyzer.data(sample_file) if i == 3
line_info2, cov_info2, count_info2 = analyzer.data(sample_file)
@@ -128,8 +127,8 @@ def test_nested_analyzer_blocks
sample_file = File.join(File.dirname(__FILE__), "sample_02.rb")
load sample_file
-
- a1.run_hooked do
+
+ a1.run_hooked do
100.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
a2.run_hooked do
10.times{ Rcov::Test::Temporary::Sample02.foo(1, 1) }
@@ -176,7 +175,7 @@ def test_compute_raw_difference
first = {"a" => [1,1,1,1,1]}
last = {"a" => [2,1,5,2,1], "b" => [1,2,3,4,5]}
a = Rcov::CodeCoverageAnalyzer.new
- assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
+ assert_equal({"a" => [1,0,4,1,0], "b" => [1,2,3,4,5]},
a.instance_eval{ compute_raw_data_difference(first, last)} )
end
end
Oops, something went wrong.

0 comments on commit 525b073

Please sign in to comment.