Sha256: f5d01ba075ad232890d13e67d969e8bbb2382e68923a0f1edb436c9f8d8f33b9

Contents?: true

Size: 1.8 KB

Versions: 24

Compression:

Stored size: 1.8 KB

Contents

require 'ceedling/plugin'
require 'ceedling/defaults'

class TeamcityTestsReport < Plugin

  def setup
    @suite_started = nil
    @output_enabled = !defined?(TEAMCITY_BUILD) || TEAMCITY_BUILD
  end

  def escape(string)
    string.gsub(/['|\[\]]/, '|\0').gsub('\r', '|r').gsub('\n', '|n')
  end

  def pre_test(test)
    teamcity_message "testSuiteStarted name='#{File.basename(test, '.c')}'"
    @suite_started = Time.now
  end

  def post_test(test)
    teamcity_message "testSuiteFinished name='#{File.basename(test, '.c')}'"
  end

  def post_test_fixture_execute(arg_hash)
    duration = (Time.now - @suite_started) * 1000
    results = @ceedling[:plugin_reportinator].assemble_test_results([arg_hash[:result_file]])
    avg_duration = (duration / [1, results[:counts][:passed] + results[:counts][:failed]].max).round

    results[:successes].each do |success|
      success[:collection].each do |test|
        teamcity_message "testStarted name='#{test[:test]}'"
        teamcity_message "testFinished name='#{test[:test]}' duration='#{avg_duration}'"
      end
    end

    results[:failures].each do |failure|
      failure[:collection].each do |test|
        teamcity_message "testStarted name='#{test[:test]}'"
        teamcity_message "testFailed name='#{test[:test]}' message='#{escape(test[:message])}' details='File: #{failure[:source][:path]}/#{failure[:source][:file]} Line: #{test[:line]}'"
        teamcity_message "testFinished name='#{test[:test]}' duration='#{avg_duration}'"
      end
    end

    results[:ignores].each do |failure|
      failure[:collection].each do |test|
        teamcity_message "testIgnored name='#{test[:test]}' message='#{escape(test[:message])}'"
      end
    end

    # We ignore stdout
  end

  def teamcity_message(content)
    puts "##teamcity[#{content}]" unless !@output_enabled
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ceedling-0.31.1 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.31.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.30.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.28.3 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.28.2 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.28.1 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.27.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.25.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.24.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.22.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.21.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.20.3 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.20.2 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.19.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.18.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.17.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.16.0 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.15.6 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.15.5 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb
ceedling-0.15.4 plugins/teamcity_tests_report/lib/teamcity_tests_report.rb