Diff
Modified: trunk/rcov4jr/Rakefile.rb (936 => 937)
--- trunk/rcov4jr/Rakefile.rb 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/Rakefile.rb 2008-03-09 04:36:09 UTC (rev 937)
@@ -7,6 +7,7 @@
require 'rake/gempackagetask'
require 'rake/testtask'
require 'rake/rdoctask'
+require 'spec/rake/spectask'
GEM_NAME='rcov4jr'
GEM_VERSION='0.0.1'
@@ -82,7 +83,14 @@
t.verbose = true
end
+desc "Run specs for rcov4jr"
+Spec::Rake::SpecTask.new( "specs" ) do | t |
+ t.libs << "lib"
+ t.spec_files = FileList[ "specs/**/*.rb" ]
+end
+
desc "Create the Java extension."
-task :compile => ['lib/rcovrt.jar']
-task :gem => [:compile]
-task :install_gem => [:gem]
+task :compile => [ 'lib/rcovrt.jar' ]
+task :gem => [ :compile ]
+task :install_gem => [ :gem ]
+task :default => [ :test_rcov4jr ]
Modified: trunk/rcov4jr/java/src/CallsiteHook.java (936 => 937)
--- trunk/rcov4jr/java/src/CallsiteHook.java 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/java/src/CallsiteHook.java 2008-03-09 04:36:09 UTC (rev 937)
@@ -15,7 +15,7 @@
public static CallsiteHook getCallsiteHook() {
if (callsiteHook == null) {
callsiteHook = new CallsiteHook();
- }
+ }
return callsiteHook;
}
@@ -94,6 +94,11 @@
}
private RubyArray formatBacktrace(Ruby runtime, String backtrace) {
+ if ( backtrace == null ) {
+ System.out.println( "backtrace is null" );
+ return runtime.newArray();
+ }
+
Matcher matcher = backtracePattern.matcher(backtrace);
RubyArray ary = runtime.newArray();
@@ -101,7 +106,9 @@
String method = matcher.group(4);
String file = matcher.group(1);
String line = matcher.group(2);
- Long lineNum = (line == null ? Long.valueOf(0) : Long.valueOf(line));
+ Long lineNum = ( line == null ?
+ Long.valueOf( 0 ) :
+ Long.valueOf( line ) );
ary.add((method == null ? runtime.getNil() : runtime
.newSymbol(method)));
Modified: trunk/rcov4jr/java/src/CoverageHook.java (936 => 937)
--- trunk/rcov4jr/java/src/CoverageHook.java 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/java/src/CoverageHook.java 2008-03-09 04:36:09 UTC (rev 937)
@@ -41,7 +41,7 @@
}
// make sure the file's source lines are in SCRIPT_LINES__
- RubyHash cover = getCover(context.getRuntime());
+ cover = getCover(context.getRuntime());
RubyArray lines = (RubyArray) scriptLines.get(file);
if (lines == null || cover == null){
return;
@@ -69,9 +69,6 @@
}
public boolean isInterestedInEvent(int event) {
-// return (event != RUBY_EVENT_C_CALL &&
-// event != RUBY_EVENT_C_RETURN &&
-// event != RUBY_EVENT_CLASS);
return event == RUBY_EVENT_CALL || event == RUBY_EVENT_LINE;
}
Added: trunk/rcov4jr/specs/code_coverage_analyzer_spec.rb (0 => 937)
--- trunk/rcov4jr/specs/code_coverage_analyzer_spec.rb (rev 0)
+++ trunk/rcov4jr/specs/code_coverage_analyzer_spec.rb 2008-03-09 04:36:09 UTC (rev 937)
@@ -0,0 +1,31 @@
+
+require 'rubygems'
+require 'rcov'
+
+describe Rcov::CodeCoverageAnalyzer do
+ def hook_level
+ Rcov::CodeCoverageAnalyzer.send( :hook_level )
+ end
+
+ before( :each ) do
+ @code_coverage_analyzer = Rcov::CodeCoverageAnalyzer.new
+ end
+
+ after( :each ) do
+ 1.upto hook_level do
+ @code_coverage_analyzer.remove_hook
+ end
+ end
+
+ it "should increase hook_level when a new hook is installed" do
+ @code_coverage_analyzer.install_hook
+ Rcov::CodeCoverageAnalyzer.send( :hook_level ).should == 1
+ end
+
+ it "should not throw an exception if remove_hook is called before install_hook" do
+ @code_coverage_analyzer.remove_hook
+ Rcov::CodeCoverageAnalyzer.send( :hook_level ).should == -1
+ @code_coverage_analyzer.reset
+ end
+end
+
Modified: trunk/rcov4jr/test/actual_coverage/diff-gcc-original.out (936 => 937)
--- trunk/rcov4jr/test/actual_coverage/diff-gcc-original.out 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/test/actual_coverage/diff-gcc-original.out 2008-03-09 04:36:09 UTC (rev 937)
@@ -0,0 +1,5 @@
+================================================================================
+sample_05.rb
+================================================================================
+sample_05.rb:10: 3*x
+sample_05.rb:11:end
Modified: trunk/rcov4jr/test/actual_coverage/gcc-text.out (936 => 937)
--- trunk/rcov4jr/test/actual_coverage/gcc-text.out 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/test/actual_coverage/gcc-text.out 2008-03-09 04:36:09 UTC (rev 937)
@@ -0,0 +1,10 @@
+================================================================================
+sample_03.rb
+================================================================================
+sample_03.rb:15: 10.times{ g2 }
+sample_03.rb:16: end
+sample_03.rb:19: # safe from here ...
+sample_03.rb:20:end end end end
+================================================================================
+sample_04.rb
+================================================================================
Modified: trunk/rcov4jr/test/sample_05.rb (936 => 937)
--- trunk/rcov4jr/test/sample_05.rb 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/test/sample_05.rb 2008-03-09 04:36:09 UTC (rev 937)
@@ -1,3 +1,7 @@
+def d(x)
+ 4*x
+end
+
def a
b 10
end
Modified: trunk/rcov4jr/test/test_CodeCoverageAnalyzer.rb (936 => 937)
--- trunk/rcov4jr/test/test_CodeCoverageAnalyzer.rb 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/test/test_CodeCoverageAnalyzer.rb 2008-03-09 04:36:09 UTC (rev 937)
@@ -45,7 +45,9 @@
analyzer.run_hooked{ load sample_file }
assert_equal(lines, SCRIPT_LINES__[sample_file][0, lines.size])
- assert(analyzer.analyzed_files.include?(sample_file))
+ analyzer.analyzed_files.each { | f | puts f } # lets see what files have been analyzed
+ assert(analyzer.analyzed_files.size > 0, "analyzer has no analyzed files")
+ assert(analyzer.analyzed_files.include?(sample_file), "#{sample_file} was not analyzed")
line_info, cov_info, count_info = analyzer.data(sample_file)
assert_equal(lines, line_info)
assert_equal([true, true, false, false, true, false, true], cov_info)
@@ -169,7 +171,7 @@
a1.reset if i == 49
end
end
-
+
assert_equal([0, 50, 50, 50, 0], a1.data(sample_file)[2])
end
Modified: trunk/rcov4jr/test/test_functional.rb (936 => 937)
--- trunk/rcov4jr/test/test_functional.rb 2008-03-08 05:34:20 UTC (rev 936)
+++ trunk/rcov4jr/test/test_functional.rb 2008-03-09 04:36:09 UTC (rev 937)
@@ -30,7 +30,7 @@
str.sub(/Generated on.+$/, '').sub(/Generated using the.+$/, '')
end
- def cmp(file)
+ def cmp(file)
content = lambda{|dir| strip_variable_sections(File.read(@@dir+dir+file))}
assert_equal(content["expected_coverage"], content["actual_coverage"])
end
@@ -48,6 +48,8 @@
# end
# end
+ # This is a bit of a hack to get the coverage tests to run. It does require that
+ # you have an rcov install to run, which can be tricky.
def run_rcov( opts, script="sample_04.rb", opts_tail="" )
ruby_opts = "-I../lib -S"
with_testdir do