Skip to content
This repository
Newer
Older
100644 158 lines (128 sloc) 4.095 kb
53c13f1a »
2010-04-26 Use Config::CONFIG['host_os'] instead of RUBY_PLATFORM [#4477 state:r…
1 require 'rbconfig'
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
2 module ActiveSupport
3 module Testing
934bb012 »
2009-11-23 Fixes remote errors in isolation tests
4 class RemoteError < StandardError
5
6 attr_reader :message, :backtrace
7
8 def initialize(exception)
9 @message = "caught #{exception.class.name}: #{exception.message}"
10 @backtrace = exception.backtrace
11 end
12 end
13
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
14 class ProxyTestResult
15 def initialize
16 @calls = []
575b95ea »
2009-06-30 Created AS::Testing::Isolation which runs each test case in a separat…
17 end
18
934bb012 »
2009-11-23 Fixes remote errors in isolation tests
19 def add_error(e)
20 e = Test::Unit::Error.new(e.test_name, RemoteError.new(e.exception))
21 @calls << [:add_error, e]
22 end
23
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
24 def __replay__(result)
25 @calls.each do |name, args|
26 result.send(name, *args)
27 end
1d280e21 »
2009-07-02 Adds support for def self.setup in isolation tests for setup that sho…
28 end
29
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
30 def method_missing(name, *args)
31 @calls << [name, args]
32 end
33 end
575b95ea »
2009-06-30 Created AS::Testing::Isolation which runs each test case in a separat…
34
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
35 module Isolation
36 def self.forking_env?
bb75c337 »
2010-08-23 Config is deprecated on 1.8.8 and 1.9.3 use RbConfig
37 !ENV["NO_FORK"] && ((RbConfig::CONFIG['host_os'] !~ /mswin|mingw/) && (RUBY_PLATFORM !~ /java/))
575b95ea »
2009-06-30 Created AS::Testing::Isolation which runs each test case in a separat…
38 end
39
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
40 def self.included(base)
41 if defined?(::MiniTest) && base < ::MiniTest::Unit::TestCase
42 base.send :include, MiniTest
43 elsif defined?(Test::Unit)
44 base.send :include, TestUnit
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
45 end
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
46 end
47
b549d93d »
2010-06-15 AS::Isolation functional on Windows/JRuby.
48 def _run_class_setup # class setup method should only happen in parent
49 unless defined?(@@ran_class_setup) || ENV['ISOLATION_TEST']
50 self.class.setup if self.class.respond_to?(:setup)
51 @@ran_class_setup = true
52 end
53 end
54
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
55 module TestUnit
56 def run(result)
b549d93d »
2010-06-15 AS::Isolation functional on Windows/JRuby.
57 _run_class_setup
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
58
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
59 yield(Test::Unit::TestCase::STARTED, name)
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
60
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
61 @_result = result
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
62
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
63 serialized = run_in_isolation do |proxy|
64 begin
65 super(proxy) { }
66 rescue Exception => e
67 proxy.add_error(Test::Unit::Error.new(name, e))
68 end
6b086449 »
2009-09-29 Fix the broken railties isolation tests
69 end
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
70
71 retval, proxy = Marshal.load(serialized)
72 proxy.__replay__(@_result)
73
74 yield(Test::Unit::TestCase::FINISHED, name)
75 retval
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
76 end
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
77 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
78
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
79 module MiniTest
80 def run(runner)
b549d93d »
2010-06-15 AS::Isolation functional on Windows/JRuby.
81 _run_class_setup
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
82
a5587efc »
2010-03-17 Remove some 1.9 warnings (resulting in some fixed bugs). Remaining AM…
83 serialized = run_in_isolation do |isolated_runner|
84 super(isolated_runner)
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
85 end
86
87 retval, proxy = Marshal.load(serialized)
88 proxy.__replay__(runner)
89 retval
90 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
91 end
92
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
93 module Forking
94 def run_in_isolation(&blk)
95 read, write = IO.pipe
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
96
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
97 pid = fork do
98 read.close
99 proxy = ProxyTestResult.new
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
100 retval = yield proxy
101 write.puts [Marshal.dump([retval, proxy])].pack("m")
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
102 exit!
103 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
104
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
105 write.close
106 result = read.read
107 Process.wait2(pid)
6b086449 »
2009-09-29 Fix the broken railties isolation tests
108 return result.unpack("m")[0]
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
109 end
110 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
111
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
112 module Subprocess
b549d93d »
2010-06-15 AS::Isolation functional on Windows/JRuby.
113 ORIG_ARGV = ARGV.dup unless defined?(ORIG_ARGV)
114
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
115 # Crazy H4X to get this working in windows / jruby with
116 # no forking.
117 def run_in_isolation(&blk)
118 require "tempfile"
119
120 if ENV["ISOLATION_TEST"]
121 proxy = ProxyTestResult.new
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
122 retval = yield proxy
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
123 File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
d39d7f5f »
2009-12-30 Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
124 file.puts [Marshal.dump([retval, proxy])].pack("m")
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
125 end
126 exit!
127 else
128 Tempfile.open("isolation") do |tmpfile|
129 ENV["ISOLATION_TEST"] = @method_name
130 ENV["ISOLATION_OUTPUT"] = tmpfile.path
131
132 load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
133 `#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")} -t\"#{self.class}\"`
134
135 ENV.delete("ISOLATION_TEST")
136 ENV.delete("ISOLATION_OUTPUT")
137
6b086449 »
2009-09-29 Fix the broken railties isolation tests
138 return tmpfile.read.unpack("m")[0]
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
139 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
140 end
141 end
142 end
143
61604fee »
2009-07-06 Get Initializer tests running without requiring parts of Rails being …
144 include forking_env? ? Forking : Subprocess
145 end
eea7b5db »
2009-06-30 Crazy hacks to get the Isolation testing module to work on non forkin…
146 end
147 end
148
149 # Only in subprocess for windows / jruby.
150 if ENV['ISOLATION_TEST']
151 require "test/unit/collector/objectspace"
152 class Test::Unit::Collector::ObjectSpace
153 def include?(test)
154 super && test.method_name == ENV['ISOLATION_TEST']
155 end
575b95ea »
2009-06-30 Created AS::Testing::Isolation which runs each test case in a separat…
156 end
c23d28e2 »
2009-10-07 To unmarshal MissingSourceFile from child
157 end
Something went wrong with that request. Please try again.