Permalink
Browse files

Generate code coverage files and HTML report after tests

  • Loading branch information...
sebreh committed Jan 14, 2014
1 parent 7ef35e5 commit 02d653746ed9d174b5b8d4c1e961c250a96beb93
Showing with 1,912 additions and 1 deletion.
  1. +4 −1 .gitignore
  2. +1 −0 Rakefile
  3. +60 −0 Scripts/coverage-report
  4. +1,847 −0 Scripts/gcovr
View
@@ -34,4 +34,7 @@ docset-installed.txt
.idea
# CocoaPods
-Pods
+Pods
+
+# Test coverage
+Coverage
View
@@ -6,6 +6,7 @@ SCRIPTS = './Scripts'
desc "Run the PodioKit unit test suite"
task :test do
sh "#{SCRIPTS}/run-tests"
+ sh "#{SCRIPTS}/coverage-report"
end
namespace :docs do
View
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+
+require 'etc'
+require 'fileutils'
+require 'getopt/long'
+
+DEFAULT_DERIVED_DATA = "#{Etc.getpwuid.dir}/Library/Developer/Xcode/DerivedData/"
+DEFAULT_OUTPUT = "Coverage"
+
+opts = Getopt::Long.getopts(
+ ['--derived-data', Getopt::OPTIONAL],
+ ['--out', Getopt::OPTIONAL]
+)
+
+derived_data = opts['derived-data'] || DEFAULT_DERIVED_DATA
+output = opts['out'] || DEFAULT_OUTPUT
+reports_dir = "#{output}/reports"
+html_dir = "#{output}/html"
+
+def copy_coverage_files(search_dir, reports_dir)
+ FileUtils.remove_dir(reports_dir, true) if Dir.exists?(reports_dir)
+ FileUtils.mkdir_p(reports_dir)
+
+ puts "=> Looking for coverage reports in #{search_dir}"
+
+ gcda_files = Dir["#{search_dir}/**/*.gcda"];
+ gcno_files = Dir["#{search_dir}/**/*.gcno"];
+ files = gcda_files.concat(gcno_files)
+
+ files.each do |path|
+ name = File.basename(path)
+
+ # Ignore test target classes
+ next if name.include?('Test')
+
+ new_path = File.join(reports_dir, name)
+ FileUtils.copy(path, new_path)
+ end
+
+ full_reports_dir = File.expand_path(reports_dir)
+ puts "=> Successfully copied #{files.size} coverage report files from last build to #{full_reports_dir}."
+end
+
+def generate_html_report(reports_dir, html_dir)
+ puts "=> Generating HMTL coverage report..."
+
+ FileUtils.remove_dir(html_dir, true) if Dir.exists?(html_dir)
+ FileUtils.mkdir_p html_dir
+
+ html_path = "#{html_dir}/index.html"
+
+ script_dir = File.expand_path(File.dirname(__FILE__))
+ system "#{script_dir}/gcovr -r . --object-directory=#{reports_dir} --html -o #{html_path}"
+
+ html_full_path = File.expand_path(html_path)
+ puts "=> HTML report successfully generated at #{html_full_path}."
+end
+
+copy_coverage_files(derived_data, reports_dir)
+generate_html_report(reports_dir, html_dir)
Oops, something went wrong.

0 comments on commit 02d6537

Please sign in to comment.