@@ -9,64 +9,81 @@ task :package
99desc "Run all unit tests"
1010task test : "test:isolated"
1111
12- namespace :test do
13- task :isolated do
14- dash_i = [
15- "test" ,
16- "lib" ,
17- "../activesupport/lib" ,
18- "../actionpack/lib" ,
19- "../actionview/lib" ,
20- "../activemodel/lib"
21- ] . map { |dir | File . expand_path ( dir , __dir__ ) }
22-
23- dash_i . reverse_each do |x |
24- $:. unshift ( x ) unless $:. include? ( x )
25- end
26- $-w = true
27-
28- require "bundler/setup" unless defined? ( Bundler )
29- require "active_support"
30-
31- failing_files = [ ]
32-
33- dirs = ( ENV [ "TEST_DIR" ] || ENV [ "TEST_DIRS" ] || "**" ) . split ( "," )
34- test_files = dirs . map { |dir | "test/#{ dir } /*_test.rb" }
35- Dir [ *test_files ] . each do |file |
36- next true if file . start_with? ( "test/fixtures/" )
37-
38- fake_command = Shellwords . join ( [
39- FileUtils ::RUBY ,
40- "-w" ,
41- *dash_i . map { |dir | "-I#{ Pathname . new ( dir ) . relative_path_from ( Pathname . pwd ) } " } ,
42- file ,
43- ] )
44- puts fake_command
45-
46- # We could run these in parallel, but pretty much all of the
47- # railties tests already run in parallel, so ¯\_(⊙︿⊙)_/¯
48- Process . waitpid fork {
49- ARGV . clear
50- Rake . application = nil
51-
52- load file
53- }
54-
55- unless $?. success?
56- failing_files << file
57- end
58- end
12+ run_isolated_tests = lambda do |files |
13+ dash_i = [
14+ "test" ,
15+ "lib" ,
16+ "../activesupport/lib" ,
17+ "../actionpack/lib" ,
18+ "../actionview/lib" ,
19+ "../activemodel/lib"
20+ ] . map { |dir | File . expand_path ( dir , __dir__ ) }
21+
22+ dash_i . reverse_each do |x |
23+ $:. unshift ( x ) unless $:. include? ( x )
24+ end
25+ $-w = true
26+
27+ require "bundler/setup" unless defined? ( Bundler )
28+ require "active_support"
5929
60- unless failing_files . empty?
61- puts
62- puts "Failed in:"
63- failing_files . each do |file |
64- puts " #{ file } "
65- end
66- puts
30+ failing_files = files . reject do |file |
31+ next true if file . start_with? ( "test/fixtures/" )
6732
68- raise "Failure in isolated test runner"
33+ fake_command = Shellwords . join ( [
34+ FileUtils ::RUBY ,
35+ "-w" ,
36+ *dash_i . map { |dir | "-I#{ Pathname . new ( dir ) . relative_path_from ( Pathname . pwd ) } " } ,
37+ file ,
38+ ] )
39+ puts fake_command
40+
41+ # We could run these in parallel, but pretty much all of the
42+ # railties tests already run in parallel, so ¯\_(⊙︿⊙)_/¯
43+ Process . waitpid fork {
44+ ARGV . clear
45+ Rake . application = nil
46+
47+ load file
48+ }
49+
50+ $?. success?
51+ end
52+
53+ unless failing_files . empty?
54+ puts
55+ puts "Failed in:"
56+ failing_files . each do |file |
57+ puts " #{ file } "
6958 end
59+ puts
60+
61+ raise "Failure in isolated test runner"
62+ end
63+ end
64+
65+ _test_files = nil
66+ test_files = lambda do
67+ _test_files ||= Dir [ *
68+ ( ENV [ "TEST_DIR" ] || ENV [ "TEST_DIRS" ] || "**" ) .
69+ split ( "," ) .
70+ map { |dir | "test/#{ dir } /*_test.rb" }
71+ ]
72+ end
73+
74+ split_filter = lambda { |file | file =~ /test\/ application\/ / }
75+
76+ namespace :test do
77+ task "1" do
78+ run_isolated_tests . call test_files . call . select ( &split_filter )
79+ end
80+
81+ task "2" do
82+ run_isolated_tests . call test_files . call . reject ( &split_filter )
83+ end
84+
85+ task :isolated do
86+ run_isolated_tests . call test_files . call
7087 end
7188end
7289
0 commit comments