-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
84 lines (68 loc) · 2.2 KB
/
Rakefile
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
80
81
82
83
require 'rake'
require 'rake/clean'
require 'rake/testtask'
CLEAN.include ["activereocrd-*.gem", '**/*.rbc']
AR_PATH = Gem.loaded_specs['activerecord'].full_gem_path
def test_libs()
[ 'lib', 'test', "/#{File.join(AR_PATH, "test")}" ]
end
def test_files(with_unit, with_ar)
if ENV['TESTFILES'] then
return ENV['TESTFILES'].split(',').sort
end
files = []
if with_unit then
files += Dir.glob("test/*_test.rb").sort
end
if with_ar then
ar_cases = Dir.glob("#{AR_PATH}/test/cases/**/*_test.rb")
adapter_cases = Dir.glob("#{AR_PATH}/test/cases/adapters/**/*_test.rb")
files += (ar_cases - adapter_cases).sort
end
match_str = ENV['TESTMATCH']
if match_str
files.delete_if { |f| !f.match(match_str) }
end
files
end
def psql_db_helper(drop)
require File.join(AR_PATH, "test", "config")
require File.join(AR_PATH, "test", "support", "config")
config = ARTest.config['connections']['fdbsqltest']
prefix = drop ? "DROP SCHEMA IF EXISTS" : "CREATE SCHEMA"
suffix = drop ? "CASCADE" : ""
%x( psql -h #{config['arunit']['host']} -p #{config['arunit']['port']} -c "#{prefix} #{config['arunit']['database']} #{suffix}" )
%x( psql -h #{config['arunit2']['host']} -p #{config['arunit2']['port']} -c "#{prefix} #{config['arunit2']['database']} #{suffix}" )
end
### TESTS
namespace :test do
def test_task(name, files)
Rake::TestTask.new(name) do |t|
t.libs = test_libs()
t.test_files = files
t.verbose = t.option_list.include? '-v'
end
end
test_task('unit', test_files(true, false))
test_task('active_record', test_files(false, true))
test_task('all', test_files(true, true))
desc "Print all files that would be run with the given arguments"
task :print_files do
for f in test_files(false, true) do
puts f
end
end
desc "Echo the command for patching the ActiveRecord tests"
task :patch_cmd do
require 'active_record'
puts "git apply --directory=#{AR_PATH}/.. test/active_record_#{ActiveRecord::VERSION::MAJOR}_tests.diff"
end
end
task :build_databases do
psql_db_helper(false)
end
task :drop_databases do
psql_db_helper(true)
end
task :rebuild_databases => [:drop_databases, :build_databases]
task :default => 'test:unit'