Sha256: a4e1a5260110fc83bb2d1b1b0d1932233f670be5f588251829c995ab69cff454

Contents?: true

Size: 1.57 KB

Versions: 17

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# This module is responsible for intercepting output made through various stdlib
# calls (i.e. puts, print, etc.) and printing summary information (e.g. a list
# of failing tests) at the end of the process.

require 'thread'

module Multiverse
  module OutputCollector
    include Color
    extend Color

    @output_lock = Mutex.new
    @buffer_lock = Mutex.new

    def self.failing_output
      @failing ||= []
    end

    def self.buffer(suite, env)
      key = [suite, env]
      @buffer_lock.synchronize do
        @buffers ||= {}
        @buffers[key] ||= ""
        @buffers[key]
      end
    end

    def self.failed(suite, env)
      @failing ||= []
      @failing << buffer(suite, env) + "\n"
    end

    def self.write(suite, env, msg)
      buffer(suite, env) << msg
    end

    def self.suite_report(suite, env)
      output(buffer(suite, env))
    end

    def self.overall_report
      output("", "")
      if failing_output.empty?
        output(green("There were no test failures"))
      else
        output(
          red("There were failures in #{failing_output.size} test suites"),
          "Here is their output",
          *failing_output)
      end
    end

    # Because the various environments potentially run in separate threads to
    # start their processes, make sure we don't blatantly interleave output.
    def self.output(*args)
      @output_lock.synchronize do
        puts *args
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
newrelic_rpm-3.7.3.204 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.3.199 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.2.195 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.2.192 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.2.190.beta test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.1.188 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.1.182 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.1.180 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.0.177 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.7.0.174.beta test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.9.171 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.8.168 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.8.164 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.7.159 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.7.159.beta test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.7.152 test/multiverse/lib/multiverse/output_collector.rb
newrelic_rpm-3.6.6.147 test/multiverse/lib/multiverse/output_collector.rb