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.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/History.rdoc +2403 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +64 -106
  5. data/doc/command_line_usage.rdoc +65 -21
  6. data/doc/glossary.rdoc +40 -49
  7. data/doc/jamis.rb +1 -0
  8. data/doc/rake.1 +156 -0
  9. data/doc/rakefile.rdoc +127 -62
  10. data/{bin → exe}/rake +1 -7
  11. data/lib/rake/application.rb +507 -271
  12. data/lib/rake/backtrace.rb +24 -0
  13. data/lib/rake/clean.rb +54 -8
  14. data/lib/rake/cloneable.rb +11 -19
  15. data/lib/rake/cpu_counter.rb +107 -0
  16. data/lib/rake/default_loader.rb +5 -0
  17. data/lib/rake/dsl_definition.rb +67 -48
  18. data/lib/rake/early_time.rb +5 -1
  19. data/lib/rake/ext/core.rb +5 -6
  20. data/lib/rake/ext/string.rb +61 -52
  21. data/lib/rake/file_creation_task.rb +4 -3
  22. data/lib/rake/file_list.rb +81 -49
  23. data/lib/rake/file_task.rb +15 -8
  24. data/lib/rake/file_utils.rb +63 -43
  25. data/lib/rake/file_utils_ext.rb +14 -25
  26. data/lib/rake/invocation_chain.rb +25 -19
  27. data/lib/rake/invocation_exception_mixin.rb +1 -0
  28. data/lib/rake/late_time.rb +18 -0
  29. data/lib/rake/linked_list.rb +112 -0
  30. data/lib/rake/loaders/makefile.rb +23 -9
  31. data/lib/rake/multi_task.rb +4 -6
  32. data/lib/rake/name_space.rb +36 -23
  33. data/lib/rake/packagetask.rb +71 -34
  34. data/lib/rake/phony.rb +16 -0
  35. data/lib/rake/private_reader.rb +21 -0
  36. data/lib/rake/promise.rb +100 -0
  37. data/lib/rake/pseudo_status.rb +8 -2
  38. data/lib/rake/rake_module.rb +41 -3
  39. data/lib/rake/rake_test_loader.rb +9 -4
  40. data/lib/rake/rule_recursion_overflow_error.rb +2 -2
  41. data/lib/rake/scope.rb +43 -0
  42. data/lib/rake/task.rb +186 -79
  43. data/lib/rake/task_argument_error.rb +1 -0
  44. data/lib/rake/task_arguments.rb +46 -15
  45. data/lib/rake/task_manager.rb +91 -67
  46. data/lib/rake/tasklib.rb +2 -12
  47. data/lib/rake/testtask.rb +61 -63
  48. data/lib/rake/thread_history_display.rb +49 -0
  49. data/lib/rake/thread_pool.rb +163 -0
  50. data/lib/rake/trace_output.rb +23 -0
  51. data/lib/rake/version.rb +5 -3
  52. data/lib/rake/win32.rb +14 -18
  53. data/lib/rake.rb +35 -33
  54. data/rake.gemspec +100 -0
  55. metadata +74 -176
  56. data/.gemtest +0 -0
  57. data/CHANGES +0 -522
  58. data/Rakefile +0 -369
  59. data/TODO +0 -20
  60. data/doc/rake.1.gz +0 -0
  61. data/doc/release_notes/rake-0.4.14.rdoc +0 -23
  62. data/doc/release_notes/rake-0.4.15.rdoc +0 -35
  63. data/doc/release_notes/rake-0.5.0.rdoc +0 -53
  64. data/doc/release_notes/rake-0.5.3.rdoc +0 -78
  65. data/doc/release_notes/rake-0.5.4.rdoc +0 -46
  66. data/doc/release_notes/rake-0.6.0.rdoc +0 -141
  67. data/doc/release_notes/rake-0.7.0.rdoc +0 -119
  68. data/doc/release_notes/rake-0.7.1.rdoc +0 -59
  69. data/doc/release_notes/rake-0.7.2.rdoc +0 -121
  70. data/doc/release_notes/rake-0.7.3.rdoc +0 -47
  71. data/doc/release_notes/rake-0.8.0.rdoc +0 -114
  72. data/doc/release_notes/rake-0.8.2.rdoc +0 -165
  73. data/doc/release_notes/rake-0.8.3.rdoc +0 -112
  74. data/doc/release_notes/rake-0.8.4.rdoc +0 -147
  75. data/doc/release_notes/rake-0.8.5.rdoc +0 -53
  76. data/doc/release_notes/rake-0.8.6.rdoc +0 -55
  77. data/doc/release_notes/rake-0.8.7.rdoc +0 -55
  78. data/doc/release_notes/rake-0.9.0.rdoc +0 -112
  79. data/doc/release_notes/rake-0.9.1.rdoc +0 -52
  80. data/doc/release_notes/rake-0.9.2.rdoc +0 -49
  81. data/install.rb +0 -90
  82. data/lib/rake/alt_system.rb +0 -109
  83. data/lib/rake/classic_namespace.rb +0 -11
  84. data/lib/rake/contrib/compositepublisher.rb +0 -21
  85. data/lib/rake/contrib/ftptools.rb +0 -150
  86. data/lib/rake/contrib/publisher.rb +0 -73
  87. data/lib/rake/contrib/rubyforgepublisher.rb +0 -16
  88. data/lib/rake/contrib/sshpublisher.rb +0 -50
  89. data/lib/rake/contrib/sys.rb +0 -191
  90. data/lib/rake/ext/module.rb +0 -39
  91. data/lib/rake/ext/time.rb +0 -14
  92. data/lib/rake/gempackagetask.rb +0 -15
  93. data/lib/rake/pathmap.rb +0 -1
  94. data/lib/rake/rdoctask.rb +0 -234
  95. data/lib/rake/ruby182_test_unit_fix.rb +0 -25
  96. data/lib/rake/runtest.rb +0 -21
  97. data/test/file_creation.rb +0 -34
  98. data/test/helper.rb +0 -492
  99. data/test/test_rake.rb +0 -40
  100. data/test/test_rake_application.rb +0 -489
  101. data/test/test_rake_application_options.rb +0 -335
  102. data/test/test_rake_clean.rb +0 -14
  103. data/test/test_rake_definitions.rb +0 -80
  104. data/test/test_rake_directory_task.rb +0 -46
  105. data/test/test_rake_dsl.rb +0 -77
  106. data/test/test_rake_early_time.rb +0 -31
  107. data/test/test_rake_extension.rb +0 -59
  108. data/test/test_rake_file_creation_task.rb +0 -56
  109. data/test/test_rake_file_list.rb +0 -628
  110. data/test/test_rake_file_list_path_map.rb +0 -8
  111. data/test/test_rake_file_task.rb +0 -102
  112. data/test/test_rake_file_utils.rb +0 -305
  113. data/test/test_rake_ftp_file.rb +0 -59
  114. data/test/test_rake_functional.rb +0 -450
  115. data/test/test_rake_invocation_chain.rb +0 -52
  116. data/test/test_rake_makefile_loader.rb +0 -44
  117. data/test/test_rake_multi_task.rb +0 -51
  118. data/test/test_rake_name_space.rb +0 -43
  119. data/test/test_rake_package_task.rb +0 -79
  120. data/test/test_rake_path_map.rb +0 -157
  121. data/test/test_rake_path_map_explode.rb +0 -34
  122. data/test/test_rake_path_map_partial.rb +0 -18
  123. data/test/test_rake_pseudo_status.rb +0 -21
  124. data/test/test_rake_rake_test_loader.rb +0 -21
  125. data/test/test_rake_rdoc_task.rb +0 -83
  126. data/test/test_rake_require.rb +0 -40
  127. data/test/test_rake_rules.rb +0 -327
  128. data/test/test_rake_task.rb +0 -267
  129. data/test/test_rake_task_argument_parsing.rb +0 -103
  130. data/test/test_rake_task_arguments.rb +0 -88
  131. data/test/test_rake_task_lib.rb +0 -9
  132. data/test/test_rake_task_manager.rb +0 -157
  133. data/test/test_rake_task_manager_argument_resolution.rb +0 -36
  134. data/test/test_rake_task_with_arguments.rb +0 -173
  135. data/test/test_rake_test_task.rb +0 -120
  136. data/test/test_rake_top_level_functions.rb +0 -111
  137. data/test/test_rake_win32.rb +0 -72
  138. data/test/test_sys.rb +0 -20
@@ -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 = Array.new
13
+ @scope = Scope.make
14
14
  @last_description = nil
15
15
  end
16
16
 
17
- def create_rule(*args, &block)
18
- pattern, _, deps = resolve_args(args)
19
- pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === 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 "Don't know how to build task '#{task_name}'"
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 synthesize_file_task(task_name)
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 triplet of
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, :needs => [:d] (deprecated)
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 hash.size != 1
100
- key, value = hash.map { |k, v| [k,v] }.first
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.join(":")
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[0, initial_scope.size - $1.size]
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
- n = scope.size
185
- while n >= 0
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
- n -= 1
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.dup
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.push(name)
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.pop
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
- $stderr.puts "#{" "*level}#{message}" if Rake.application.options.trace_rules
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.collect { |source|
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({task_name => prereqs}, &block)
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.collect { |ext|
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.ext(ext)
276
- when String
277
- ext
278
- when Proc
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
- require 'rake'
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
- # Define a task library for running unit tests.
2
-
3
- require 'rake'
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 to added to $LOAD_PATH before running the
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 commandline options to pass to ruby when running test loader.
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 = false
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 = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
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 "Run tests" + (@name==:test ? "" : " for #{@name}")
97
- task @name do
109
+ desc @description
110
+ task @name => Array(deps) do
98
111
  FileUtilsExt.verbose(@verbose) do
99
- ruby "#{ruby_opts_string} #{run_code} #{file_list_string} #{option_list}"
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['TESTOPTS'] ||
107
- ENV['TESTOPT'] ||
108
- ENV['TEST_OPTS'] ||
109
- ENV['TEST_OPT'] ||
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( "-I\"#{lib_path}\"" ) unless @libs.empty?
117
- opts.unshift( "-w" ) if @warning
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.collect { |fn| "\"#{fn}\"" }.join(' ')
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['TEST']
131
- FileList[ ENV['TEST'] ]
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 << @pattern if @pattern
168
+ result += FileList[@pattern].to_a if @pattern
136
169
  result
137
170
  end
138
171
  end
139
172
 
140
- def fix # :nodoc:
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 #{fix}"
182
+ "-S testrb"
159
183
  when :rake
160
- "-I\"#{rake_lib_dir}\" \"#{rake_loader}\""
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