rake 0.9.2.2 → 13.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.rdoc +2403 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +64 -106
- data/doc/command_line_usage.rdoc +65 -21
- data/doc/glossary.rdoc +40 -49
- data/doc/jamis.rb +1 -0
- data/doc/rake.1 +156 -0
- data/doc/rakefile.rdoc +127 -62
- data/{bin → exe}/rake +1 -7
- data/lib/rake/application.rb +507 -271
- data/lib/rake/backtrace.rb +24 -0
- data/lib/rake/clean.rb +54 -8
- data/lib/rake/cloneable.rb +11 -19
- data/lib/rake/cpu_counter.rb +107 -0
- data/lib/rake/default_loader.rb +5 -0
- data/lib/rake/dsl_definition.rb +67 -48
- data/lib/rake/early_time.rb +5 -1
- data/lib/rake/ext/core.rb +5 -6
- data/lib/rake/ext/string.rb +61 -52
- data/lib/rake/file_creation_task.rb +4 -3
- data/lib/rake/file_list.rb +81 -49
- data/lib/rake/file_task.rb +15 -8
- data/lib/rake/file_utils.rb +63 -43
- data/lib/rake/file_utils_ext.rb +14 -25
- data/lib/rake/invocation_chain.rb +25 -19
- data/lib/rake/invocation_exception_mixin.rb +1 -0
- data/lib/rake/late_time.rb +18 -0
- data/lib/rake/linked_list.rb +112 -0
- data/lib/rake/loaders/makefile.rb +23 -9
- data/lib/rake/multi_task.rb +4 -6
- data/lib/rake/name_space.rb +36 -23
- data/lib/rake/packagetask.rb +71 -34
- data/lib/rake/phony.rb +16 -0
- data/lib/rake/private_reader.rb +21 -0
- data/lib/rake/promise.rb +100 -0
- data/lib/rake/pseudo_status.rb +8 -2
- data/lib/rake/rake_module.rb +41 -3
- data/lib/rake/rake_test_loader.rb +9 -4
- data/lib/rake/rule_recursion_overflow_error.rb +2 -2
- data/lib/rake/scope.rb +43 -0
- data/lib/rake/task.rb +186 -79
- data/lib/rake/task_argument_error.rb +1 -0
- data/lib/rake/task_arguments.rb +46 -15
- data/lib/rake/task_manager.rb +91 -67
- data/lib/rake/tasklib.rb +2 -12
- data/lib/rake/testtask.rb +61 -63
- data/lib/rake/thread_history_display.rb +49 -0
- data/lib/rake/thread_pool.rb +163 -0
- data/lib/rake/trace_output.rb +23 -0
- data/lib/rake/version.rb +5 -3
- data/lib/rake/win32.rb +14 -18
- data/lib/rake.rb +35 -33
- data/rake.gemspec +100 -0
- metadata +74 -176
- data/.gemtest +0 -0
- data/CHANGES +0 -522
- data/Rakefile +0 -369
- data/TODO +0 -20
- data/doc/rake.1.gz +0 -0
- data/doc/release_notes/rake-0.4.14.rdoc +0 -23
- data/doc/release_notes/rake-0.4.15.rdoc +0 -35
- data/doc/release_notes/rake-0.5.0.rdoc +0 -53
- data/doc/release_notes/rake-0.5.3.rdoc +0 -78
- data/doc/release_notes/rake-0.5.4.rdoc +0 -46
- data/doc/release_notes/rake-0.6.0.rdoc +0 -141
- data/doc/release_notes/rake-0.7.0.rdoc +0 -119
- data/doc/release_notes/rake-0.7.1.rdoc +0 -59
- data/doc/release_notes/rake-0.7.2.rdoc +0 -121
- data/doc/release_notes/rake-0.7.3.rdoc +0 -47
- data/doc/release_notes/rake-0.8.0.rdoc +0 -114
- data/doc/release_notes/rake-0.8.2.rdoc +0 -165
- data/doc/release_notes/rake-0.8.3.rdoc +0 -112
- data/doc/release_notes/rake-0.8.4.rdoc +0 -147
- data/doc/release_notes/rake-0.8.5.rdoc +0 -53
- data/doc/release_notes/rake-0.8.6.rdoc +0 -55
- data/doc/release_notes/rake-0.8.7.rdoc +0 -55
- data/doc/release_notes/rake-0.9.0.rdoc +0 -112
- data/doc/release_notes/rake-0.9.1.rdoc +0 -52
- data/doc/release_notes/rake-0.9.2.rdoc +0 -49
- data/install.rb +0 -90
- data/lib/rake/alt_system.rb +0 -109
- data/lib/rake/classic_namespace.rb +0 -11
- data/lib/rake/contrib/compositepublisher.rb +0 -21
- data/lib/rake/contrib/ftptools.rb +0 -150
- data/lib/rake/contrib/publisher.rb +0 -73
- data/lib/rake/contrib/rubyforgepublisher.rb +0 -16
- data/lib/rake/contrib/sshpublisher.rb +0 -50
- data/lib/rake/contrib/sys.rb +0 -191
- data/lib/rake/ext/module.rb +0 -39
- data/lib/rake/ext/time.rb +0 -14
- data/lib/rake/gempackagetask.rb +0 -15
- data/lib/rake/pathmap.rb +0 -1
- data/lib/rake/rdoctask.rb +0 -234
- data/lib/rake/ruby182_test_unit_fix.rb +0 -25
- data/lib/rake/runtest.rb +0 -21
- data/test/file_creation.rb +0 -34
- data/test/helper.rb +0 -492
- data/test/test_rake.rb +0 -40
- data/test/test_rake_application.rb +0 -489
- data/test/test_rake_application_options.rb +0 -335
- data/test/test_rake_clean.rb +0 -14
- data/test/test_rake_definitions.rb +0 -80
- data/test/test_rake_directory_task.rb +0 -46
- data/test/test_rake_dsl.rb +0 -77
- data/test/test_rake_early_time.rb +0 -31
- data/test/test_rake_extension.rb +0 -59
- data/test/test_rake_file_creation_task.rb +0 -56
- data/test/test_rake_file_list.rb +0 -628
- data/test/test_rake_file_list_path_map.rb +0 -8
- data/test/test_rake_file_task.rb +0 -102
- data/test/test_rake_file_utils.rb +0 -305
- data/test/test_rake_ftp_file.rb +0 -59
- data/test/test_rake_functional.rb +0 -450
- data/test/test_rake_invocation_chain.rb +0 -52
- data/test/test_rake_makefile_loader.rb +0 -44
- data/test/test_rake_multi_task.rb +0 -51
- data/test/test_rake_name_space.rb +0 -43
- data/test/test_rake_package_task.rb +0 -79
- data/test/test_rake_path_map.rb +0 -157
- data/test/test_rake_path_map_explode.rb +0 -34
- data/test/test_rake_path_map_partial.rb +0 -18
- data/test/test_rake_pseudo_status.rb +0 -21
- data/test/test_rake_rake_test_loader.rb +0 -21
- data/test/test_rake_rdoc_task.rb +0 -83
- data/test/test_rake_require.rb +0 -40
- data/test/test_rake_rules.rb +0 -327
- data/test/test_rake_task.rb +0 -267
- data/test/test_rake_task_argument_parsing.rb +0 -103
- data/test/test_rake_task_arguments.rb +0 -88
- data/test/test_rake_task_lib.rb +0 -9
- data/test/test_rake_task_manager.rb +0 -157
- data/test/test_rake_task_manager_argument_resolution.rb +0 -36
- data/test/test_rake_task_with_arguments.rb +0 -173
- data/test/test_rake_test_task.rb +0 -120
- data/test/test_rake_top_level_functions.rb +0 -111
- data/test/test_rake_win32.rb +0 -72
- data/test/test_sys.rb +0 -20
data/lib/rake/task_manager.rb
CHANGED
@@ -1,37 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Rake
|
2
3
|
|
3
4
|
# The TaskManager module is a mixin for managing tasks.
|
4
5
|
module TaskManager
|
5
6
|
# Track the last comment made in the Rakefile.
|
6
7
|
attr_accessor :last_description
|
7
|
-
alias :last_comment :last_description # Backwards compatibility
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize # :nodoc:
|
10
10
|
super
|
11
11
|
@tasks = Hash.new
|
12
12
|
@rules = Array.new
|
13
|
-
@scope =
|
13
|
+
@scope = Scope.make
|
14
14
|
@last_description = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def create_rule(*args, &block)
|
18
|
-
pattern,
|
19
|
-
pattern = Regexp.new(Regexp.quote(pattern) +
|
20
|
-
@rules << [pattern, deps, block]
|
17
|
+
def create_rule(*args, &block) # :nodoc:
|
18
|
+
pattern, args, deps, order_only = resolve_args(args)
|
19
|
+
pattern = Regexp.new(Regexp.quote(pattern) + "$") if String === pattern
|
20
|
+
@rules << [pattern, args, deps, order_only, block]
|
21
21
|
end
|
22
22
|
|
23
|
-
def define_task(task_class, *args, &block)
|
24
|
-
task_name, arg_names, deps = resolve_args(args)
|
23
|
+
def define_task(task_class, *args, &block) # :nodoc:
|
24
|
+
task_name, arg_names, deps, order_only = resolve_args(args)
|
25
|
+
|
26
|
+
original_scope = @scope
|
27
|
+
if String === task_name and
|
28
|
+
not task_class.ancestors.include? Rake::FileTask
|
29
|
+
task_name, *definition_scope = *(task_name.split(":").reverse)
|
30
|
+
@scope = Scope.make(*(definition_scope + @scope.to_a))
|
31
|
+
end
|
32
|
+
|
25
33
|
task_name = task_class.scope_name(@scope, task_name)
|
26
|
-
deps = [deps] unless deps.respond_to?(:to_ary)
|
27
|
-
deps = deps.collect {|d| d.to_s }
|
28
34
|
task = intern(task_class, task_name)
|
29
35
|
task.set_arg_names(arg_names) unless arg_names.empty?
|
30
36
|
if Rake::TaskManager.record_task_metadata
|
31
37
|
add_location(task)
|
32
38
|
task.add_description(get_description(task))
|
33
39
|
end
|
34
|
-
task.enhance(deps, &block)
|
40
|
+
task.enhance(Task.format_deps(deps), &block)
|
41
|
+
task | order_only unless order_only.nil?
|
42
|
+
task
|
43
|
+
ensure
|
44
|
+
@scope = original_scope
|
35
45
|
end
|
36
46
|
|
37
47
|
# Lookup a task. Return an existing task if found, otherwise
|
@@ -46,16 +56,35 @@ module Rake
|
|
46
56
|
self.lookup(task_name, scopes) or
|
47
57
|
enhance_with_matching_rule(task_name) or
|
48
58
|
synthesize_file_task(task_name) or
|
49
|
-
fail
|
59
|
+
fail generate_message_for_undefined_task(task_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_message_for_undefined_task(task_name)
|
63
|
+
message = "Don't know how to build task '#{task_name}' "\
|
64
|
+
"(See the list of available tasks with `#{Rake.application.name} --tasks`)"
|
65
|
+
message + generate_did_you_mean_suggestions(task_name)
|
50
66
|
end
|
51
67
|
|
52
|
-
def
|
68
|
+
def generate_did_you_mean_suggestions(task_name)
|
69
|
+
return "" unless defined?(::DidYouMean::SpellChecker)
|
70
|
+
|
71
|
+
suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s)
|
72
|
+
if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later
|
73
|
+
::DidYouMean.formatter.message_for(suggestions)
|
74
|
+
elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0
|
75
|
+
::DidYouMean::Formatter.new(suggestions).to_s
|
76
|
+
else
|
77
|
+
""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def synthesize_file_task(task_name) # :nodoc:
|
53
82
|
return nil unless File.exist?(task_name)
|
54
83
|
define_task(Rake::FileTask, task_name)
|
55
84
|
end
|
56
85
|
|
57
|
-
# Resolve the arguments for a task/rule. Returns a
|
58
|
-
# [task_name, arg_name_list, prerequisites].
|
86
|
+
# Resolve the arguments for a task/rule. Returns a tuple of
|
87
|
+
# [task_name, arg_name_list, prerequisites, order_only_prerequisites].
|
59
88
|
def resolve_args(args)
|
60
89
|
if args.last.is_a?(Hash)
|
61
90
|
deps = args.pop
|
@@ -72,7 +101,6 @@ module Rake
|
|
72
101
|
#
|
73
102
|
# task :t
|
74
103
|
# task :t, [:a]
|
75
|
-
# task :t, :a (deprecated)
|
76
104
|
#
|
77
105
|
def resolve_args_without_dependencies(args)
|
78
106
|
task_name = args.shift
|
@@ -81,7 +109,7 @@ module Rake
|
|
81
109
|
else
|
82
110
|
arg_names = args
|
83
111
|
end
|
84
|
-
[task_name, arg_names, []]
|
112
|
+
[task_name, arg_names, [], nil]
|
85
113
|
end
|
86
114
|
private :resolve_args_without_dependencies
|
87
115
|
|
@@ -90,33 +118,29 @@ module Rake
|
|
90
118
|
#
|
91
119
|
# The patterns recognized by this argument resolving function are:
|
92
120
|
#
|
121
|
+
# task :t, order_only: [:e]
|
93
122
|
# task :t => [:d]
|
123
|
+
# task :t => [:d], order_only: [:e]
|
94
124
|
# task :t, [a] => [:d]
|
95
|
-
# task :t,
|
96
|
-
# task :t, :a, :needs => [:d] (deprecated)
|
125
|
+
# task :t, [a] => [:d], order_only: [:e]
|
97
126
|
#
|
98
127
|
def resolve_args_with_dependencies(args, hash) # :nodoc:
|
99
|
-
fail "Task Argument Error" if
|
100
|
-
|
128
|
+
fail "Task Argument Error" if
|
129
|
+
hash.size != 1 &&
|
130
|
+
(hash.size != 2 || !hash.key?(:order_only))
|
131
|
+
order_only = hash.delete(:order_only)
|
132
|
+
key, value = hash.map { |k, v| [k, v] }.first
|
101
133
|
if args.empty?
|
102
134
|
task_name = key
|
103
135
|
arg_names = []
|
104
|
-
deps = value
|
105
|
-
elsif key == :needs
|
106
|
-
Rake.application.deprecate(
|
107
|
-
"task :t, arg, :needs => [deps]",
|
108
|
-
"task :t, [args] => [deps]",
|
109
|
-
caller.detect { |c| c !~ /\blib\/rake\b/ })
|
110
|
-
task_name = args.shift
|
111
|
-
arg_names = args
|
112
|
-
deps = value
|
136
|
+
deps = value || []
|
113
137
|
else
|
114
138
|
task_name = args.shift
|
115
|
-
arg_names = key
|
116
|
-
deps = value
|
139
|
+
arg_names = key || args.shift|| []
|
140
|
+
deps = value || []
|
117
141
|
end
|
118
142
|
deps = [deps] unless deps.respond_to?(:to_ary)
|
119
|
-
[task_name, arg_names, deps]
|
143
|
+
[task_name, arg_names, deps, order_only]
|
120
144
|
end
|
121
145
|
private :resolve_args_with_dependencies
|
122
146
|
|
@@ -127,9 +151,10 @@ module Rake
|
|
127
151
|
def enhance_with_matching_rule(task_name, level=0)
|
128
152
|
fail Rake::RuleRecursionOverflowError,
|
129
153
|
"Rule Recursion Too Deep" if level >= 16
|
130
|
-
@rules.each do |pattern, extensions, block|
|
131
|
-
if pattern.match(task_name)
|
132
|
-
task = attempt_rule(task_name, extensions, block, level)
|
154
|
+
@rules.each do |pattern, args, extensions, order_only, block|
|
155
|
+
if pattern && pattern.match(task_name)
|
156
|
+
task = attempt_rule(task_name, pattern, args, extensions, block, level)
|
157
|
+
task | order_only unless order_only.nil?
|
133
158
|
return task if task
|
134
159
|
end
|
135
160
|
end
|
@@ -147,7 +172,7 @@ module Rake
|
|
147
172
|
# List of all the tasks defined in the given scope (and its
|
148
173
|
# sub-scopes).
|
149
174
|
def tasks_in_scope(scope)
|
150
|
-
prefix = scope.
|
175
|
+
prefix = scope.path
|
151
176
|
tasks.select { |t|
|
152
177
|
/^#{prefix}:/ =~ t.name
|
153
178
|
}
|
@@ -168,11 +193,11 @@ module Rake
|
|
168
193
|
initial_scope ||= @scope
|
169
194
|
task_name = task_name.to_s
|
170
195
|
if task_name =~ /^rake:/
|
171
|
-
scopes =
|
172
|
-
task_name = task_name.sub(/^rake:/,
|
196
|
+
scopes = Scope.make
|
197
|
+
task_name = task_name.sub(/^rake:/, "")
|
173
198
|
elsif task_name =~ /^(\^+)/
|
174
|
-
scopes = initial_scope
|
175
|
-
task_name = task_name.sub(/^(\^+)/,
|
199
|
+
scopes = initial_scope.trim($1.size)
|
200
|
+
task_name = task_name.sub(/^(\^+)/, "")
|
176
201
|
else
|
177
202
|
scopes = initial_scope
|
178
203
|
end
|
@@ -181,12 +206,12 @@ module Rake
|
|
181
206
|
|
182
207
|
# Lookup the task name
|
183
208
|
def lookup_in_scope(name, scope)
|
184
|
-
|
185
|
-
|
186
|
-
tn = (scope[0,n] + [name]).join(':')
|
209
|
+
loop do
|
210
|
+
tn = scope.path_with_task_name(name)
|
187
211
|
task = @tasks[tn]
|
188
212
|
return task if task
|
189
|
-
|
213
|
+
break if scope.empty?
|
214
|
+
scope = scope.tail
|
190
215
|
end
|
191
216
|
nil
|
192
217
|
end
|
@@ -195,19 +220,19 @@ module Rake
|
|
195
220
|
# Return the list of scope names currently active in the task
|
196
221
|
# manager.
|
197
222
|
def current_scope
|
198
|
-
@scope
|
223
|
+
@scope
|
199
224
|
end
|
200
225
|
|
201
226
|
# Evaluate the block in a nested namespace named +name+. Create
|
202
227
|
# an anonymous namespace if +name+ is nil.
|
203
228
|
def in_namespace(name)
|
204
229
|
name ||= generate_name
|
205
|
-
@scope.
|
230
|
+
@scope = Scope.new(name, @scope)
|
206
231
|
ns = NameSpace.new(self, @scope)
|
207
232
|
yield(ns)
|
208
233
|
ns
|
209
234
|
ensure
|
210
|
-
@scope.
|
235
|
+
@scope = @scope.tail
|
211
236
|
end
|
212
237
|
|
213
238
|
private
|
@@ -224,7 +249,7 @@ module Rake
|
|
224
249
|
locations = caller
|
225
250
|
i = 0
|
226
251
|
while locations[i]
|
227
|
-
return locations[i+1] if locations[i] =~ /rake\/dsl_definition.rb/
|
252
|
+
return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
|
228
253
|
i += 1
|
229
254
|
end
|
230
255
|
nil
|
@@ -237,19 +262,20 @@ module Rake
|
|
237
262
|
"_anon_#{@seed}"
|
238
263
|
end
|
239
264
|
|
240
|
-
def trace_rule(level, message)
|
241
|
-
|
265
|
+
def trace_rule(level, message) # :nodoc:
|
266
|
+
options.trace_output.puts "#{" " * level}#{message}" if
|
267
|
+
Rake.application.options.trace_rules
|
242
268
|
end
|
243
269
|
|
244
270
|
# Attempt to create a rule given the list of prerequisites.
|
245
|
-
def attempt_rule(task_name, extensions, block, level)
|
246
|
-
sources = make_sources(task_name, extensions)
|
247
|
-
prereqs = sources.
|
271
|
+
def attempt_rule(task_name, task_pattern, args, extensions, block, level)
|
272
|
+
sources = make_sources(task_name, task_pattern, extensions)
|
273
|
+
prereqs = sources.map { |source|
|
248
274
|
trace_rule level, "Attempting Rule #{task_name} => #{source}"
|
249
275
|
if File.exist?(source) || Rake::Task.task_defined?(source)
|
250
276
|
trace_rule level, "(#{task_name} => #{source} ... EXIST)"
|
251
277
|
source
|
252
|
-
elsif parent = enhance_with_matching_rule(source, level+1)
|
278
|
+
elsif parent = enhance_with_matching_rule(source, level + 1)
|
253
279
|
trace_rule level, "(#{task_name} => #{source} ... ENHANCE)"
|
254
280
|
parent.name
|
255
281
|
else
|
@@ -257,25 +283,26 @@ module Rake
|
|
257
283
|
return nil
|
258
284
|
end
|
259
285
|
}
|
260
|
-
task = FileTask.define_task(
|
286
|
+
task = FileTask.define_task(task_name, { args => prereqs }, &block)
|
261
287
|
task.sources = prereqs
|
262
288
|
task
|
263
289
|
end
|
264
290
|
|
265
291
|
# Make a list of sources from the list of file name extensions /
|
266
292
|
# translation procs.
|
267
|
-
def make_sources(task_name, extensions)
|
268
|
-
result = extensions.
|
293
|
+
def make_sources(task_name, task_pattern, extensions)
|
294
|
+
result = extensions.map { |ext|
|
269
295
|
case ext
|
270
296
|
when /%/
|
271
297
|
task_name.pathmap(ext)
|
272
298
|
when %r{/}
|
273
299
|
ext
|
274
300
|
when /^\./
|
275
|
-
task_name.
|
276
|
-
|
277
|
-
|
278
|
-
|
301
|
+
source = task_name.sub(task_pattern, ext)
|
302
|
+
source == ext ? task_name.ext(ext) : source
|
303
|
+
when String, Symbol
|
304
|
+
ext.to_s
|
305
|
+
when Proc, Method
|
279
306
|
if ext.arity == 1
|
280
307
|
ext.call(task_name)
|
281
308
|
else
|
@@ -288,9 +315,6 @@ module Rake
|
|
288
315
|
result.flatten
|
289
316
|
end
|
290
317
|
|
291
|
-
|
292
|
-
private
|
293
|
-
|
294
318
|
# Return the current description, clearing it in the process.
|
295
319
|
def get_description(task)
|
296
320
|
desc = @last_description
|
@@ -299,7 +323,7 @@ module Rake
|
|
299
323
|
end
|
300
324
|
|
301
325
|
class << self
|
302
|
-
attr_accessor :record_task_metadata
|
326
|
+
attr_accessor :record_task_metadata # :nodoc:
|
303
327
|
TaskManager.record_task_metadata = false
|
304
328
|
end
|
305
329
|
end
|
data/lib/rake/tasklib.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rake"
|
2
3
|
|
3
4
|
module Rake
|
4
5
|
|
@@ -6,17 +7,6 @@ module Rake
|
|
6
7
|
class TaskLib
|
7
8
|
include Cloneable
|
8
9
|
include Rake::DSL
|
9
|
-
|
10
|
-
# Make a symbol by pasting two strings together.
|
11
|
-
#
|
12
|
-
# NOTE: DEPRECATED! This method is kinda stupid. I don't know why
|
13
|
-
# I didn't just use string interpolation. But now other task
|
14
|
-
# libraries depend on this so I can't remove it without breaking
|
15
|
-
# other people's code. So for now it stays for backwards
|
16
|
-
# compatibility. BUT DON'T USE IT.
|
17
|
-
def paste(a,b) # :nodoc:
|
18
|
-
(a.to_s + b.to_s).intern
|
19
|
-
end
|
20
10
|
end
|
21
11
|
|
22
12
|
end
|
data/lib/rake/testtask.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require
|
4
|
-
require 'rake/tasklib'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rake"
|
3
|
+
require "rake/tasklib"
|
5
4
|
|
6
5
|
module Rake
|
7
6
|
|
8
7
|
# Create a task that runs a set of tests.
|
9
8
|
#
|
10
9
|
# Example:
|
10
|
+
# require "rake/testtask"
|
11
11
|
#
|
12
12
|
# Rake::TestTask.new do |t|
|
13
13
|
# t.libs << "test"
|
@@ -37,7 +37,7 @@ module Rake
|
|
37
37
|
# Name of test task. (default is :test)
|
38
38
|
attr_accessor :name
|
39
39
|
|
40
|
-
# List of directories
|
40
|
+
# List of directories added to $LOAD_PATH before running the
|
41
41
|
# tests. (default is 'lib')
|
42
42
|
attr_accessor :libs
|
43
43
|
|
@@ -51,6 +51,7 @@ module Rake
|
|
51
51
|
|
52
52
|
# Request that the tests be run with the warning flag set.
|
53
53
|
# E.g. warning=true implies "ruby -w" used to run the tests.
|
54
|
+
# (default is true)
|
54
55
|
attr_accessor :warning
|
55
56
|
|
56
57
|
# Glob pattern to match test files. (default is 'test/test*.rb')
|
@@ -64,9 +65,15 @@ module Rake
|
|
64
65
|
#
|
65
66
|
attr_accessor :loader
|
66
67
|
|
67
|
-
# Array of
|
68
|
+
# Array of command line options to pass to ruby when running test loader.
|
68
69
|
attr_accessor :ruby_opts
|
69
70
|
|
71
|
+
# Description of the test task. (default is 'Run tests')
|
72
|
+
attr_accessor :description
|
73
|
+
|
74
|
+
# Task prerequisites.
|
75
|
+
attr_accessor :deps
|
76
|
+
|
70
77
|
# Explicitly define the list of test files to be included in a
|
71
78
|
# test. +list+ is expected to be an array of file names (a
|
72
79
|
# FileList is acceptable). If both +pattern+ and +test_files+ are
|
@@ -83,108 +90,99 @@ module Rake
|
|
83
90
|
@options = nil
|
84
91
|
@test_files = nil
|
85
92
|
@verbose = false
|
86
|
-
@warning =
|
93
|
+
@warning = true
|
87
94
|
@loader = :rake
|
88
95
|
@ruby_opts = []
|
96
|
+
@description = "Run tests" + (@name == :test ? "" : " for #{@name}")
|
97
|
+
@deps = []
|
98
|
+
if @name.is_a?(Hash)
|
99
|
+
@deps = @name.values.first
|
100
|
+
@name = @name.keys.first
|
101
|
+
end
|
89
102
|
yield self if block_given?
|
90
|
-
@pattern =
|
103
|
+
@pattern = "test/test*.rb" if @pattern.nil? && @test_files.nil?
|
91
104
|
define
|
92
105
|
end
|
93
106
|
|
94
107
|
# Create the tasks defined by this task lib.
|
95
108
|
def define
|
96
|
-
desc
|
97
|
-
task @name do
|
109
|
+
desc @description
|
110
|
+
task @name => Array(deps) do
|
98
111
|
FileUtilsExt.verbose(@verbose) do
|
99
|
-
|
112
|
+
puts "Use TESTOPTS=\"--verbose\" to pass --verbose" \
|
113
|
+
", etc. to runners." if ARGV.include? "--verbose"
|
114
|
+
args =
|
115
|
+
"#{ruby_opts_string} #{run_code} " +
|
116
|
+
"#{file_list_string} #{option_list}"
|
117
|
+
ruby args do |ok, status|
|
118
|
+
if !ok && status.respond_to?(:signaled?) && status.signaled?
|
119
|
+
raise SignalException.new(status.termsig)
|
120
|
+
elsif !ok
|
121
|
+
status = "Command failed with status (#{status.exitstatus})"
|
122
|
+
details = ": [ruby #{args}]"
|
123
|
+
message =
|
124
|
+
if Rake.application.options.trace or @verbose
|
125
|
+
status + details
|
126
|
+
else
|
127
|
+
status
|
128
|
+
end
|
129
|
+
|
130
|
+
fail message
|
131
|
+
end
|
132
|
+
end
|
100
133
|
end
|
101
134
|
end
|
102
135
|
self
|
103
136
|
end
|
104
137
|
|
105
138
|
def option_list # :nodoc:
|
106
|
-
(ENV[
|
107
|
-
ENV[
|
108
|
-
ENV[
|
109
|
-
ENV[
|
139
|
+
(ENV["TESTOPTS"] ||
|
140
|
+
ENV["TESTOPT"] ||
|
141
|
+
ENV["TEST_OPTS"] ||
|
142
|
+
ENV["TEST_OPT"] ||
|
110
143
|
@options ||
|
111
144
|
"")
|
112
145
|
end
|
113
146
|
|
114
|
-
def ruby_opts_string
|
147
|
+
def ruby_opts_string # :nodoc:
|
115
148
|
opts = @ruby_opts.dup
|
116
|
-
opts.unshift(
|
117
|
-
opts.unshift(
|
149
|
+
opts.unshift("-I\"#{lib_path}\"") unless @libs.empty?
|
150
|
+
opts.unshift("-w") if @warning
|
118
151
|
opts.join(" ")
|
119
152
|
end
|
120
153
|
|
121
|
-
def lib_path
|
154
|
+
def lib_path # :nodoc:
|
122
155
|
@libs.join(File::PATH_SEPARATOR)
|
123
156
|
end
|
124
157
|
|
125
|
-
def file_list_string
|
126
|
-
file_list.
|
158
|
+
def file_list_string # :nodoc:
|
159
|
+
file_list.map { |fn| "\"#{fn}\"" }.join(" ")
|
127
160
|
end
|
128
161
|
|
129
162
|
def file_list # :nodoc:
|
130
|
-
if ENV[
|
131
|
-
FileList[
|
163
|
+
if ENV["TEST"]
|
164
|
+
FileList[ENV["TEST"]]
|
132
165
|
else
|
133
166
|
result = []
|
134
167
|
result += @test_files.to_a if @test_files
|
135
|
-
result
|
168
|
+
result += FileList[@pattern].to_a if @pattern
|
136
169
|
result
|
137
170
|
end
|
138
171
|
end
|
139
172
|
|
140
|
-
def
|
141
|
-
case ruby_version
|
142
|
-
when '1.8.2'
|
143
|
-
"\"#{find_file 'rake/ruby182_test_unit_fix'}\""
|
144
|
-
else
|
145
|
-
nil
|
146
|
-
end || ''
|
147
|
-
end
|
148
|
-
|
149
|
-
def ruby_version
|
173
|
+
def ruby_version # :nodoc:
|
150
174
|
RUBY_VERSION
|
151
175
|
end
|
152
176
|
|
153
|
-
def run_code
|
177
|
+
def run_code # :nodoc:
|
154
178
|
case @loader
|
155
179
|
when :direct
|
156
180
|
"-e \"ARGV.each{|f| require f}\""
|
157
181
|
when :testrb
|
158
|
-
"-S testrb
|
182
|
+
"-S testrb"
|
159
183
|
when :rake
|
160
|
-
"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def rake_loader # :nodoc:
|
165
|
-
find_file('rake/rake_test_loader') or
|
166
|
-
fail "unable to find rake test loader"
|
167
|
-
end
|
168
|
-
|
169
|
-
def find_file(fn) # :nodoc:
|
170
|
-
$LOAD_PATH.each do |path|
|
171
|
-
file_path = File.join(path, "#{fn}.rb")
|
172
|
-
return file_path if File.exist? file_path
|
173
|
-
end
|
174
|
-
nil
|
175
|
-
end
|
176
|
-
|
177
|
-
def rake_lib_dir # :nodoc:
|
178
|
-
find_dir('rake') or
|
179
|
-
fail "unable to find rake lib"
|
180
|
-
end
|
181
|
-
|
182
|
-
def find_dir(fn) # :nodoc:
|
183
|
-
$LOAD_PATH.each do |path|
|
184
|
-
file_path = File.join(path, "#{fn}.rb")
|
185
|
-
return path if File.exist? file_path
|
184
|
+
"#{__dir__}/rake_test_loader.rb"
|
186
185
|
end
|
187
|
-
nil
|
188
186
|
end
|
189
187
|
|
190
188
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rake/private_reader"
|
3
|
+
|
4
|
+
module Rake
|
5
|
+
|
6
|
+
class ThreadHistoryDisplay # :nodoc: all
|
7
|
+
include Rake::PrivateReader
|
8
|
+
|
9
|
+
private_reader :stats, :items, :threads
|
10
|
+
|
11
|
+
def initialize(stats)
|
12
|
+
@stats = stats
|
13
|
+
@items = { _seq_: 1 }
|
14
|
+
@threads = { _seq_: "A" }
|
15
|
+
end
|
16
|
+
|
17
|
+
def show
|
18
|
+
puts "Job History:"
|
19
|
+
stats.each do |stat|
|
20
|
+
stat[:data] ||= {}
|
21
|
+
rename(stat, :thread, threads)
|
22
|
+
rename(stat[:data], :item_id, items)
|
23
|
+
rename(stat[:data], :new_thread, threads)
|
24
|
+
rename(stat[:data], :deleted_thread, threads)
|
25
|
+
printf("%8d %2s %-20s %s\n",
|
26
|
+
(stat[:time] * 1_000_000).round,
|
27
|
+
stat[:thread],
|
28
|
+
stat[:event],
|
29
|
+
stat[:data].map do |k, v| "#{k}:#{v}" end.join(" "))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def rename(hash, key, renames)
|
36
|
+
if hash && hash[key]
|
37
|
+
original = hash[key]
|
38
|
+
value = renames[original]
|
39
|
+
unless value
|
40
|
+
value = renames[:_seq_]
|
41
|
+
renames[:_seq_] = renames[:_seq_].succ
|
42
|
+
renames[original] = value
|
43
|
+
end
|
44
|
+
hash[key] = value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|