* test/rake*: Remove dependencies on flexmock and session gems.

[Ruby 1.9 - Bug #4987]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2011-07-23 05:38:50 +00:00
Родитель 12d9be6b72
Коммит c93ed570a2
11 изменённых файлов: 238 добавлений и 182 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Sat Jul 23 14:38:28 2011 Eric Hodel <drbrain@segment7.net>
* test/rake*: Remove dependencies on flexmock and session gems.
[Ruby 1.9 - Bug #4987]
Sat Jul 23 12:19:04 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (rb_check_id): take care of attrset ID created

Просмотреть файл

@ -1,15 +1,22 @@
require 'rubygems'
require 'minitest/unit'
require 'flexmock/test_unit_integration'
begin
gem 'minitest'
rescue Gem::LoadError
end
require 'minitest/autorun'
require 'rake'
require 'tmpdir'
require File.expand_path('../file_creation', __FILE__)
class Rake::TestCase < MiniTest::Unit::TestCase
include FlexMock::ArgumentTypes
include FlexMock::MockContainer
begin
require 'test/ruby/envutil'
rescue LoadError
# for ruby trunk
end
class Rake::TestCase < MiniTest::Unit::TestCase
include FileCreation
include Rake::DSL
@ -18,6 +25,8 @@ class Rake::TestCase < MiniTest::Unit::TestCase
include Rake::TaskManager
end
RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby
def setup
ARGV.clear
@ -43,11 +52,10 @@ class Rake::TestCase < MiniTest::Unit::TestCase
Rake.application = Rake::Application.new
Rake::TaskManager.record_task_metadata = true
RakeFileUtils.verbose_flag = false
end
def teardown
flexmock_teardown
Dir.chdir @orig_PWD
FileUtils.rm_rf @tempdir
@ -434,17 +442,6 @@ end
end
end
def rakefile_statusreturn
rakefile <<-STATUSRETURN
task :exit5 do
exit(5)
end
task :normal do
end
STATUSRETURN
end
def rakefile_unittest
rakefile '# Empty Rakefile for Unit Test'
@ -494,7 +491,3 @@ end
end
# workarounds for 1.8
$" << 'test/helper.rb'
Test::Unit.run = true if Test::Unit.respond_to? :run=

Просмотреть файл

@ -232,7 +232,9 @@ class TestRakeApplication < Rake::TestCase
def test_load_from_calculated_system_rakefile
rakefile_default
flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
def @app.standard_system_dir
"__STD_SYS_DIR__"
end
ENV['RAKE_SYSTEM'] = nil
@ -270,25 +272,28 @@ class TestRakeApplication < Rake::TestCase
end
def test_loading_imports
mock = flexmock("loader")
mock.should_receive(:load).with("x.dummy").once
loader = util_loader
@app.instance_eval do
add_loader("dummy", mock)
add_loader("dummy", loader)
add_import("x.dummy")
load_imports
end
# HACK no assertions
end
def test_building_imported_files_on_demand
mock = flexmock("loader")
mock.should_receive(:load).with("x.dummy").once
mock.should_receive(:make_dummy).with_no_args.once
loader = util_loader
@app.instance_eval do
intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
add_loader("dummy", mock)
intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
add_loader("dummy", loader)
add_import("x.dummy")
load_imports
end
# HACK no assertions
end
def test_handle_options_should_strip_options_from_ARGV
@ -399,5 +404,86 @@ class TestRakeApplication < Rake::TestCase
assert_match(/use 'b' instead/i, err)
assert_match(/at c$/i, err)
end
def test_standard_exception_handling_invalid_option
out, err = capture_io do
e = assert_raises SystemExit do
@app.standard_exception_handling do
raise OptionParser::InvalidOption, 'blah'
end
end
assert_equal 1, e.status
end
assert_empty out
assert_equal "invalid option: blah\n", err
end
def test_standard_exception_handling_other
out, err = capture_io do
e = assert_raises SystemExit do
@app.standard_exception_handling do
raise 'blah'
end
end
assert_equal 1, e.status
end
assert_empty out
assert_match "rake aborted!\n", err
assert_match "blah\n", err
end
def test_standard_exception_handling_system_exit
out, err = capture_io do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 0
end
end
assert_equal 0, e.status
end
assert_empty out
assert_empty err
end
def test_standard_exception_handling_system_exit_nonzero
out, err = capture_io do
e = assert_raises SystemExit do
@app.standard_exception_handling do
exit 5
end
end
assert_equal 5, e.status
end
assert_empty out
assert_empty err
end
def util_loader
loader = Object.new
loader.instance_variable_set :@load_called, false
def loader.load arg
raise 'called more than once' if @load_called
raise ArgumentError, arg unless arg == 'x.dummy'
@load_called = true
end
loader.instance_variable_set :@make_dummy_called, false
def loader.make_dummy
raise 'called more than once' if @make_dummy_called
@make_dummy_called = true
end
loader
end
end

Просмотреть файл

@ -119,33 +119,16 @@ class TestRakeFileUtils < Rake::TestCase
def test_sh
shellcommand
verbose(false) { sh %{#{FileUtils::RUBY} shellcommand.rb} }
verbose(false) { sh %{#{Rake::TestCase::RUBY} shellcommand.rb} }
assert true, "should not fail"
end
# If the :sh method is invoked directly from a test unit instance
# (under mini/test), the mini/test version of fail is invoked rather
# than the kernel version of fail. So we run :sh from within a
# non-test class to avoid the problem.
class Sh
include FileUtils
def run(*args)
sh(*args)
end
def self.run(*args)
new.run(*args)
end
def self.ruby(*args)
Sh.run(RUBY, *args)
end
end
def test_sh_with_a_single_string_argument
check_expansion
ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) {
sh %{#{FileUtils::RUBY} check_expansion.rb #{env_var} someval}
sh %{#{RUBY} check_expansion.rb #{env_var} someval}
}
end
@ -154,7 +137,7 @@ class TestRakeFileUtils < Rake::TestCase
ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) {
Sh.ruby 'check_no_expansion.rb', env_var, 'someval'
sh RUBY, 'check_no_expansion.rb', env_var, 'someval'
}
end
@ -162,7 +145,7 @@ class TestRakeFileUtils < Rake::TestCase
shellcommand
assert_raises(RuntimeError) {
verbose(false) { Sh.run %{#{FileUtils::RUBY} shellcommand.rb 1} }
verbose(false) { sh %{#{RUBY} shellcommand.rb 1} }
}
end
@ -171,12 +154,12 @@ class TestRakeFileUtils < Rake::TestCase
count = 0
verbose(false) {
sh(%{#{FileUtils::RUBY} shellcommand.rb}) do |ok, res|
sh(%{#{RUBY} shellcommand.rb}) do |ok, res|
assert(ok)
assert_equal 0, res.exitstatus
count += 1
end
sh(%{#{FileUtils::RUBY} shellcommand.rb 1}) do |ok, res|
sh(%{#{RUBY} shellcommand.rb 1}) do |ok, res|
assert(!ok)
assert_equal 1, res.exitstatus
count += 1
@ -241,8 +224,10 @@ class TestRakeFileUtils < Rake::TestCase
ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) {
replace_ruby {
ruby %{check_expansion.rb #{env_var} someval}
}
}
end
def test_ruby_with_multiple_arguments
@ -250,8 +235,10 @@ class TestRakeFileUtils < Rake::TestCase
ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) {
replace_ruby {
ruby 'check_no_expansion.rb', env_var, 'someval'
}
}
end
def test_split_all
@ -289,6 +276,16 @@ end
CHECK_EXPANSION
end
def replace_ruby
ruby = FileUtils::RUBY
FileUtils.send :remove_const, :RUBY
FileUtils.const_set :RUBY, RUBY
yield
ensure
FileUtils.send :remove_const, :RUBY
FileUtils.const_set:RUBY, ruby
end
def shellcommand
command 'shellcommand.rb', <<-SHELLCOMMAND
#!/usr/bin/env ruby

Просмотреть файл

@ -1,38 +1,6 @@
begin
old_verbose = $VERBOSE
$VERBOSE = nil
require 'session'
rescue LoadError
if File::ALT_SEPARATOR
puts "Unable to run functional tests on MS Windows. Skipping."
else
puts "Unable to run functional tests -- please run \"gem install session\""
end
ensure
$VERBOSE = old_verbose
end
if defined?(Session)
if File::ALT_SEPARATOR
puts "Unable to run functional tests on MS Windows. Skipping."
end
end
require File.expand_path('../helper', __FILE__)
require 'fileutils'
# Version 2.1.9 of session has a bug where the @debug instance
# variable is not initialized, causing warning messages. This snippet
# of code fixes that problem.
module Session
class AbstractSession
alias old_initialize initialize
def initialize(*args)
@debug = nil
old_initialize(*args)
end
end
end if defined? Session
require 'open3'
class TestRakeFunctional < Rake::TestCase
@ -59,16 +27,14 @@ class TestRakeFunctional < Rake::TestCase
rake
assert_match(/^DEFAULT$/, @out)
assert_status
end
def test_rake_error_on_bad_task
rakefile_default
rake "xyz"
rake '-t', 'xyz'
assert_match(/rake aborted/, @err)
assert_status(1)
end
def test_env_available_at_top_scope
@ -77,16 +43,14 @@ class TestRakeFunctional < Rake::TestCase
rake "TESTTOPSCOPE=1"
assert_match(/^TOPSCOPE$/, @out)
assert_status
end
def test_env_available_at_task_scope
rakefile_default
rake "TESTTASKSCOPE=1 task_scope"
rake 'TESTTASKSCOPE=1', 'task_scope'
assert_match(/^TASKSCOPE$/, @out)
assert_status
end
def test_multi_desc
@ -283,8 +247,6 @@ class TestRakeFunctional < Rake::TestCase
rake "--dry-run"
refute_match(/No such file/, @out)
assert_status
end
# Test for the trace/dry_run bug found by Brian Chandler
@ -298,7 +260,6 @@ class TestRakeFunctional < Rake::TestCase
rake "--trace"
refute_match(/No such file/, @out)
assert_status
end
def test_imports
@ -309,7 +270,6 @@ class TestRakeFunctional < Rake::TestCase
assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
"'dynamic_deps' file should exist"
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
assert_status
end
def test_rules_chaining_to_file_task
@ -319,7 +279,6 @@ class TestRakeFunctional < Rake::TestCase
assert File.exist?(File.join(@tempdir, 'play.app')),
"'play.app' file should exist"
assert_status
end
def test_file_creation_task
@ -335,7 +294,7 @@ class TestRakeFunctional < Rake::TestCase
def test_dash_f_with_no_arg_foils_rakefile_lookup
rakefile_rakelib
rake "-I rakelib -rtest1 -f"
rake '-I', 'rakelib', '-rtest1', '-f'
assert_match(/^TEST1$/, @out)
end
@ -343,8 +302,9 @@ class TestRakeFunctional < Rake::TestCase
def test_dot_rake_files_can_be_loaded_with_dash_r
rakefile_rakelib
rake "-I rakelib -rtest2 -f"
rake '-I', 'rakelib', '-rtest2', '-f'
assert_empty @err
assert_match(/^TEST2$/, @out)
end
@ -412,22 +372,6 @@ class TestRakeFunctional < Rake::TestCase
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
end
def test_rake_returns_status_error_values
rakefile_statusreturn
rake "exit5"
assert_status 5
end
def test_rake_returns_no_status_error_on_normal_exit
rakefile_statusreturn
rake "normal"
assert_status 0
end
def test_comment_before_task_acts_like_desc
rakefile_comments
@ -469,42 +413,38 @@ class TestRakeFunctional < Rake::TestCase
end
def test_file_list_is_requirable_separately
ruby "-rrake/file_list", "-e 'puts Rake::FileList[\"a\"].size'"
ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size'
assert_equal "1\n", @out
assert_equal 0, @status
end
private
# Run a shell Ruby command with command line options (using the
# default test options). Output is captured in @out, @err and
# @status.
# default test options). Output is captured in @out and @err
def ruby(*option_list)
run_ruby(@ruby_options + option_list)
end
# Run a command line rake with the give rake options. Default
# command line ruby options are included. Output is captured in
# @out, @err and @status.
# @out and @err
def rake(*rake_options)
run_ruby @ruby_options + [@rake_path] + rake_options
end
# Low level ruby command runner ...
def run_ruby(option_list)
shell = Session::Shell.new
command = "#{Gem.ruby} #{option_list.join ' '}"
puts "COMMAND: [#{command}]" if @verbose
@out, @err = shell.execute command
@status = shell.exit_status
puts "STATUS: [#{@status}]" if @verbose
puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list)
inn.close
@out = out.read
@err = err.read
puts "OUTPUT: [#{@out}]" if @verbose
puts "ERROR: [#{@err}]" if @verbose
puts "PWD: [#{Dir.pwd}]" if @verbose
shell.close
end
def assert_status(expected_status=0)
assert_equal expected_status, @status
end
end if defined?(Session)
end

Просмотреть файл

@ -208,10 +208,7 @@ class TestRakeTask < Rake::TestCase
b = task :b
c = task :c
faux_stamp = 100
flexmock(Time, :now => faux_stamp)
assert_equal faux_stamp, a.timestamp
assert_in_delta Time.now, a.timestamp, 0.1, 'computer too slow?'
end
def test_timestamp_returns_latest_prereq_timestamp
@ -219,12 +216,11 @@ class TestRakeTask < Rake::TestCase
b = task :b
c = task :c
faux_stamp = 100
flexmock(Time, :now => faux_stamp-10)
flexmock(b, :timestamp => faux_stamp - 1)
flexmock(c, :timestamp => faux_stamp)
now = Time.now
def b.timestamp() Time.now + 10 end
def c.timestamp() Time.now + 5 end
assert_equal faux_stamp, a.timestamp
assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
end
def test_investigation_output

Просмотреть файл

@ -51,38 +51,31 @@ class TestRakeTaskArgumentParsing < Rake::TestCase
end
def test_terminal_width_using_stty
app = Rake::Application.new
def @app.unix?() true end
def @app.dynamic_width_stty() 1235 end
def @app.dynamic_width_tput() 0 end
flexmock(app,
:unix? => true,
:dynamic_width_stty => 1235,
:dynamic_width_tput => 0)
assert_equal 1235, app.terminal_width
assert_equal 1235, @app.terminal_width
end
def test_terminal_width_using_tput
app = Rake::Application.new
flexmock(app,
:unix? => true,
:dynamic_width_stty => 0,
:dynamic_width_tput => 1236)
def @app.unix?() true end
def @app.dynamic_width_stty() 0 end
def @app.dynamic_width_tput() 1236 end
assert_equal 1236, app.terminal_width
assert_equal 1236, @app.terminal_width
end
def test_terminal_width_using_hardcoded_80
app = Rake::Application.new
flexmock(app, :unix? => false)
def @app.unix?() true end
assert_equal 80, app.terminal_width
assert_equal 80, @app.terminal_width
end
def test_terminal_width_with_failure
app = Rake::Application.new
flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
def @app.unix?() raise end
assert_equal 80, app.terminal_width
assert_equal 80, @app.terminal_width
end
def test_no_rakeopt

Просмотреть файл

@ -19,6 +19,14 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal @tm, t.application
end
def test_index
e = assert_raises RuntimeError do
@tm['bad']
end
assert_equal "Don't know how to build task 'bad'", e.message
end
def test_name_lookup
t = @tm.define_task(Rake::Task, :t)
assert_equal t, @tm[:t]

Просмотреть файл

@ -160,11 +160,14 @@ class TestRakeTaskWithArguments < Rake::TestCase
end
def test_values_at
t = task(:pre, [:a, :b, :c]) { |t, args|
t = task(:pre, [:a, :b, :c]) { |task, args|
a, b, c = args.values_at(:a, :b, :c)
assert_equal %w[1 2 3], [a, b, c]
}
t.invoke(*%w[1 2 3])
# HACK no assertions
end
end

Просмотреть файл

@ -93,7 +93,7 @@ class TestRakeTestTask < Rake::TestCase
t.loader = :testrb
end
flexmock(test_task).should_receive(:ruby_version).and_return('1.8.2')
def test_task.ruby_version() '1.8.2' end
assert_match(/^-S testrb +".*"$/, test_task.run_code)
end
@ -103,7 +103,7 @@ class TestRakeTestTask < Rake::TestCase
t.loader = :testrb
end
flexmock(test_task).should_receive(:ruby_version).and_return('1.8.6')
def test_task.ruby_version() '1.8.6' end
assert_match(/^-S testrb +$/, test_task.run_code)
end

Просмотреть файл

@ -5,28 +5,43 @@ class TestRakeTopLevelFunctions < Rake::TestCase
def setup
super
@app = Rake.application
Rake.application = flexmock("app")
Rake.application.should_receive(:deprecate).
and_return { |old, new, call| @app.deprecate(old, new, call) }
@app = Object.new
def @app.called
@called
end
def teardown
Rake.application = @app
def @app.method_missing(*a, &b)
@called ||= []
@called << [a, b]
nil
end
super
Rake.application = @app
end
def test_namespace
Rake.application.should_receive(:in_namespace).with("xyz", any).once
namespace "xyz" do end
block = proc do end
namespace("xyz", &block)
expected = [
[[:in_namespace, 'xyz'], block]
]
assert_equal expected, @app.called
end
def test_import
Rake.application.should_receive(:add_import).with("x").once.ordered
Rake.application.should_receive(:add_import).with("y").once.ordered
Rake.application.should_receive(:add_import).with("z").once.ordered
import('x', 'y', 'z')
expected = [
[[:add_import, 'x'], nil],
[[:add_import, 'y'], nil],
[[:add_import, 'z'], nil],
]
assert_equal expected, @app.called
end
def test_when_writing
@ -51,23 +66,43 @@ class TestRakeTopLevelFunctions < Rake::TestCase
end
def test_missing_constants_task
Rake.application.should_receive(:const_warning).with(:Task).once
Object.const_missing(:Task)
expected = [
[[:const_warning, :Task], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_file_task
Rake.application.should_receive(:const_warning).with(:FileTask).once
Object.const_missing(:FileTask)
expected = [
[[:const_warning, :FileTask], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_file_creation_task
Rake.application.should_receive(:const_warning).with(:FileCreationTask).once
Object.const_missing(:FileCreationTask)
expected = [
[[:const_warning, :FileCreationTask], nil]
]
assert_equal expected, @app.called
end
def test_missing_constants_rake_app
Rake.application.should_receive(:const_warning).with(:RakeApp).once
Object.const_missing(:RakeApp)
expected = [
[[:const_warning, :RakeApp], nil]
]
assert_equal expected, @app.called
end
def test_missing_other_constant