From 560541ffdecf6240e2cd38d68b841e01bbd654d2 Mon Sep 17 00:00:00 2001 From: Alex Tambellini Date: Thu, 1 Aug 2013 23:35:27 -0400 Subject: [PATCH] Fix ActiveSupport::Testing::Isolation on jruby Hopefully the first of many related to #11700. With these changes the railties tests wont 100% pass but at least they will run and show the errors. The first problem was the @method_name variable was never set. This was causing ENV["ISOLATION_TEST"] to always be nil which would cause the test output to never be written to the tempfile. The second problem was that an invalid -t option was being passed to minitest and minitest was erroring out. The third problem was the run method needs to always return an instance of the test class it is trying to isolate. We were returning a ProxyTestResult instead. --- .../lib/active_support/testing/isolation.rb | 52 ++----------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index 9c52ae7768..d5d31cecbe 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -3,49 +3,6 @@ require 'minitest/parallel_each' module ActiveSupport module Testing - class RemoteError < StandardError - - attr_reader :message, :backtrace - - def initialize(exception) - @message = "caught #{exception.class.name}: #{exception.message}" - @backtrace = exception.backtrace - end - end - - class ProxyTestResult - def initialize(calls = []) - @calls = calls - end - - def add_error(e) - e = Test::Unit::Error.new(e.test_name, RemoteError.new(e.exception)) - @calls << [:add_error, e] - end - - def __replay__(result) - @calls.each do |name, args| - result.send(name, *args) - end - end - - def marshal_dump - @calls - end - - def marshal_load(calls) - initialize(calls) - end - - def method_missing(name, *args) - @calls << [name, args] - end - - def info_signal - Signal.list['INFO'] - end - end - module Isolation require 'thread' @@ -107,19 +64,18 @@ module ActiveSupport require "tempfile" if ENV["ISOLATION_TEST"] - proxy = ProxyTestResult.new - retval = yield proxy + yield File.open(ENV["ISOLATION_OUTPUT"], "w") do |file| - file.puts [Marshal.dump([retval, proxy])].pack("m") + file.puts [Marshal.dump(self.dup)].pack("m") end exit! else Tempfile.open("isolation") do |tmpfile| - ENV["ISOLATION_TEST"] = @method_name + ENV["ISOLATION_TEST"] = self.class.name ENV["ISOLATION_OUTPUT"] = tmpfile.path load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ") - `#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")} -t\"#{self.class}\"` + `#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")}` ENV.delete("ISOLATION_TEST") ENV.delete("ISOLATION_OUTPUT")