Sha256: 0e81a2382cac694463ab020060b601f038adcec8f0aabc6dd55613d9c1d3379c

Contents?: true

Size: 834 Bytes

Versions: 2

Compression:

Stored size: 834 Bytes

Contents

require 'benchmark'

if ENV['BENCHMARK_TESTS'] || ENV['TEST_BENCHMARKS_FILE']
  class Test::Unit::TestSuite
    @@run_count = 0

    def run(result, &progress_block)
      @@run_count += 1
      begin
        yield(STARTED, name)
        @tests.each do |test|
          TestBenchmarker::TestBenchmark.new(self.name, test.name, Benchmark.measure { test.run(result, &progress_block) })
        end
        yield(FINISHED, name)
      ensure
        @@run_count -= 1
        # print the results as we're exiting the very last test run...
        if @@run_count == 0
          results = TestBenchmarker::TestBenchmarks.results
          if ENV['TEST_BENCHMARKS_FILE']
            File.open(ENV['TEST_BENCHMARKS_FILE'], 'a') { |f| f << results }
          else
            puts results
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
myronmarston-test_benchmarker-1.2.1 lib/test_benchmarker/test_suite.rb
test_benchmarker-1.2.1 lib/test_benchmarker/test_suite.rb