forked from GoogleCloudPlatform/ruby-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
85 lines (73 loc) · 1.72 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
84
85
require "rake/testtask"
task :test do
run_tests "test"
end
task :acceptance do
run_tests "acceptance"
end
def run_tests type
failed = false
full_start_time = Time.now
header "Installing dependencies"
each_lib do |_dir|
sh "bundle update"
end
each_lib do |dir|
start_time = Time.now
lib = dir.split("ruby-docs-samples/").last
begin
header "Running tests for #{lib}"
test_task dir, type
rescue
failed = true
end
end_time = Time.now
header_2 "Tests for #{lib} took #{(end_time - start_time).to_i} seconds"
test_task dir, type
end
full_end_time = Time.now
header_2 "Tests took a total of #{(full_end_time - full_start_time).to_i} seconds"
raise "Tests failed" if failed
header "Tests passed"
end
def each_lib
dirs.each do |dir|
Dir.chdir dir do
Bundler.with_clean_env do
yield dir
end
end
end
end
def each_gemfile
gemfiles = Dir.glob("**/Gemfile") - ["Gemfile"]
gemfiles.map! { |gemfile| File.dirname gemfile }.uniq!
gemfiles.each do |gemfile|
yield gemfile
end
end
def test_task dir, type
Rake::TestTask.new "#{dir}_#{type}" do |t|
t.test_files = FileList["#{dir}/#{type}/**/*_test.rb"]
t.options = "--junit --junit-filename=#{dir}/sponge_log.xml"
t.warning = false
end
Rake::Task["#{dir}_#{type}"].invoke
end
def dirs
entries = Dir.glob("#{__dir__}/**/*_test.rb").map do |entry|
File.expand_path "..", File.dirname(entry)
end
entries.uniq
end
def header str, token = "#"
line_length = str.length + 8
puts ""
puts token * line_length
puts "#{token * 3} #{str} #{token * 3}"
puts token * line_length
puts ""
end
def header_2 str, token = "#"
puts "\n#{token * 3} #{str} #{token * 3}\n"
end