start on FileReport class
This commit is contained in:
parent
894c426cbf
commit
0422f6f573
0
assets/file_report.html.erb
Normal file
0
assets/file_report.html.erb
Normal file
@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|||||||
spec.homepage = "https://github.com/holtrop/gcovinator"
|
spec.homepage = "https://github.com/holtrop/gcovinator"
|
||||||
spec.license = "MIT"
|
spec.license = "MIT"
|
||||||
|
|
||||||
spec.files = Dir["{exe,lib}/**/*", "*.gemspec"]
|
spec.files = Dir["{assets,exe,lib}/**/*", "*.gemspec"]
|
||||||
spec.bindir = "exe"
|
spec.bindir = "exe"
|
||||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ["lib"]
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
require_relative "gcovinator/file_coverage"
|
require_relative "gcovinator/file_coverage"
|
||||||
|
require_relative "gcovinator/file_report"
|
||||||
require_relative "gcovinator/gcov_parser"
|
require_relative "gcovinator/gcov_parser"
|
||||||
require_relative "gcovinator/version"
|
require_relative "gcovinator/version"
|
||||||
require "tmpdir"
|
require "fileutils"
|
||||||
require "open3"
|
require "open3"
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
require "tmpdir"
|
||||||
|
|
||||||
module Gcovinator
|
module Gcovinator
|
||||||
|
|
||||||
@ -33,6 +35,10 @@ module Gcovinator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
FileUtils.mkdir_p(output_dir)
|
||||||
|
file_reports = file_coverages.each_with_index.map do |(source_file_name, file_coverage), i|
|
||||||
|
FileReport.new(source_file_name, file_coverage, source_dirs, output_dir, sprintf("s%04d.html", i))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
47
lib/gcovinator/file_report.rb
Normal file
47
lib/gcovinator/file_report.rb
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
module Gcovinator
|
||||||
|
class FileReport
|
||||||
|
|
||||||
|
def initialize(source_file_name, file_coverage, source_dirs, output_dir, report_file_name)
|
||||||
|
@source_file_name = clean_source_file_name(source_file_name, source_dirs)
|
||||||
|
@report_file_name = report_file_name
|
||||||
|
@total_lines = 0
|
||||||
|
@covered_lines = 0
|
||||||
|
@total_branches = 0
|
||||||
|
@covered_branches = 0
|
||||||
|
run(source_file_name, File.join(output_dir, report_file_name))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def clean_source_file_name(source_file_name, source_dirs)
|
||||||
|
source_dirs.each do |source_dir|
|
||||||
|
prefix_test = "#{source_dir}/"
|
||||||
|
if source_file_name.start_with?(prefix_test)
|
||||||
|
return source_file_name[prefix_test.size, source_file_name.size]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
source_file_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(source_file_name, output_file_name)
|
||||||
|
require "erb"
|
||||||
|
source_file = read_source_file(source_file_name)
|
||||||
|
source_file_lines = source_file.lines.to_a
|
||||||
|
file_report_template = File.read(File.join(File.dirname(__FILE__), "../../assets/file_report.html.erb"))
|
||||||
|
erb = ERB.new(file_report_template, nil, "<>")
|
||||||
|
report = erb.run(binding.clone)
|
||||||
|
File.open(output_file_name, "w") do |fh|
|
||||||
|
fh.write(report)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_source_file(source_file_name)
|
||||||
|
begin
|
||||||
|
File.read(source_file_name)
|
||||||
|
rescue
|
||||||
|
%[<Could not open #{source_file_name}>]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user