Sha256: f2555b5fbd1779c2f231aeb38e94d34ba17bb62a4e3e8908bc2df608990a59ed

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'

require_relative './coverage' if ENV['COVERAGE']

require 'httparty'
require 'polyphony'

require 'fileutils'
require_relative './eg'

require 'minitest/autorun'
require 'minitest/reporters'

::Exception.__disable_sanitized_backtrace__ = true

IS_LINUX = RUBY_PLATFORM =~ /linux/

# Minitest::Reporters.use! [
#   Minitest::Reporters::SpecReporter.new
# ]

module ::Kernel
  def trace(*args)
    STDOUT.orig_write(format_trace(args))
  end

  def format_trace(args)
    if args.first.is_a?(String)
      if args.size > 1
        format("%s: %p\n", args.shift, args)
      else
        format("%s\n", args.first)
      end
    else
      format("%p\n", args.size == 1 ? args.first : args)
    end
  end
end

class MiniTest::Test
  def setup
    # trace "* setup #{self.name}"
    Fiber.current.setup_main_fiber
    Thread.current.backend.finalize
    Thread.current.backend = Polyphony::Backend.new
    sleep 0.001
    @__stamp = Time.now
  end

  def teardown
    # trace "* teardown #{self.name} (#{Time.now - @__stamp}s)"
    Fiber.current.shutdown_all_children
    if Fiber.current.children.size > 0
      puts "Children left after #{self.name}: #{Fiber.current.children.inspect}"
      exit!
    end
  rescue => e
    puts e
    puts e.backtrace.join("\n")
    exit!
  end

  def fiber_tree(fiber)
    { fiber: fiber, children: fiber.children.map { |f| fiber_tree(f) } }
  end
end

module Kernel
  def capture_exception
    yield
  rescue Exception => e
    e
  end
end

module Minitest::Assertions
  def assert_in_range exp_range, act
    msg = message(msg) { "Expected #{mu_pp(act)} to be in range #{mu_pp(exp_range)}" }
    assert exp_range.include?(act), msg
  end
end

puts "Polyphony backend: #{Thread.current.backend.kind}"

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
polyphony-0.82 test/helper.rb
polyphony-0.81.1 test/helper.rb
polyphony-0.81 test/helper.rb
polyphony-0.80 test/helper.rb
polyphony-0.79 test/helper.rb
polyphony-0.78 test/helper.rb
polyphony-0.77 test/helper.rb