more updates, more work on instrumenting, it reports back, whoa
This commit is contained in:
parent
e28703b047
commit
91027aee61
@ -33,7 +33,7 @@ module Flowerbox
|
||||
end
|
||||
|
||||
def instrument_js?
|
||||
!@instrument_files.empty?
|
||||
!instrument_files.empty?
|
||||
end
|
||||
|
||||
def test_with(what)
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user