From 91027aee613b3abd6b2c52f6dbbd51c879f6fdcd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 26 Mar 2012 17:40:20 -0400 Subject: [PATCH] more updates, more work on instrumenting, it reports back, whoa --- lib/flowerbox/configuration.rb | 2 +- lib/flowerbox/runner/base.rb | 11 ++++++++++- lib/flowerbox/sprockets_handler.rb | 1 - lib/flowerbox/tilt/instrument_js.rb | 14 +++++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/flowerbox/configuration.rb b/lib/flowerbox/configuration.rb index ea97dff..52c7410 100644 --- a/lib/flowerbox/configuration.rb +++ b/lib/flowerbox/configuration.rb @@ -33,7 +33,7 @@ module Flowerbox end def instrument_js? - !@instrument_files.empty? + !instrument_files.empty? end def test_with(what) diff --git a/lib/flowerbox/runner/base.rb b/lib/flowerbox/runner/base.rb index 0a22420..e9cb42a 100644 --- a/lib/flowerbox/runner/base.rb +++ b/lib/flowerbox/runner/base.rb @@ -37,6 +37,15 @@ module Flowerbox end def instrument(data) + results = [] + + data.flatten.first.each do |filename, lines| + results += lines.reject { |line| line == nil } + end + + visited = results.find_all { |result| result == 1 }.length + + Flowerbox.notify "Coverage: %d/%d lines (%0.2f%% of instrumented code)" % [ visited, results.length, (visited.to_f / results.length.to_f) * 100 ] end def ensure_alive @@ -97,7 +106,7 @@ module Flowerbox @results rescue => e case e - when ExecJS::RuntimeError, ExecJS::ProgramError + when ExecJS::RuntimeError, ExecJS::ProgramError, Sprockets::FileNotFound handle_coffeescript_compilation_error(e) else raise e diff --git a/lib/flowerbox/sprockets_handler.rb b/lib/flowerbox/sprockets_handler.rb index f4e25c5..3b5ab4e 100644 --- a/lib/flowerbox/sprockets_handler.rb +++ b/lib/flowerbox/sprockets_handler.rb @@ -38,7 +38,6 @@ module Flowerbox return @environment if @environment @environment = Sprockets::Environment.new - @environment.cache = cache if Flowerbox.instrument_js? require 'flowerbox/tilt/instrument_js' diff --git a/lib/flowerbox/tilt/instrument_js.rb b/lib/flowerbox/tilt/instrument_js.rb index 0199c5b..4cdc4ad 100644 --- a/lib/flowerbox/tilt/instrument_js.rb +++ b/lib/flowerbox/tilt/instrument_js.rb @@ -14,11 +14,14 @@ module Flowerbox output = [ 'if (typeof __$instrument == "undefined") { __$instrument = {} }', "__$instrument['#{file}'] = [];", - "__$instrument['#{file}'][#{lines.length - 1}] = 0;" + "__$instrument['#{file}'][#{lines.length - 1}] = null;" ] prior_comma_end = comma_end = false + lines_instrumented = [] + + code_output = [] lines.each_with_index do |line, index| line.rstrip! @@ -26,12 +29,17 @@ module Flowerbox if line[%r{; *$}] line = line + instrument + lines_instrumented << index end - output << line + code_output << line end - output.join("\n") + lines_instrumented.each do |line| + output << "__$instrument['#{file}'][#{line}] = 0;" + end + + (output + code_output).join("\n") else data end