-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
79 lines (67 loc) · 1.83 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
require "bundler/gem_tasks"
require "rake/testtask"
namespace :db do
namespace :mysql do
task :env do
system "mysql -e 'drop database if exists pluck_map_test'"
system "mysql -e 'create database pluck_map_test'"
ENV["ACTIVE_RECORD_ADAPTER"] = "mysql2"
end
end
namespace :postgres do
task :env do
system "psql -c 'drop database if exists pluck_map_test'"
system "psql -c 'create database pluck_map_test'"
ENV["ACTIVE_RECORD_ADAPTER"] = "postgresql"
end
end
namespace :sqlite do
task :env do
ENV["ACTIVE_RECORD_ADAPTER"] = "sqlite3"
end
end
end
ADAPTERS = Rake.application.tasks.each_with_object([]) do |task, adapters|
match = task.name.match(/db:(.*):env/)
adapters.push(match[1]) if match
end.freeze
namespace :test do
ADAPTERS.each do |adapter|
Rake::TestTask.new(adapter => "db:#{adapter}:env") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
end
end
namespace :benchmark do
ADAPTERS.each do |adapter|
desc "Run benchmarks on #{adapter}"
task adapter => "db:#{adapter}:env" do
load File.expand_path("test/benchmarks.rb", __dir__)
end
end
end
def run_without_aborting(*tasks)
errors = []
tasks.each do |task|
puts task
Rake::Task[task].invoke
rescue Exception
puts "\e[31m#{$!.class}: #{$!.message}\e[0m"
errors << task
end
abort "Errors running #{errors.join(', ')}" if errors.any?
end
desc "Run #{ADAPTERS.join(', ')} tests"
task :test do
tasks = ADAPTERS.map { |adapter| "test:#{adapter}" }
run_without_aborting(*tasks)
end
desc "Run #{ADAPTERS.join(', ')} benchmarks"
task :benchmark do
tasks = ADAPTERS.map { |adapter| "benchmark:#{adapter}" }
run_without_aborting(*tasks)
end
desc "Run #{ADAPTERS.join(', ')} tests by default"
task default: :test