aboutsummaryrefslogtreecommitdiffstats
path: root/railties/Rakefile
blob: 8251b2bb32233060de7cbecbbb4d51874fc6878c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true

require "rake/testtask"

task default: :test

task :package

desc "Run all unit tests"
task test: "test:isolated"

namespace :test do
  task :isolated do
    dash_i = [
      "test",
      "lib",
      "../activesupport/lib",
      "../actionpack/lib",
      "../actionview/lib",
      "../activemodel/lib"
    ].map { |dir| File.expand_path(dir, __dir__) }

    dash_i.reverse_each do |x|
      $:.unshift(x) unless $:.include?(x)
    end
    $-w = true

    require "bundler/setup" unless defined?(Bundler)
    require "active_support"

    failing_files = []

    dirs = (ENV["TEST_DIR"] || ENV["TEST_DIRS"] || "**").split(",")
    test_files = dirs.map { |dir| "test/#{dir}/*_test.rb" }
    Dir[*test_files].each do |file|
      next true if file.start_with?("test/fixtures/")

      fake_command = Shellwords.join([
        FileUtils::RUBY,
        "-w",
        *dash_i.map { |dir| "-I#{Pathname.new(dir).relative_path_from(Pathname.pwd)}" },
        file,
      ])
      puts fake_command

      # We could run these in parallel, but pretty much all of the
      # railties tests already run in parallel, so ¯\_(⊙︿⊙)_/¯
      Process.waitpid fork {
        ARGV.clear
        Rake.application = nil

        load file
      }

      unless $?.success?
        failing_files << file
      end
    end

    unless failing_files.empty?
      puts
      puts "Failed in:"
      failing_files.each do |file|
        puts "  #{file}"
      end
      puts

      raise "Failure in isolated test runner"
    end
  end
end

Rake::TestTask.new("test:regular") do |t|
  t.libs << "test" << "#{__dir__}/../activesupport/lib"
  t.pattern = "test/**/*_test.rb"
  t.warning = true
  t.verbose = true
  t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
end