Skip to content

Commit

Permalink
new --reduce-compat option removes Module#const_missing and Deprecate…
Browse files Browse the repository at this point in the history
…dObjectDSL
  • Loading branch information
quix committed Aug 1, 2011
1 parent e16aae7 commit c150beb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bin/rake
Expand Up @@ -28,6 +28,10 @@ begin
rescue LoadError
end

module Rake
REDUCE_COMPAT = true if ARGV.include?("--reduce-compat")
end

require 'rake'

Rake.application.run
5 changes: 5 additions & 0 deletions lib/rake/application.rb
Expand Up @@ -349,6 +349,11 @@ def standard_rake_options
# HACK Use File::PATH_SEPARATOR
lambda { |value| options.rakelib = value.split(':') }
],
['--reduce-compat', "Remove DSL in Object; remove Module#const_missing which defines ::Task etc.",
# Load-time option.
# Handled in bin/rake where Rake::REDUCE_COMPAT is defined (or not).
lambda { |_| }
],
['--require', '-r MODULE', "Require MODULE before executing rakefile.",
lambda { |value|
begin
Expand Down
4 changes: 2 additions & 2 deletions lib/rake/dsl_definition.rb
Expand Up @@ -165,10 +165,10 @@ def #{name}(*args, &block)
private :#{name}
}, __FILE__, line
end
end
end unless defined? Rake::REDUCE_COMPAT

extend FileUtilsExt
end

self.extend Rake::DSL
include Rake::DeprecatedObjectDSL
include Rake::DeprecatedObjectDSL unless defined? Rake::REDUCE_COMPAT
2 changes: 1 addition & 1 deletion lib/rake/ext/module.rb
Expand Up @@ -36,4 +36,4 @@ def const_missing(const_name)
rake_original_const_missing(const_name)
end
end
end
end unless defined? Rake::REDUCE_COMPAT
65 changes: 65 additions & 0 deletions test/test_rake_reduce_compat.rb
@@ -0,0 +1,65 @@
require File.expand_path('../helper', __FILE__)
require 'open3'

class TestRakeReduceCompat < Rake::TestCase
# TODO: factor out similar code in test_rake_functional.rb
def rake(*args)
lib = File.join(@orig_PWD, "lib")
bin_rake = File.join(@orig_PWD, "bin", "rake")
Open3.popen3(RUBY, "-I", lib, bin_rake, *args) { |_, out, _, _| out.read }
end

def invoke_normal(task_name)
rake task_name.to_s
end

def invoke_reduce_compat(task_name)
rake "--reduce-compat", task_name.to_s
end

def test_no_deprecated_dsl
rakefile %q{
task :check_task do
Module.new { p defined?(task) }
end
task :check_file do
Module.new { p defined?(file) }
end
}

assert_equal %{"method"}, invoke_normal(:check_task).chomp
assert_equal %{"method"}, invoke_normal(:check_file).chomp

assert_equal "nil", invoke_reduce_compat(:check_task).chomp
assert_equal "nil", invoke_reduce_compat(:check_file).chomp
end

def test_no_classic_namespace
rakefile %q{
task :check_task do
begin
Task
print "present"
rescue NameError
print "absent"
end
end
task :check_file_task do
begin
FileTask
print "present"
rescue NameError
print "absent"
end
end
}

assert_equal "present", invoke_normal(:check_task)
assert_equal "present", invoke_normal(:check_file_task)

assert_equal "absent", invoke_reduce_compat(:check_task)
assert_equal "absent", invoke_reduce_compat(:check_file_task)
end
end

0 comments on commit c150beb

Please sign in to comment.