Skip to content

Commit

Permalink
Added global DSL warning to list of warnings suppressed by --no-depre…
Browse files Browse the repository at this point in the history
…cate.
  • Loading branch information
jimweirich committed Jun 5, 2011
1 parent 0e6587e commit 23e79f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/rake/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ module DeprecatedObjectDSL
line = __LINE__+1
class_eval %{
def #{name}(*args, &block)
unless @rake_dsl_warning
$stderr.puts "WARNING: Global access to Rake DSL methods is deprecated. Please include"
$stderr.puts " ... Rake::DSL into classes and modules which use the Rake DSL methods."
@rake_dsl_warning = true
unless Rake.application.options.ignore_deprecate
unless @rake_dsl_warning
$stderr.puts "WARNING: Global access to Rake DSL methods is deprecated. Please include"
$stderr.puts " ... Rake::DSL into classes and modules which use the Rake DSL methods."
@rake_dsl_warning = true
end
$stderr.puts "WARNING: DSL method \#{self.class}##{name} called at \#{caller.first}"
end
$stderr.puts "WARNING: DSL method \#{self.class}##{name} called at \#{caller.first}"
Rake::DeprecatedObjectDSL::Commands.send(:#{name}, *args, &block)
end
end
private :#{name}
}, __FILE__, line
end
Expand Down
20 changes: 20 additions & 0 deletions test/test_rake_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

class TestRakeDsl < Rake::TestCase

def setup
super
Rake::Task.clear
end

def test_namespace_command
namespace "n" do
task "t"
Expand Down Expand Up @@ -50,4 +55,19 @@ def test_deprecated_object_dsl
assert_match(/Foo\#file/, err)
assert_match(/test_rake_dsl\.rb:\d+/, err)
end

def test_deprecated_object_dsl_with_suppressed_warnings
Rake.application.options.ignore_deprecate = true
out, err = capture_io do
Foo.new
Rake.application.invoke_task :foo_deprecated_a
end
assert_equal("ba", out)
refute_match(/deprecated/, err)
refute_match(/Foo\#task/, err)
refute_match(/Foo\#file/, err)
refute_match(/test_rake_dsl\.rb:\d+/, err)
ensure
Rake.application.options.ignore_deprecate = false
end
end

0 comments on commit 23e79f2

Please sign in to comment.