Skip to content

Commit a3f1eb5

Browse files
committed
Active Record bin/test command runs only its own adapter tests
There are two ways to run unit tests. `bundle exec rake test` and `bin/test`. Active Record `bundle exec rake test` only executes its own adapter specific tests. on the other hand, `bin/test` executes all adapter specfic tests then some test files need to have `if current_adapter?`, which can be removed. - Removed `require_relative "../../tools/test"` to require its own one - `default_test_exclude_glob` excludes all of adapter specific tests. - `list_tests(argv)` adds its own adapter specific tests - `adapter_short` method extracted to get the short hand adapter name like `sqlite3`, `mysql2` and `postgresql` via `ENV["ARCONN"]`
1 parent 39b305c commit a3f1eb5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

activerecord/bin/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if adapter_index
88
end
99

1010
COMPONENT_ROOT = File.expand_path("..", __dir__)
11-
require_relative "../../tools/test"
11+
require_relative "../test/support/tools"
1212

1313
module Minitest
1414
def self.plugin_active_record_options(opts, options)

activerecord/test/support/tools.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
$: << File.expand_path("test", COMPONENT_ROOT)
4+
5+
require "bundler/setup"
6+
7+
require "rails/test_unit/runner"
8+
require "rails/test_unit/reporter"
9+
require "rails/test_unit/line_filtering"
10+
require "active_support"
11+
require "active_support/test_case"
12+
13+
require "rake/testtask"
14+
Rails::TestUnit::Runner.singleton_class.prepend Module.new {
15+
private
16+
def list_tests(argv)
17+
tests = super
18+
tests.concat FileList["test/cases/adapters/#{adapter_short}/**/*_test.rb"]
19+
end
20+
21+
def default_test_exclude_glob
22+
ENV["DEFAULT_TEST_EXCLUDE"] || "test/cases/adapters/*/*_test.rb"
23+
end
24+
25+
def adapter_short
26+
ENV["ARCONN"] || "sqlite3"
27+
end
28+
}
29+
30+
ActiveSupport::TestCase.extend Rails::LineFiltering
31+
Rails::TestUnitReporter.app_root = COMPONENT_ROOT
32+
Rails::TestUnitReporter.executable = "bin/test"
33+
34+
Rails::TestUnit::Runner.parse_options(ARGV)
35+
Rails::TestUnit::Runner.run(ARGV)

0 commit comments

Comments
 (0)