rake 10.0.0.beta.2 → 13.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/macos.yml +22 -0
  3. data/.github/workflows/ubuntu-rvm.yml +28 -0
  4. data/.github/workflows/ubuntu.yml +20 -0
  5. data/.github/workflows/windows.yml +20 -0
  6. data/CONTRIBUTING.rdoc +43 -0
  7. data/Gemfile +10 -0
  8. data/History.rdoc +2359 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.rdoc +57 -101
  11. data/Rakefile +22 -354
  12. data/bin/bundle +105 -0
  13. data/bin/console +7 -0
  14. data/bin/rake +19 -27
  15. data/bin/rdoc +29 -0
  16. data/bin/rubocop +29 -0
  17. data/bin/setup +6 -0
  18. data/doc/command_line_usage.rdoc +30 -18
  19. data/doc/glossary.rdoc +40 -49
  20. data/doc/jamis.rb +1 -0
  21. data/doc/rake.1 +156 -0
  22. data/doc/rakefile.rdoc +127 -62
  23. data/exe/rake +27 -0
  24. data/lib/rake.rb +35 -34
  25. data/lib/rake/application.rb +355 -188
  26. data/lib/rake/backtrace.rb +14 -7
  27. data/lib/rake/clean.rb +54 -8
  28. data/lib/rake/cloneable.rb +5 -4
  29. data/lib/rake/cpu_counter.rb +107 -0
  30. data/lib/rake/default_loader.rb +5 -0
  31. data/lib/rake/dsl_definition.rb +58 -19
  32. data/lib/rake/early_time.rb +5 -1
  33. data/lib/rake/ext/core.rb +5 -6
  34. data/lib/rake/ext/string.rb +61 -52
  35. data/lib/rake/file_creation_task.rb +4 -3
  36. data/lib/rake/file_list.rb +81 -49
  37. data/lib/rake/file_task.rb +15 -8
  38. data/lib/rake/file_utils.rb +63 -43
  39. data/lib/rake/file_utils_ext.rb +10 -22
  40. data/lib/rake/invocation_chain.rb +25 -19
  41. data/lib/rake/invocation_exception_mixin.rb +1 -0
  42. data/lib/rake/late_time.rb +18 -0
  43. data/lib/rake/linked_list.rb +112 -0
  44. data/lib/rake/loaders/makefile.rb +23 -9
  45. data/lib/rake/multi_task.rb +2 -1
  46. data/lib/rake/name_space.rb +36 -23
  47. data/lib/rake/packagetask.rb +71 -34
  48. data/lib/rake/phony.rb +6 -3
  49. data/lib/rake/private_reader.rb +21 -0
  50. data/lib/rake/promise.rb +100 -0
  51. data/lib/rake/pseudo_status.rb +8 -2
  52. data/lib/rake/rake_module.rb +34 -11
  53. data/lib/rake/rake_test_loader.rb +18 -13
  54. data/lib/rake/rule_recursion_overflow_error.rb +2 -2
  55. data/lib/rake/scope.rb +43 -0
  56. data/lib/rake/task.rb +166 -82
  57. data/lib/rake/task_argument_error.rb +1 -0
  58. data/lib/rake/task_arguments.rb +45 -14
  59. data/lib/rake/task_manager.rb +82 -50
  60. data/lib/rake/tasklib.rb +2 -12
  61. data/lib/rake/testtask.rb +68 -39
  62. data/lib/rake/thread_history_display.rb +10 -6
  63. data/lib/rake/thread_pool.rb +60 -86
  64. data/lib/rake/trace_output.rb +23 -0
  65. data/lib/rake/version.rb +6 -8
  66. data/lib/rake/win32.rb +14 -18
  67. data/rake.gemspec +36 -0
  68. metadata +64 -166
  69. data/.gemtest +0 -0
  70. data/CHANGES +0 -526
  71. data/TODO +0 -21
  72. data/doc/rake.1.gz +0 -0
  73. data/doc/release_notes/rake-0.4.14.rdoc +0 -23
  74. data/doc/release_notes/rake-0.4.15.rdoc +0 -35
  75. data/doc/release_notes/rake-0.5.0.rdoc +0 -53
  76. data/doc/release_notes/rake-0.5.3.rdoc +0 -78
  77. data/doc/release_notes/rake-0.5.4.rdoc +0 -46
  78. data/doc/release_notes/rake-0.6.0.rdoc +0 -141
  79. data/doc/release_notes/rake-0.7.0.rdoc +0 -119
  80. data/doc/release_notes/rake-0.7.1.rdoc +0 -59
  81. data/doc/release_notes/rake-0.7.2.rdoc +0 -121
  82. data/doc/release_notes/rake-0.7.3.rdoc +0 -47
  83. data/doc/release_notes/rake-0.8.0.rdoc +0 -114
  84. data/doc/release_notes/rake-0.8.2.rdoc +0 -165
  85. data/doc/release_notes/rake-0.8.3.rdoc +0 -112
  86. data/doc/release_notes/rake-0.8.4.rdoc +0 -147
  87. data/doc/release_notes/rake-0.8.5.rdoc +0 -53
  88. data/doc/release_notes/rake-0.8.6.rdoc +0 -55
  89. data/doc/release_notes/rake-0.8.7.rdoc +0 -55
  90. data/doc/release_notes/rake-0.9.0.rdoc +0 -112
  91. data/doc/release_notes/rake-0.9.1.rdoc +0 -52
  92. data/doc/release_notes/rake-0.9.2.2.rdoc +0 -55
  93. data/doc/release_notes/rake-0.9.2.rdoc +0 -49
  94. data/doc/release_notes/rake-0.9.3.rdoc +0 -102
  95. data/doc/release_notes/rake-10.0.0.rdoc +0 -178
  96. data/install.rb +0 -90
  97. data/lib/rake/alt_system.rb +0 -109
  98. data/lib/rake/contrib/compositepublisher.rb +0 -21
  99. data/lib/rake/contrib/ftptools.rb +0 -151
  100. data/lib/rake/contrib/publisher.rb +0 -73
  101. data/lib/rake/contrib/rubyforgepublisher.rb +0 -16
  102. data/lib/rake/contrib/sshpublisher.rb +0 -50
  103. data/lib/rake/ext/module.rb +0 -0
  104. data/lib/rake/ext/time.rb +0 -14
  105. data/lib/rake/pathmap.rb +0 -1
  106. data/lib/rake/ruby182_test_unit_fix.rb +0 -25
  107. data/lib/rake/runtest.rb +0 -21
  108. data/test/file_creation.rb +0 -34
  109. data/test/helper.rb +0 -522
  110. data/test/test_rake.rb +0 -40
  111. data/test/test_rake_application.rb +0 -484
  112. data/test/test_rake_application_options.rb +0 -427
  113. data/test/test_rake_backtrace.rb +0 -67
  114. data/test/test_rake_clean.rb +0 -14
  115. data/test/test_rake_definitions.rb +0 -80
  116. data/test/test_rake_directory_task.rb +0 -57
  117. data/test/test_rake_dsl.rb +0 -40
  118. data/test/test_rake_early_time.rb +0 -31
  119. data/test/test_rake_extension.rb +0 -59
  120. data/test/test_rake_file_creation_task.rb +0 -56
  121. data/test/test_rake_file_list.rb +0 -628
  122. data/test/test_rake_file_list_path_map.rb +0 -8
  123. data/test/test_rake_file_task.rb +0 -122
  124. data/test/test_rake_file_utils.rb +0 -305
  125. data/test/test_rake_ftp_file.rb +0 -59
  126. data/test/test_rake_functional.rb +0 -472
  127. data/test/test_rake_invocation_chain.rb +0 -52
  128. data/test/test_rake_makefile_loader.rb +0 -44
  129. data/test/test_rake_multi_task.rb +0 -59
  130. data/test/test_rake_name_space.rb +0 -43
  131. data/test/test_rake_package_task.rb +0 -79
  132. data/test/test_rake_path_map.rb +0 -157
  133. data/test/test_rake_path_map_explode.rb +0 -34
  134. data/test/test_rake_path_map_partial.rb +0 -18
  135. data/test/test_rake_pseudo_status.rb +0 -21
  136. data/test/test_rake_rake_test_loader.rb +0 -21
  137. data/test/test_rake_reduce_compat.rb +0 -30
  138. data/test/test_rake_require.rb +0 -40
  139. data/test/test_rake_rules.rb +0 -327
  140. data/test/test_rake_task.rb +0 -316
  141. data/test/test_rake_task_argument_parsing.rb +0 -103
  142. data/test/test_rake_task_arguments.rb +0 -88
  143. data/test/test_rake_task_lib.rb +0 -9
  144. data/test/test_rake_task_manager.rb +0 -157
  145. data/test/test_rake_task_manager_argument_resolution.rb +0 -19
  146. data/test/test_rake_task_with_arguments.rb +0 -162
  147. data/test/test_rake_test_task.rb +0 -120
  148. data/test/test_rake_thread_pool.rb +0 -146
  149. data/test/test_rake_top_level_functions.rb +0 -71
  150. data/test/test_rake_win32.rb +0 -72
  151. data/test/test_thread_history_display.rb +0 -91
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
4
  # Error indicating an ill-formed task declaration.
@@ -1,30 +1,43 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
- ####################################################################
4
+ ##
4
5
  # TaskArguments manage the arguments passed to a task.
5
6
  #
6
7
  class TaskArguments
7
8
  include Enumerable
8
9
 
10
+ # Argument names
9
11
  attr_reader :names
10
12
 
11
- # Create a TaskArgument object with a list of named arguments
12
- # (given by :names) and a set of associated values (given by
13
- # :values). :parent is the parent argument object.
13
+ # Create a TaskArgument object with a list of argument +names+ and a set
14
+ # of associated +values+. +parent+ is the parent argument object.
14
15
  def initialize(names, values, parent=nil)
15
16
  @names = names
16
17
  @parent = parent
17
18
  @hash = {}
19
+ @values = values
18
20
  names.each_with_index { |name, i|
19
- @hash[name.to_sym] = values[i] unless values[i].nil?
21
+ next if values[i].nil? || values[i] == ""
22
+ @hash[name.to_sym] = values[i]
20
23
  }
21
24
  end
22
25
 
26
+ # Retrieve the complete array of sequential values
27
+ def to_a
28
+ @values.dup
29
+ end
30
+
31
+ # Retrieve the list of values not associated with named arguments
32
+ def extras
33
+ @values[@names.length..-1] || []
34
+ end
35
+
23
36
  # Create a new argument scope using the prerequisite argument
24
37
  # names.
25
38
  def new_scope(names)
26
- values = names.collect { |n| self[n] }
27
- self.class.new(names, values, self)
39
+ values = names.map { |n| self[n] }
40
+ self.class.new(names, values + extras, self)
28
41
  end
29
42
 
30
43
  # Find an argument value by name or index.
@@ -39,33 +52,51 @@ module Rake
39
52
  @hash = defaults.merge(@hash)
40
53
  end
41
54
 
55
+ # Enumerates the arguments and their values
42
56
  def each(&block)
43
57
  @hash.each(&block)
44
58
  end
45
59
 
60
+ # Extracts the argument values at +keys+
46
61
  def values_at(*keys)
47
62
  keys.map { |k| lookup(k) }
48
63
  end
49
64
 
65
+ # Returns the value of the given argument via method_missing
50
66
  def method_missing(sym, *args)
51
67
  lookup(sym.to_sym)
52
68
  end
53
69
 
70
+ # Returns a Hash of arguments and their values
54
71
  def to_hash
55
- @hash
72
+ @hash.dup
73
+ end
74
+
75
+ def to_s # :nodoc:
76
+ inspect
77
+ end
78
+
79
+ def inspect # :nodoc:
80
+ inspection = @hash.map do |k,v|
81
+ "#{k.to_s}: #{v.to_s}"
82
+ end.join(", ")
83
+
84
+ "#<#{self.class} #{inspection}>"
56
85
  end
57
86
 
58
- def to_s
59
- @hash.inspect
87
+ # Returns true if +key+ is one of the arguments
88
+ def has_key?(key)
89
+ @hash.has_key?(key)
60
90
  end
91
+ alias key? has_key?
61
92
 
62
- def inspect
63
- to_s
93
+ def fetch(*args, &block)
94
+ @hash.fetch(*args, &block)
64
95
  end
65
96
 
66
97
  protected
67
98
 
68
- def lookup(name)
99
+ def lookup(name) # :nodoc:
69
100
  if @hash.has_key?(name)
70
101
  @hash[name]
71
102
  elsif @parent
@@ -74,5 +105,5 @@ module Rake
74
105
  end
75
106
  end
76
107
 
77
- EMPTY_TASK_ARGS = TaskArguments.new([], [])
108
+ EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
78
109
  end
@@ -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,10 +56,29 @@ 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
@@ -80,7 +109,7 @@ module Rake
80
109
  else
81
110
  arg_names = args
82
111
  end
83
- [task_name, arg_names, []]
112
+ [task_name, arg_names, [], nil]
84
113
  end
85
114
  private :resolve_args_without_dependencies
86
115
 
@@ -93,19 +122,22 @@ module Rake
93
122
  # task :t, [a] => [:d]
94
123
  #
95
124
  def resolve_args_with_dependencies(args, hash) # :nodoc:
96
- fail "Task Argument Error" if hash.size != 1
97
- key, value = hash.map { |k, v| [k,v] }.first
125
+ fail "Task Argument Error" if
126
+ hash.size != 1 &&
127
+ (hash.size != 2 || !hash.key?(:order_only))
128
+ order_only = hash.delete(:order_only)
129
+ key, value = hash.map { |k, v| [k, v] }.first
98
130
  if args.empty?
99
131
  task_name = key
100
132
  arg_names = []
101
- deps = value
133
+ deps = value || []
102
134
  else
103
135
  task_name = args.shift
104
136
  arg_names = key
105
137
  deps = value
106
138
  end
107
139
  deps = [deps] unless deps.respond_to?(:to_ary)
108
- [task_name, arg_names, deps]
140
+ [task_name, arg_names, deps, order_only]
109
141
  end
110
142
  private :resolve_args_with_dependencies
111
143
 
@@ -116,9 +148,10 @@ module Rake
116
148
  def enhance_with_matching_rule(task_name, level=0)
117
149
  fail Rake::RuleRecursionOverflowError,
118
150
  "Rule Recursion Too Deep" if level >= 16
119
- @rules.each do |pattern, extensions, block|
120
- if pattern.match(task_name)
121
- task = attempt_rule(task_name, extensions, block, level)
151
+ @rules.each do |pattern, args, extensions, order_only, block|
152
+ if pattern && pattern.match(task_name)
153
+ task = attempt_rule(task_name, pattern, args, extensions, block, level)
154
+ task | order_only unless order_only.nil?
122
155
  return task if task
123
156
  end
124
157
  end
@@ -136,7 +169,7 @@ module Rake
136
169
  # List of all the tasks defined in the given scope (and its
137
170
  # sub-scopes).
138
171
  def tasks_in_scope(scope)
139
- prefix = scope.join(":")
172
+ prefix = scope.path
140
173
  tasks.select { |t|
141
174
  /^#{prefix}:/ =~ t.name
142
175
  }
@@ -157,11 +190,11 @@ module Rake
157
190
  initial_scope ||= @scope
158
191
  task_name = task_name.to_s
159
192
  if task_name =~ /^rake:/
160
- scopes = []
161
- task_name = task_name.sub(/^rake:/, '')
193
+ scopes = Scope.make
194
+ task_name = task_name.sub(/^rake:/, "")
162
195
  elsif task_name =~ /^(\^+)/
163
- scopes = initial_scope[0, initial_scope.size - $1.size]
164
- task_name = task_name.sub(/^(\^+)/, '')
196
+ scopes = initial_scope.trim($1.size)
197
+ task_name = task_name.sub(/^(\^+)/, "")
165
198
  else
166
199
  scopes = initial_scope
167
200
  end
@@ -170,12 +203,12 @@ module Rake
170
203
 
171
204
  # Lookup the task name
172
205
  def lookup_in_scope(name, scope)
173
- n = scope.size
174
- while n >= 0
175
- tn = (scope[0,n] + [name]).join(':')
206
+ loop do
207
+ tn = scope.path_with_task_name(name)
176
208
  task = @tasks[tn]
177
209
  return task if task
178
- n -= 1
210
+ break if scope.empty?
211
+ scope = scope.tail
179
212
  end
180
213
  nil
181
214
  end
@@ -184,19 +217,19 @@ module Rake
184
217
  # Return the list of scope names currently active in the task
185
218
  # manager.
186
219
  def current_scope
187
- @scope.dup
220
+ @scope
188
221
  end
189
222
 
190
223
  # Evaluate the block in a nested namespace named +name+. Create
191
224
  # an anonymous namespace if +name+ is nil.
192
225
  def in_namespace(name)
193
226
  name ||= generate_name
194
- @scope.push(name)
227
+ @scope = Scope.new(name, @scope)
195
228
  ns = NameSpace.new(self, @scope)
196
229
  yield(ns)
197
230
  ns
198
231
  ensure
199
- @scope.pop
232
+ @scope = @scope.tail
200
233
  end
201
234
 
202
235
  private
@@ -213,7 +246,7 @@ module Rake
213
246
  locations = caller
214
247
  i = 0
215
248
  while locations[i]
216
- return locations[i+1] if locations[i] =~ /rake\/dsl_definition.rb/
249
+ return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
217
250
  i += 1
218
251
  end
219
252
  nil
@@ -226,19 +259,20 @@ module Rake
226
259
  "_anon_#{@seed}"
227
260
  end
228
261
 
229
- def trace_rule(level, message)
230
- options.trace_output.puts "#{" "*level}#{message}" if Rake.application.options.trace_rules
262
+ def trace_rule(level, message) # :nodoc:
263
+ options.trace_output.puts "#{" " * level}#{message}" if
264
+ Rake.application.options.trace_rules
231
265
  end
232
266
 
233
267
  # Attempt to create a rule given the list of prerequisites.
234
- def attempt_rule(task_name, extensions, block, level)
235
- sources = make_sources(task_name, extensions)
236
- prereqs = sources.collect { |source|
268
+ def attempt_rule(task_name, task_pattern, args, extensions, block, level)
269
+ sources = make_sources(task_name, task_pattern, extensions)
270
+ prereqs = sources.map { |source|
237
271
  trace_rule level, "Attempting Rule #{task_name} => #{source}"
238
272
  if File.exist?(source) || Rake::Task.task_defined?(source)
239
273
  trace_rule level, "(#{task_name} => #{source} ... EXIST)"
240
274
  source
241
- elsif parent = enhance_with_matching_rule(source, level+1)
275
+ elsif parent = enhance_with_matching_rule(source, level + 1)
242
276
  trace_rule level, "(#{task_name} => #{source} ... ENHANCE)"
243
277
  parent.name
244
278
  else
@@ -246,25 +280,26 @@ module Rake
246
280
  return nil
247
281
  end
248
282
  }
249
- task = FileTask.define_task({task_name => prereqs}, &block)
283
+ task = FileTask.define_task(task_name, { args => prereqs }, &block)
250
284
  task.sources = prereqs
251
285
  task
252
286
  end
253
287
 
254
288
  # Make a list of sources from the list of file name extensions /
255
289
  # translation procs.
256
- def make_sources(task_name, extensions)
257
- result = extensions.collect { |ext|
290
+ def make_sources(task_name, task_pattern, extensions)
291
+ result = extensions.map { |ext|
258
292
  case ext
259
293
  when /%/
260
294
  task_name.pathmap(ext)
261
295
  when %r{/}
262
296
  ext
263
297
  when /^\./
264
- task_name.ext(ext)
298
+ source = task_name.sub(task_pattern, ext)
299
+ source == ext ? task_name.ext(ext) : source
265
300
  when String
266
301
  ext
267
- when Proc
302
+ when Proc, Method
268
303
  if ext.arity == 1
269
304
  ext.call(task_name)
270
305
  else
@@ -277,9 +312,6 @@ module Rake
277
312
  result.flatten
278
313
  end
279
314
 
280
-
281
- private
282
-
283
315
  # Return the current description, clearing it in the process.
284
316
  def get_description(task)
285
317
  desc = @last_description
@@ -288,7 +320,7 @@ module Rake
288
320
  end
289
321
 
290
322
  class << self
291
- attr_accessor :record_task_metadata
323
+ attr_accessor :record_task_metadata # :nodoc:
292
324
  TaskManager.record_task_metadata = false
293
325
  end
294
326
  end
@@ -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
@@ -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,22 +90,44 @@ 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}" do |ok, status|
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|
100
118
  if !ok && status.respond_to?(:signaled?) && status.signaled?
101
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
102
131
  end
103
132
  end
104
133
  end
@@ -107,66 +136,57 @@ module Rake
107
136
  end
108
137
 
109
138
  def option_list # :nodoc:
110
- (ENV['TESTOPTS'] ||
111
- ENV['TESTOPT'] ||
112
- ENV['TEST_OPTS'] ||
113
- ENV['TEST_OPT'] ||
139
+ (ENV["TESTOPTS"] ||
140
+ ENV["TESTOPT"] ||
141
+ ENV["TEST_OPTS"] ||
142
+ ENV["TEST_OPT"] ||
114
143
  @options ||
115
144
  "")
116
145
  end
117
146
 
118
- def ruby_opts_string
147
+ def ruby_opts_string # :nodoc:
119
148
  opts = @ruby_opts.dup
120
- opts.unshift( "-I\"#{lib_path}\"" ) unless @libs.empty?
121
- opts.unshift( "-w" ) if @warning
149
+ opts.unshift("-I\"#{lib_path}\"") unless @libs.empty?
150
+ opts.unshift("-w") if @warning
122
151
  opts.join(" ")
123
152
  end
124
153
 
125
- def lib_path
154
+ def lib_path # :nodoc:
126
155
  @libs.join(File::PATH_SEPARATOR)
127
156
  end
128
157
 
129
- def file_list_string
130
- file_list.collect { |fn| "\"#{fn}\"" }.join(' ')
158
+ def file_list_string # :nodoc:
159
+ file_list.map { |fn| "\"#{fn}\"" }.join(" ")
131
160
  end
132
161
 
133
162
  def file_list # :nodoc:
134
- if ENV['TEST']
135
- FileList[ ENV['TEST'] ]
163
+ if ENV["TEST"]
164
+ FileList[ENV["TEST"]]
136
165
  else
137
166
  result = []
138
167
  result += @test_files.to_a if @test_files
139
- result << @pattern if @pattern
168
+ result += FileList[@pattern].to_a if @pattern
140
169
  result
141
170
  end
142
171
  end
143
172
 
144
- def fix # :nodoc:
145
- case ruby_version
146
- when '1.8.2'
147
- "\"#{find_file 'rake/ruby182_test_unit_fix'}\""
148
- else
149
- nil
150
- end || ''
151
- end
152
-
153
- def ruby_version
173
+ def ruby_version # :nodoc:
154
174
  RUBY_VERSION
155
175
  end
156
176
 
157
- def run_code
177
+ def run_code # :nodoc:
158
178
  case @loader
159
179
  when :direct
160
180
  "-e \"ARGV.each{|f| require f}\""
161
181
  when :testrb
162
- "-S testrb #{fix}"
182
+ "-S testrb"
163
183
  when :rake
164
- "-I\"#{rake_lib_dir}\" \"#{rake_loader}\""
184
+ "#{rake_include_arg} \"#{rake_loader}\""
165
185
  end
166
186
  end
167
187
 
168
188
  def rake_loader # :nodoc:
169
- find_file('rake/rake_test_loader') or
189
+ find_file("rake/rake_test_loader") or
170
190
  fail "unable to find rake test loader"
171
191
  end
172
192
 
@@ -178,8 +198,17 @@ module Rake
178
198
  nil
179
199
  end
180
200
 
201
+ def rake_include_arg # :nodoc:
202
+ spec = Gem.loaded_specs["rake"]
203
+ if spec.respond_to?(:default_gem?) && spec.default_gem?
204
+ ""
205
+ else
206
+ "-I\"#{rake_lib_dir}\""
207
+ end
208
+ end
209
+
181
210
  def rake_lib_dir # :nodoc:
182
- find_dir('rake') or
211
+ find_dir("rake") or
183
212
  fail "unable to find rake lib"
184
213
  end
185
214