forked from rubyworks/facets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
224 lines (182 loc) · 4.7 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env ruby
require 'fileutils'
#
# CORE TEST COVERAGE
# ----------------------------------------------------------------------------
desc "show core unit test coverage"
task 'coverage' do
core_scripts = []
cd 'lib/core/facets' do
core_scripts = Dir['**/*'].reject{ |s| File.directory?(s) }
end
core_tests = []
cd 'test/core' do
core_tests = Dir['**/*']
end
core_tests = core_tests.collect do |t|
dir, fname = *File.split(t)
File.join(dir, fname.sub(/^test_/,''))
end
diff = core_scripts - core_tests
# remove core collectives
diff = diff - %w{
array.rb binding.rb cattr.rb class.rb comparable.rb dir.rb
enumerable.rb exception.rb hash.rb file.rb filetest.rb float.rb
integer.rb kernel.rb matchdata.rb module.rb nilclass.rb
numeric.rb proc.rb range.rb regexp.rb string.rb symbol.rb
time.rb unboundmethod.rb
}
puts diff.sort.join("\n")
puts
puts "#{diff.size} files uncovered."
end
#
# GENERATE RDOCS
# ----------------------------------------------------------------------------
desc "generate rdocs"
task "rdoc" do
TEMPLATE = ENV['RDOC_TEMPLATE'] || 'html'
APIOUT = "doc/rdoc"
FileUtils.rm_r(APIOUT)
system "rdoc -a -S -t'Facets Core API' -T #{TEMPLATE} -m README --op '#{APIOUT}/core' README lib/facets/core"
system "rdoc -a -S -t'Facets More API' -T #{TEMPLATE} -m README --op '#{APIOUT}/more' README lib/facets/more"
end
#
# RUN TESTS
# ----------------------------------------------------------------------------
task 'default' do
prepare_tests_all
end
task 'test' do
prepare_tests_all
end
desc "run all unit tests"
task 'test:all' do
prepare_tests_all
end
desc "run core unit tests"
task 'test:core' do
prepare_tests_core
end
desc "run more unit tests"
task 'test:more' do
prepare_tests_more
end
desc "run all unit tests with ActiveSupport loaded"
task 'test:all:activesupport' => [:include_activesupport, 'test:all']
desc "run core unit tests with ActiveSupport loaded"
task 'test:core:activesupport' => [:include_activesupport, 'test:core']
desc "run more unit tests with ActiveSupport loaded"
task 'test:more:activesupport' => [:include_activesupport, 'test:more']
task 'include_activesupport' do
require 'activesupport'
end
def add_loadpath(*paths)
live = ENV['live']
unless live
# $LOAD_PATH.unshift(File.expand_path('lib/core'))
# $LOAD_PATH.unshift(File.expand_path('lib/more'))
paths.each do |path|
$LOAD_PATH.unshift(File.expand_path(path))
end
end
puts "RUBY VERSION: #{RUBY_VERSION}"
puts "LOAD PATH:\n" + $LOAD_PATH.join("\n") if $DEBUG
end
def get_tests(find=nil)
find = find && File.directory?(find) ? File.join(find, '**/test_*.rb') : find
find = find || ENV['TESTS'] || 'test/**/test_*.rb'
Dir.glob(find)
end
def run_tests(files)
files.each do |file|
next if File.directory?(file)
begin
puts "Loading: #{file}" if $DEBUG
load(file)
rescue LoadError
puts "Error loading: #{file}"
end
end
end
def prepare_tests_all
add_loadpath('lib/core','lib/more')
files = get_tests
run_tests(files)
end
def prepare_tests_core
add_loadpath('lib/core')
files = get_tests('test/core')
run_tests(files)
end
def prepare_tests_more
add_loadpath('lib/more')
files = get_tests('test/more')
run_tests(files)
end
#def run_tests
# live = ENV['live']
#
# unless live
# $LOAD_PATH.unshift(File.expand_path('lib/core'))
# $LOAD_PATH.unshift(File.expand_path('lib/more'))
# end
#
# puts "RUBY VERSION: #{RUBY_VERSION}"
# puts "LOAD PATH:\n" + $LOAD_PATH.join("\n")
#
# if find = ARGV[1..-1].select{|e| e !~ /(^[-]|[=])/ }[0]
# unless FileTest.file?(find)
# find = File.join(find, '**', 'test_*.rb')
# end
# else
# find = 'test/**/test_*.rb'
# end
#
# files = Dir.glob(find)
#
# files.each do |file|
# next if File.directory?(file)
# begin
# puts "Loading: #{file}" if $DEBUG
# load(file)
# rescue LoadError
# puts "Error loading: #{file}"
# end
# end
#end
#
# SETUP/INSTALL
# ----------------------------------------------------------------------------
def load_setup
begin
require 'setup'
$setup_installed = true
rescue LoadError
$setup_installed = false
puts "NOTP"
end
end
private :load_setup
desc "install to ruby site location"
task :install do
load_setup
if $setup_installed
sh "setup.rb all"
else
puts "Requires stand-alone Setup.rb."
puts "See http://setup.rubyforge.org"
puts "or 'gem install setup'."
end
end
desc "uninstall from ruby site location"
task :uninstall do
load_setup
if $setup_installed
sh "setup.rb uninstall"
else
puts "Requires stand-alone Setup.rb."
puts "See http://setup.rubyforge.org"
puts "or 'gem install setup'."
end
end