Class: Piggly::Reporter::Sonar
- Defined in:
- lib/piggly/reporter/sonar.rb
Overview
Generates SonarQube generic test coverage XML format.
Format specification: docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/test-coverage/generic-test-data/
Constant Summary
Constants included from HtmlDsl
HtmlDsl::HTML_PATTERN, HtmlDsl::HTML_REPLACE
Instance Method Summary collapse
-
#initialize(config, profile, output_path = nil) ⇒ Sonar
constructor
A new instance of Sonar.
-
#report(procedures) ⇒ Object
Generate Sonar coverage report for all procedures.
Methods inherited from Base
Methods included from HtmlDsl
Constructor Details
#initialize(config, profile, output_path = nil) ⇒ Sonar
Returns a new instance of Sonar.
12 13 14 15 16 17 |
# File 'lib/piggly/reporter/sonar.rb', line 12 def initialize(config, profile, output_path = nil) @config = config @profile = profile @output_path = output_path || File.join(@config.report_root, "sonar-coverage.xml") @line_coverage = Compiler::LineCoverage.new(config) end |
Instance Method Details
#report(procedures) ⇒ Object
Generate Sonar coverage report for all procedures
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/piggly/reporter/sonar.rb', line 21 def report(procedures) FileUtils.makedirs(File.dirname(@output_path)) File.open(@output_path, "w:UTF-8") do |io| io.puts '<?xml version="1.0" encoding="UTF-8"?>' io.puts '<coverage version="1">' procedures.each do |procedure| begin write_procedure_coverage(io, procedure) rescue => e # Skip procedures that can't be processed $stderr.puts "Warning: Could not generate Sonar coverage for #{procedure.name}: #{e.}" end end io.puts '</coverage>' end @output_path end |