-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
108 lines (88 loc) · 2.33 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
require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks
#
# Gem specification
#
def gemspec
@gemspec ||= eval(File.read('configurable.gemspec'), TOPLEVEL_BINDING)
end
desc 'Prints the gemspec manifest.'
task :manifest do
# collect files from the gemspec, labeling
# with true or false corresponding to the
# file existing or not
files = gemspec.files.inject({}) do |files, file|
files[File.expand_path(file)] = [File.exists?(file), file]
files
end
# gather non-rdoc/pkg files for the project
# and add to the files list if they are not
# included already (marking by the absence
# of a label)
Dir.glob('**/*').each do |file|
next if file =~ /^(rdoc|pkg|test|coverage|benchmark|.*\.rbc)/ || File.directory?(file)
path = File.expand_path(file)
files[path] = ['', file] unless files.has_key?(path)
end
# sort and output the results
files.values.sort_by {|exists, file| file }.each do |entry|
puts '%-5s %s' % entry
end
end
#
# Documentation tasks
#
desc 'Generate documentation.'
task :rdoc do
spec = gemspec
files = spec.files.select {|file| File.extname(file) == '.rb' }
files += spec.extra_rdoc_files
options = spec.rdoc_options.join(' ')
Dir.chdir File.expand_path('..', __FILE__) do
FileUtils.rm_r('rdoc') if File.exists?('rdoc')
sh "rdoc -o rdoc #{options} '#{files.join("' '")}'"
end
end
#
# Dependency tasks
#
desc 'Bundle dependencies'
task :bundle do
output = `bundle check 2>&1`
unless $?.to_i == 0
puts output
sh "bundle install 2>&1"
puts
end
end
#
# Test tasks
#
def current_ruby
`ruby -v`.split[0,2].join('-')
end
desc 'Default: Run tests.'
task :default => :test
desc 'Run the tests'
task :test => :bundle do
puts "Using #{current_ruby}"
tests = Dir.glob('test/**/*_test.rb')
if ENV['RCOV'] == 'true'
FileUtils.rm_rf File.expand_path('../coverage', __FILE__)
sh('rcov', '-w', '--text-report', '--exclude', '^/', *tests)
else
sh('ruby', '-w', '-e', 'ARGV.dup.each {|test| load test}', *tests)
end
end
desc 'Run the benchmarks'
task :benchmark => :bundle do
puts "Using #{current_ruby}"
benchmarks = Dir.glob('benchmark/**/*_benchmark.rb')
sh('ruby', '-w', '-e', 'ARGV.dup.each {|benchmark| load benchmark}', *benchmarks)
end
desc 'Run rcov'
task :rcov do
ENV['RCOV'] = 'true'
Rake::Task['test'].invoke
end