Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed argument specification to use task command rather than desc c…

…ommand"

git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@621 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information...
commit 32fef525079dbbad3e1df1aeb23692f53401394e 1 parent 8e05fcd
jimweirich authored
View
33 Rakefile
@@ -293,15 +293,16 @@ end
task :noop
#plugin "release_manager"
-desc "[rel, reuse, reltest] Make a new release"
-task :release => [
- :prerelease,
- :clobber,
- :test_all,
- :update_version,
- :package,
- :tag] do
-
+desc "Make a new release"
+task :release, :rel, :reuse, :reltest,
+ :needs => [
+ :prerelease,
+ :clobber,
+ :test_all,
+ :update_version,
+ :package,
+ :tag
+ ] do
announce
announce "**************************************************************"
announce "* Release #{$package_version} Complete."
@@ -311,8 +312,7 @@ task :release => [
end
# Validate that everything is ready to go for a release.
-desc "[rel, reuse, reltest]"
-task :prerelease do |t, rel, reuse, reltest|
+task :prerelease, :rel, :reuse, :reltest do |t, rel, reuse, reltest|
$package_version = rel
announce
announce "**************************************************************"
@@ -345,8 +345,8 @@ task :prerelease do |t, rel, reuse, reltest|
end
end
-desc "[rel, reuse, reltest]"
-task :update_version => [:prerelease] do |t, rel, reuse, reltest|
+task :update_version, :rel, :reuse, :reltest,
+ :needs => [:prerelease] do |t, rel, reuse, reltest|
if rel == CURRENT_VERSION
announce "No version change ... skipping version update"
else
@@ -371,15 +371,16 @@ task :update_version => [:prerelease] do |t, rel, reuse, reltest|
end
end
-desc "[rel, reuse, reltest] Tag all the CVS files with the latest release number (REL=x.y.z)"
-task :tag => [:prerelease] do |t, rel, reuse, reltest|
+desc "Tag all the CVS files with the latest release number (REL=x.y.z)"
+task :tag, :rel, :reuse, :reltest,
+ :needs => [:prerelease] do |t, rel, reuse, reltest|
reltag = "REL_#{rel.gsub(/\./, '_')}"
reltag << reuse.gsub(/\./, '_') if reuse
announce "Tagging Repository with [#{reltag}]"
if reltest
announce "Release Task Testing, skipping CVS tagging"
else
- sh %{svn copy svn+ssh://rubyforge.org/var/svn/rake/trunk svn+ssh://rubyforge.org/var/svn/rake/tags/#{reltag} -m 'Commiting release #{reltag}'}
+ sh %{svn copy svn+ssh://rubyforge.org/var/svn/rake/trunk svn+ssh://rubyforge.org/var/svn/rake/tags/#{reltag} -m 'Commiting release #{reltag}'} ###'
end
end
View
117 lib/rake.rb
@@ -29,7 +29,7 @@
# as a library via a require statement, but it can be distributed
# independently as an application.
-RAKEVERSION = '0.7.99.3'
+RAKEVERSION = '0.7.99.4'
require 'rbconfig'
require 'ftools'
@@ -208,7 +208,7 @@ def pathmap(spec=nil, &block)
when '%x'
result << $1 if self =~ /[^\/](\.[^.]+)$/
when '%X'
- if self =~ /^(.+[^\/])(\.[^.]+)$/
+ if self =~ /^(.*[^\/])(\.[^.]+)$/
result << $1
else
result << self
@@ -289,11 +289,10 @@ class TaskArguments
def initialize(names, values, parent=nil)
@names = names
- @values = values
@parent = parent
@hash = {}
names.each_with_index { |name, i|
- @hash[name.to_s] = @values[i]
+ @hash[name.to_sym] = values[i]
}
end
@@ -306,33 +305,23 @@ def new_scope(names)
# Find an argument value by name or index.
def [](index)
- case index
- when Integer
- @values[index]
- else
- lookup(index.to_s)
- end
- end
-
- # Compare to an array
- def ==(other)
- to_ary == other
- end
-
- def to_ary
- @values
+ lookup(index.to_sym)
end
def each(&block)
- @values.each(&block)
+ @hash.each(&block)
end
def method_missing(sym, *args, &block)
- lookup(sym.to_s)
+ lookup(sym.to_sym)
+ end
+
+ def to_hash
+ @hash
end
def to_s
- "[" + @values.collect { |v| v.inspect }.join(', ') + "]"
+ @hash.inspect
end
def inspect
@@ -344,10 +333,10 @@ def inspect
def lookup(name)
if @hash.has_key?(name)
@hash[name]
- elsif ENV.has_key?(name)
- ENV[name]
- elsif ENV.has_key?(name.upcase)
- ENV[name.upcase]
+ elsif ENV.has_key?(name.to_s)
+ ENV[name.to_s]
+ elsif ENV.has_key?(name.to_s.upcase)
+ ENV[name.to_s.upcase]
elsif @parent
@parent.lookup(name)
end
@@ -575,13 +564,7 @@ def timestamp
# argument list (enclosed brackets) and an optional comment.
def add_description(description)
return if ! description
- if description =~ %r{\A\s*(\[([^\]]*)\])\s*(.*)\Z}m
- arg_string = $2
- comment = $3.strip
- else
- comment = description.strip
- end
- set_arg_names(arg_string) if arg_string
+ comment = description.strip
add_comment(comment) if comment && ! comment.empty?
end
@@ -604,17 +587,14 @@ def add_comment(comment)
else
@comment = @full_comment
end
-# if @comment.length > 50
-# @comment = @comment[0, 47] + "..."
-# end
end
private :add_comment
- # Set the names of the arguments for this task.
- def set_arg_names(arg_string)
- @arg_names = arg_string.split(',').collect { |n| n.strip }
+ # Set the names of the arguments for this task. +args+ should be
+ # an array of symbols, one for each argument name.
+ def set_arg_names(args)
+ @arg_names = args.map { |a| a.to_sym }
end
- private :set_arg_names
# Return a string describing the internal state of a task. Useful for
# debugging.
@@ -668,13 +648,13 @@ def task_defined?(task_name)
# Define a task given +args+ and an option block. If a rule with the
# given name already exists, the prerequisites and actions are added to
# the existing task. Returns the defined task.
- def define_task(args, &block)
- Rake.application.define_task(self, args, &block)
+ def define_task(*args, &block)
+ Rake.application.define_task(self, *args, &block)
end
# Define a rule for synthesizing tasks.
- def create_rule(args, &block)
- Rake.application.create_rule(args, &block)
+ def create_rule(*args, &block)
+ Rake.application.create_rule(*args, &block)
end
# Apply the scope to the task name according to the rules for
@@ -775,8 +755,8 @@ def invoke_prerequisites(args, invocation_chain)
# rm_rf "html"
# end
#
-def task(args, &block)
- Rake::Task.define_task(args, &block)
+def task(*args, &block)
+ Rake::Task.define_task(*args, &block)
end
@@ -849,8 +829,8 @@ def namespace(name=nil, &block)
# sh %{cc -o #{t.name} #{t.source}}
# end
#
-def rule(args, &block)
- Rake::Task.create_rule(args, &block)
+def rule(*args, &block)
+ Rake::Task.create_rule(*args, &block)
end
# Describe the next rake task.
@@ -1166,7 +1146,7 @@ class FileList
# List of array methods (that are not in +Object+) that need to be
# delegated.
- ARRAY_METHODS = Array.instance_methods - Object.instance_methods
+ ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
# List of additional methods that must be delegated.
MUST_DEFINE = %w[to_a inspect]
@@ -1621,18 +1601,19 @@ def initialize
@last_description = nil
end
- def create_rule(args, &block)
- pattern, deps = resolve_args(args)
+ def create_rule(*args, &block)
+ pattern, arg_names, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
@rules << [pattern, deps, block]
end
- def define_task(task_class, args, &block)
- task_name, deps = resolve_args(args)
+ def define_task(task_class, *args, &block)
+ task_name, arg_names, deps = resolve_args(args)
task_name = task_class.scope_name(@scope, task_name)
deps = [deps] unless deps.respond_to?(:to_ary)
deps = deps.collect {|d| d.to_s }
task = intern(task_class, task_name)
+ task.set_arg_names(arg_names) unless arg_names.empty?
task.add_description(@last_description)
@last_description = nil
task.enhance(deps, &block)
@@ -1659,20 +1640,25 @@ def synthesize_file_task(task_name)
define_task(Rake::FileTask, task_name)
end
- # Resolve the arguments for a task/rule.
+ # Resolve the arguments for a task/rule. Returns a triplet of
+ # [task_name, arg_list, dependencies_list].
+ # TODO: Rework this to handle arguments
def resolve_args(args)
- case args
- when Hash
- fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
- fail "No Task Name Given" if args.size < 1
- task_name = args.keys[0]
- deps = args[task_name]
- deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
- else
- task_name = args
- deps = []
+ task_name = args.shift
+ arg_names = args #.map { |a| a.to_sym }
+ needs = []
+ if task_name.is_a?(Hash)
+ hash = task_name
+ task_name = hash.keys[0]
+ needs = hash[task_name]
+ end
+ if arg_names.last.is_a?(Hash)
+ hash = arg_names.pop
+ needs = hash[:needs]
+ fail "Unrecognized keys in task hash: #{hash.keys.inspect}" if hash.size > 1
end
- [task_name, deps]
+ needs = [needs] unless needs.respond_to?(:to_ary)
+ [task_name, arg_names, needs]
end
# If a rule can be found that matches the task name, enhance the
@@ -2132,7 +2118,6 @@ def handle_options
$silent = options.silent
end
rescue NoMethodError => ex
- puts "DBG: RESCUING xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
raise GetoptLong::InvalidOption, "While parsing options, error = #{ex.class}:#{ex.message}"
end
View
4 test/test_application.rb
@@ -258,7 +258,9 @@ def test_default_options
def test_bad_options
assert_raise GetoptLong::InvalidOption do
- flags('--bad', '-t') do |opts|
+ capture_stderr do
+ flags('--bad', '-t') do |opts|
+ end
end
end
end
View
7 test/test_filelist.rb
@@ -18,6 +18,13 @@ def teardown
FileUtils.rm_rf("testdata")
end
+ def test_delgating_methods_do_not_include_to_a_or_to_ary
+ assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
+ assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
+ assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
+ assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
+ end
+
def test_create
fl = FileList.new
assert_equal 0, fl.size
View
5 test/test_pathmap.rb
@@ -60,6 +60,11 @@ def test_X_returns_everything_but_extension
assert_equal "abc", "abc".pathmap("%X")
assert_equal "abc", "abc.rb".pathmap("%X")
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
+ assert_equal "ab.xyz", "ab.xyz.rb".pathmap("%X")
+ assert_equal "a.xyz", "a.xyz.rb".pathmap("%X")
+ assert_equal "abc", "abc.rb".pathmap("%X")
+ assert_equal "ab", "ab.rb".pathmap("%X")
+ assert_equal "a", "a.rb".pathmap("%X")
assert_equal ".depends", ".depends".pathmap("%X")
assert_equal "a/dir/.depends", "a/dir/.depends".pathmap("%X")
assert_equal "/.depends", "/.depends".pathmap("%X")
View
35 test/test_task_arguments.rb
@@ -5,31 +5,30 @@
######################################################################
class TestTaskArguments < Test::Unit::TestCase
- def test_empty_arg_list_is_empty
- ta = Rake::TaskArguments.new([], [])
- assert_equal [], ta
+ def teardown
+ ENV.delete('rev')
+ ENV.delete('VER')
end
- def test_one_arg_equals_array
- ta = Rake::TaskArguments.new([], [:one])
- assert_equal [:one], ta
- assert_equal :one, ta[0]
+ def test_empty_arg_list_is_empty
+ ta = Rake::TaskArguments.new([], [])
+ assert_equal({}, ta.to_hash)
end
def test_multiple_values_in_args
- ta = Rake::TaskArguments.new([], [:one, :two, :three])
- assert_equal [:one, :two, :three], ta
+ ta = Rake::TaskArguments.new([:a, :b, :c], [:one, :two, :three])
+ assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash)
end
def test_to_s
- ta = Rake::TaskArguments.new([], [1, 2, 3])
- assert_equal "[1, 2, 3]", ta.to_s
- assert_equal "[1, 2, 3]", ta.inspect
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
+ assert_equal ta.to_hash.inspect, ta.to_s
+ assert_equal ta.to_hash.inspect, ta.inspect
end
def test_enumerable_behavior
- ta = Rake::TaskArguments.new([], [1, 2 ,3])
- assert_equal [10, 20, 30], ta.collect { |n| n * 10 }
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2 ,3])
+ assert_equal [10, 20, 30], ta.collect { |k,v| v * 10 }.sort
end
def test_named_args
@@ -51,12 +50,6 @@ def test_extra_names_are_nil
assert_nil ta.cc
end
- def test_unamed_args_are_referenced_by_index
- ta = Rake::TaskArguments.new(["aa"], [1, 2])
- assert_equal [1, 2], ta
- assert_equal 2, ta[1]
- end
-
def test_args_can_reference_env_values
ta = Rake::TaskArguments.new(["aa"], [1])
ENV['rev'] = "1.2"
@@ -68,7 +61,7 @@ def test_args_can_reference_env_values
def test_creating_new_argument_scopes
parent = Rake::TaskArguments.new(['p'], [1])
child = parent.new_scope(['c', 'p'])
- assert_equal [nil, 1], child
+ assert_equal({:c => nil, :p=>1}, child.to_hash)
assert_equal 1, child.p
assert_equal 1, child["p"]
assert_equal 1, child[:p]
View
238 test/test_tasks.rb
@@ -6,10 +6,20 @@
require 'test/filecreation'
require 'test/capture_stdout'
+
+module Interning
+ private
+
+ def intern(name, *args)
+ Rake.application.define_task(Rake::Task, name, *args)
+ end
+end
+
######################################################################
class TestTask < Test::Unit::TestCase
include CaptureStdout
include Rake
+ include Interning
def setup
Task.clear
@@ -154,20 +164,112 @@ def test_investigation_output
assert_match(/pre-requisites:\s*--t2/, out)
end
- def test_tasks_can_access_arguments
- t = intern(:t).enhance do |t, args|
- assert_equal [1, 2, 3], args
+
+ def test_extended_comments
+ desc %{
+ This is a comment.
+
+ And this is the extended comment.
+ name -- Name of task to execute.
+ rev -- Software revision to use.
+ }
+ t = intern(:t, :name, :rev)
+ assert_equal "[name,rev]", t.arg_description
+ assert_equal "This is a comment.", t.comment
+ assert_match(/^\s*name -- Name/, t.full_comment)
+ assert_match(/^\s*rev -- Software/, t.full_comment)
+ assert_match(/\A\s*This is a comment\.$/, t.full_comment)
+ end
+
+ def test_multiple_comments
+ desc "line one"
+ t = intern(:t)
+ desc "line two"
+ intern(:t)
+ assert_equal "line one / line two", t.comment
+ end
+
+ def test_settable_comments
+ t = intern(:t)
+ t.comment = "HI"
+ assert_equal "HI", t.comment
+ end
+end
+
+######################################################################
+class TestTaskWithArguments < Test::Unit::TestCase
+ include CaptureStdout
+ include Rake
+ include Interning
+
+ def setup
+ Task.clear
+ end
+
+ def test_no_args_given
+ t = task :t
+ assert_equal [], t.arg_names
+ end
+
+ def test_args_given
+ t = task :t, :a, :b
+ assert_equal [:a, :b], t.arg_names
+ end
+
+ def test_name_and_needs
+ t = task(:t => [:pre])
+ assert_equal "t", t.name
+ assert_equal [], t.arg_names
+ assert_equal ["pre"], t.prerequisites
+ end
+
+ def test_name_and_explicit_needs
+ t = task(:t, :needs => [:pre])
+ assert_equal "t", t.name
+ assert_equal [], t.arg_names
+ assert_equal ["pre"], t.prerequisites
+ end
+
+ def test_name_args_and_explicit_needs
+ t = task(:t, :x, :y, :needs => [:pre])
+ assert_equal "t", t.name
+ assert_equal [:x, :y], t.arg_names
+ assert_equal ["pre"], t.prerequisites
+ end
+
+ def test_illegal_keys_in_task_name_hash
+ assert_raise RuntimeError do
+ t = task(:t, :x, :y => 1, :needs => [:pre])
+ end
+ end
+
+ def test_arg_list_is_empty_if_no_args_given
+ t = intern(:t).enhance do |tt, args|
+ assert_equal({}, args.to_hash)
+ end
+ t.invoke(1, 2, 3)
+ end
+
+ def test_tasks_can_access_arguments_as_hash
+ t = task :t, :a, :b, :c do |tt, args|
+ assert_equal({:a => 1, :b => 2, :c => 3}, args.to_hash)
+ assert_equal 1, args[:a]
+ assert_equal 2, args[:b]
+ assert_equal 3, args[:c]
+ assert_equal 1, args.a
+ assert_equal 2, args.b
+ assert_equal 3, args.c
end
t.invoke(1, 2, 3)
end
def test_actions_of_various_arity_are_ok_with_args
notes = []
- t = intern(:t).enhance do
+ t = intern(:t, :x).enhance do
notes << :a
end
- t.enhance do ||
- notes << :b
+ t.enhance do | |
+ notes << :b
end
t.enhance do |task|
notes << :c
@@ -176,22 +278,22 @@ def test_actions_of_various_arity_are_ok_with_args
t.enhance do |t2, args|
notes << :d
assert_equal t, t2
- assert_equal [1], args
+ assert_equal({:x => 1}, args.to_hash)
end
assert_nothing_raised do t.invoke(1) end
assert_equal [:a, :b, :c, :d], notes
end
def test_arguments_are_passed_to_block
- t = intern(:t).enhance { |t, args|
- assert_equal [1, 2], args
+ t = intern(:t, :a, :b).enhance { |tt, args|
+ assert_equal( { :a => 1, :b => 2 }, args.to_hash )
}
t.invoke(1, 2)
end
- def test_extra_parameters_are_nil
- t = intern(:t).enhance { |t, args|
- assert_equal [1, 2], args
+ def test_extra_parameters_are_ignored
+ t = intern(:t, :a).enhance { |tt, args|
+ assert_equal 1, args.a
assert_nil args[2]
}
t.invoke(1, 2)
@@ -199,14 +301,15 @@ def test_extra_parameters_are_nil
def test_arguments_are_passed_to_all_blocks
counter = 0
- t = intern(:t).enhance { |t, args|
- assert_equal [1], args
+ t = task :t, :a
+ task :t do |tt, args|
+ assert_equal 1, args.a
counter += 1
- }
- intern(:t).enhance { |t, args|
- assert_equal [1], args
+ end
+ task :t do |tt, args|
+ assert_equal 1, args.a
counter += 1
- }
+ end
t.invoke(1)
assert_equal 2, counter
end
@@ -216,117 +319,38 @@ def test_block_with_no_parameters_is_ok
t.invoke(1, 2)
end
- def test_descriptions_with_no_args
- desc "T"
- t = intern(:tt).enhance { }
- assert_equal "tt", t.name
- assert_nil t.arg_description
- assert_equal "T", t.comment
- end
-
def test_name_with_args
- desc "[a, b] T"
- t = intern(:tt)
+ desc "T"
+ t = intern(:tt, :a, :b)
assert_equal "tt", t.name
assert_equal "T", t.comment
assert_equal "[a,b]", t.arg_description
assert_equal "tt[a,b]", t.name_with_args
- assert_equal ["a", "b"],t.arg_names
- end
-
- def test_task_args_can_be_named
- desc "[aa,bb] T"
- t = intern(:tt).enhance { |t, args|
- assert_equal [1, 2], args
- assert_equal 1, args.aa
- }
- t.invoke(1, 2)
+ assert_equal [:a, :b],t.arg_names
end
- def xtest_named_args_are_passed_to_prereqs
+ def test_named_args_are_passed_to_prereqs
value = nil
- desc "[rev] pre"
- pre = intern(:pre).enhance { |t, rev| value = rev }
- desc "[name,rev] t"
- t = intern(:t).enhance([:pre])
+ pre = intern(:pre, :rev).enhance { |t, args| value = args.rev }
+ t = intern(:t, :name, :rev).enhance([:pre])
t.invoke("bill", "1.2")
assert_equal "1.2", value
end
def test_args_not_passed_if_no_prereq_names
- value = nil
- desc "pre"
pre = intern(:pre).enhance { |t, args|
- assert_equal [], args
+ assert_equal({}, args.to_hash)
assert_equal "bill", args.name
}
- desc "[name,rev] t"
- t = intern(:t).enhance([:pre])
+ t = intern(:t, :name, :rev).enhance([:pre])
t.invoke("bill", "1.2")
- assert_nil value
end
def test_args_not_passed_if_no_arg_names
- value = nil
- desc "[rev] pre"
- pre = intern(:pre).enhance { |t, args|
- assert_equal [nil], args
+ pre = intern(:pre, :rev).enhance { |t, args|
+ assert_equal({ :rev => nil }, args.to_hash)
}
- desc "t"
t = intern(:t).enhance([:pre])
t.invoke("bill", "1.2")
end
-
- def test_task_can_have_arg_names_but_no_comment
- desc "[a,b]"
- t = intern(:t)
- assert_equal "[a,b]", t.arg_description
- assert_nil t.comment
- assert_nil t.full_comment
- end
-
- def test_extended_comments
- desc %{
- [name, rev]
- This is a comment.
-
- And this is the extended comment.
- name -- Name of task to execute.
- rev -- Software revision to use.
- }
- t = intern(:t)
- assert_equal "[name,rev]", t.arg_description
- assert_equal "This is a comment.", t.comment
- assert_match(/^\s*name -- Name/, t.full_comment)
- assert_match(/^\s*rev -- Software/, t.full_comment)
- assert_match(/\A\s*This is a comment\.$/, t.full_comment)
- end
-
- def test_comments_below_limit_are_unchanged
- desc %{12345678901234567890123456789012345678901234567890}
- t = intern(:t)
- assert_equal "12345678901234567890123456789012345678901234567890", t.comment
- end
-
- def test_multiple_comments
- desc "line one"
- t = intern(:t)
- desc "line two"
- intern(:t)
- assert_equal "line one / line two", t.comment
- end
-
- def test_settable_comments
- t = intern(:t)
- t.comment = "HI"
- assert_equal "HI", t.comment
- end
-
- private
-
- def intern(name)
- Rake.application.define_task(Rake::Task,name)
- end
-
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.