-
Notifications
You must be signed in to change notification settings - Fork 42
/
Rakefile
128 lines (103 loc) · 3.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# encoding: utf-8
# frozen_string_literal: true
#-- Bootstrap --------------------------------------------------------------#
desc 'Initializes your working copy to run the specs'
task :bootstrap do
if system('which bundle')
title 'Installing gems'
sh 'bundle install'
title 'Updating submodule'
sh 'git submodule update --init'
else
$stderr.puts "\033[0;31m" \
"[!] Please install the bundler gem manually:\n" \
' $ [sudo] gem install bundler' \
"\e[0m"
exit 1
end
end
begin
require 'bundler/gem_tasks'
default_tasks = [:spec, :no_warnings]
#-- Specs ------------------------------------------------------------------#
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
#-- Kick -------------------------------------------------------------------#
desc 'Automatically run specs for updated files'
task :kick do
exec 'bundle exec kicker -c'
end
#-- RuboCop ----------------------------------------------------------------#
if Bundler.rubygems.loaded_specs('rubocop')
require 'rubocop/rake_task'
RuboCop::RakeTask.new
default_tasks << :rubocop
end
#-- Ruby Warnings ----------------------------------------------------------#
task :no_warnings do
next if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
require 'open3'
files = FileList['lib/**/*.rb']
out, err = Bundler.with_original_env do
Open3.popen3(Gem.ruby, '-w', '-Ilib') do |stdin, stdout, stderr, _wait_thr|
files.each do |file|
stdin.puts "require '#{file.gsub(%r{(^lib/|\.rb$)}, '')}'"
end
stdin.close
[stdout, stderr].map do |io|
chunk_size = 16_384
select_timeout = 0.02
buffer = []
next '' if io.closed? || io.eof?
# IO.select cannot be used here due to the fact that it
# just does not work on windows
loop do
begin
IO.select([io], nil, nil, select_timeout)
break if io.eof? # stop raising :-(
buffer << io.readpartial(chunk_size)
rescue EOFError
break
end
end
buffer.join.strip
end
end
end
err = err.sub(
%r{.+rubygems/version\.rb:\d+: warning: deprecated Object#=~ is called on Integer; it always returns nil},
''
).gsub(
/^RUBY_GC_(HEAP_INIT_SLOTS|MALLOC_LIMIT)=\d+ \(default value: \d+\)$/,
''
).strip
raise "Molinillo should contain no ruby warnings:\n\nout:\n#{out}\n\nerr:\n#{err}\n" unless out.empty? && err.empty?
end
#-- Inch -------------------------------------------------------------------#
if Bundler.rubygems.loaded_specs('inch_by_inch')
require 'inch_by_inch/rake_task'
InchByInch::RakeTask.new do |task|
task.failing_grades << :U
end
default_tasks << :inch
end
#-- Default ----------------------------------------------------------------#
task :default => default_tasks
rescue LoadError => e
$stderr.puts "\033[0;31m" \
'[!] Some Rake tasks haven been disabled because the environment' \
' couldn’t be loaded. Be sure to run `rake bootstrap` first.' \
"\e[0m"
$stderr.puts e.message
$stderr.puts e.backtrace
$stderr.puts
end
#-- Helpers ------------------------------------------------------------------#
def title(title)
cyan_title = "\033[0;36m#{title}\033[0m"
puts
puts '-' * 80
puts cyan_title
puts '-' * 80
puts
end