diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 39ee5e191..7c487d8b1 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -179,6 +179,12 @@ def thread_pool # :nodoc: # Invokes a task with arguments that are extracted from +task_string+ def invoke_task(task_string) # :nodoc: name, args = parse_task_string(task_string) + + if name.end_with?('?') && !lookup(name) + name = name[0..-2] + return unless lookup(name) + end + t = self[name] t.invoke(*args) end diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index e661a3c3b..9e4ca9334 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -502,6 +502,29 @@ def test_good_run assert_equal "DEFAULT\n", out end + def test_safe_run + ran = false + existing_ran = false + + @app.options.silent = true + + @app.instance_eval do + intern(Rake::Task, "default").enhance { ran = true } + intern(Rake::Task, "existing?").enhance { existing_ran = true } + end + + rakefile_default + + out, err = capture_output do + @app.run %w[--rakelib="" default existing? missing?] + end + + assert ran + assert existing_ran + assert_empty err + assert_equal "DEFAULT\n", out + end + def test_display_task_run ran = false @app.last_description = "COMMENT"