mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
12d9be6b72
commit
c93ed570a2
11 changed files with 238 additions and 182 deletions
|
@ -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>
|
Sat Jul 23 12:19:04 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (rb_check_id): take care of attrset ID created
|
* parse.y (rb_check_id): take care of attrset ID created
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'minitest/unit'
|
|
||||||
require 'flexmock/test_unit_integration'
|
begin
|
||||||
|
gem 'minitest'
|
||||||
|
rescue Gem::LoadError
|
||||||
|
end
|
||||||
|
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
require File.expand_path('../file_creation', __FILE__)
|
require File.expand_path('../file_creation', __FILE__)
|
||||||
|
|
||||||
class Rake::TestCase < MiniTest::Unit::TestCase
|
begin
|
||||||
include FlexMock::ArgumentTypes
|
require 'test/ruby/envutil'
|
||||||
include FlexMock::MockContainer
|
rescue LoadError
|
||||||
|
# for ruby trunk
|
||||||
|
end
|
||||||
|
|
||||||
|
class Rake::TestCase < MiniTest::Unit::TestCase
|
||||||
include FileCreation
|
include FileCreation
|
||||||
|
|
||||||
include Rake::DSL
|
include Rake::DSL
|
||||||
|
@ -18,6 +25,8 @@ class Rake::TestCase < MiniTest::Unit::TestCase
|
||||||
include Rake::TaskManager
|
include Rake::TaskManager
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
ARGV.clear
|
ARGV.clear
|
||||||
|
|
||||||
|
@ -43,11 +52,10 @@ class Rake::TestCase < MiniTest::Unit::TestCase
|
||||||
|
|
||||||
Rake.application = Rake::Application.new
|
Rake.application = Rake::Application.new
|
||||||
Rake::TaskManager.record_task_metadata = true
|
Rake::TaskManager.record_task_metadata = true
|
||||||
|
RakeFileUtils.verbose_flag = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
flexmock_teardown
|
|
||||||
|
|
||||||
Dir.chdir @orig_PWD
|
Dir.chdir @orig_PWD
|
||||||
FileUtils.rm_rf @tempdir
|
FileUtils.rm_rf @tempdir
|
||||||
|
|
||||||
|
@ -434,17 +442,6 @@ end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rakefile_statusreturn
|
|
||||||
rakefile <<-STATUSRETURN
|
|
||||||
task :exit5 do
|
|
||||||
exit(5)
|
|
||||||
end
|
|
||||||
|
|
||||||
task :normal do
|
|
||||||
end
|
|
||||||
STATUSRETURN
|
|
||||||
end
|
|
||||||
|
|
||||||
def rakefile_unittest
|
def rakefile_unittest
|
||||||
rakefile '# Empty Rakefile for Unit Test'
|
rakefile '# Empty Rakefile for Unit Test'
|
||||||
|
|
||||||
|
@ -494,7 +491,3 @@ end
|
||||||
|
|
||||||
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
|
def test_load_from_calculated_system_rakefile
|
||||||
rakefile_default
|
rakefile_default
|
||||||
flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__")
|
def @app.standard_system_dir
|
||||||
|
"__STD_SYS_DIR__"
|
||||||
|
end
|
||||||
|
|
||||||
ENV['RAKE_SYSTEM'] = nil
|
ENV['RAKE_SYSTEM'] = nil
|
||||||
|
|
||||||
|
@ -270,25 +272,28 @@ class TestRakeApplication < Rake::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_loading_imports
|
def test_loading_imports
|
||||||
mock = flexmock("loader")
|
loader = util_loader
|
||||||
mock.should_receive(:load).with("x.dummy").once
|
|
||||||
@app.instance_eval do
|
@app.instance_eval do
|
||||||
add_loader("dummy", mock)
|
add_loader("dummy", loader)
|
||||||
add_import("x.dummy")
|
add_import("x.dummy")
|
||||||
load_imports
|
load_imports
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# HACK no assertions
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_building_imported_files_on_demand
|
def test_building_imported_files_on_demand
|
||||||
mock = flexmock("loader")
|
loader = util_loader
|
||||||
mock.should_receive(:load).with("x.dummy").once
|
|
||||||
mock.should_receive(:make_dummy).with_no_args.once
|
|
||||||
@app.instance_eval do
|
@app.instance_eval do
|
||||||
intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end
|
intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
|
||||||
add_loader("dummy", mock)
|
add_loader("dummy", loader)
|
||||||
add_import("x.dummy")
|
add_import("x.dummy")
|
||||||
load_imports
|
load_imports
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# HACK no assertions
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_options_should_strip_options_from_ARGV
|
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(/use 'b' instead/i, err)
|
||||||
assert_match(/at c$/i, err)
|
assert_match(/at c$/i, err)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -119,33 +119,16 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
def test_sh
|
def test_sh
|
||||||
shellcommand
|
shellcommand
|
||||||
|
|
||||||
verbose(false) { sh %{#{FileUtils::RUBY} shellcommand.rb} }
|
verbose(false) { sh %{#{Rake::TestCase::RUBY} shellcommand.rb} }
|
||||||
assert true, "should not fail"
|
assert true, "should not fail"
|
||||||
end
|
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
|
def test_sh_with_a_single_string_argument
|
||||||
check_expansion
|
check_expansion
|
||||||
|
|
||||||
ENV['RAKE_TEST_SH'] = 'someval'
|
ENV['RAKE_TEST_SH'] = 'someval'
|
||||||
verbose(false) {
|
verbose(false) {
|
||||||
sh %{#{FileUtils::RUBY} check_expansion.rb #{env_var} someval}
|
sh %{#{RUBY} check_expansion.rb #{env_var} someval}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,7 +137,7 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
ENV['RAKE_TEST_SH'] = 'someval'
|
ENV['RAKE_TEST_SH'] = 'someval'
|
||||||
|
|
||||||
verbose(false) {
|
verbose(false) {
|
||||||
Sh.ruby 'check_no_expansion.rb', env_var, 'someval'
|
sh RUBY, 'check_no_expansion.rb', env_var, 'someval'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -162,7 +145,7 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
shellcommand
|
shellcommand
|
||||||
|
|
||||||
assert_raises(RuntimeError) {
|
assert_raises(RuntimeError) {
|
||||||
verbose(false) { Sh.run %{#{FileUtils::RUBY} shellcommand.rb 1} }
|
verbose(false) { sh %{#{RUBY} shellcommand.rb 1} }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,12 +154,12 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
verbose(false) {
|
verbose(false) {
|
||||||
sh(%{#{FileUtils::RUBY} shellcommand.rb}) do |ok, res|
|
sh(%{#{RUBY} shellcommand.rb}) do |ok, res|
|
||||||
assert(ok)
|
assert(ok)
|
||||||
assert_equal 0, res.exitstatus
|
assert_equal 0, res.exitstatus
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
sh(%{#{FileUtils::RUBY} shellcommand.rb 1}) do |ok, res|
|
sh(%{#{RUBY} shellcommand.rb 1}) do |ok, res|
|
||||||
assert(!ok)
|
assert(!ok)
|
||||||
assert_equal 1, res.exitstatus
|
assert_equal 1, res.exitstatus
|
||||||
count += 1
|
count += 1
|
||||||
|
@ -241,8 +224,10 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
ENV['RAKE_TEST_SH'] = 'someval'
|
ENV['RAKE_TEST_SH'] = 'someval'
|
||||||
|
|
||||||
verbose(false) {
|
verbose(false) {
|
||||||
|
replace_ruby {
|
||||||
ruby %{check_expansion.rb #{env_var} someval}
|
ruby %{check_expansion.rb #{env_var} someval}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ruby_with_multiple_arguments
|
def test_ruby_with_multiple_arguments
|
||||||
|
@ -250,8 +235,10 @@ class TestRakeFileUtils < Rake::TestCase
|
||||||
|
|
||||||
ENV['RAKE_TEST_SH'] = 'someval'
|
ENV['RAKE_TEST_SH'] = 'someval'
|
||||||
verbose(false) {
|
verbose(false) {
|
||||||
|
replace_ruby {
|
||||||
ruby 'check_no_expansion.rb', env_var, 'someval'
|
ruby 'check_no_expansion.rb', env_var, 'someval'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_split_all
|
def test_split_all
|
||||||
|
@ -289,6 +276,16 @@ end
|
||||||
CHECK_EXPANSION
|
CHECK_EXPANSION
|
||||||
end
|
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
|
def shellcommand
|
||||||
command 'shellcommand.rb', <<-SHELLCOMMAND
|
command 'shellcommand.rb', <<-SHELLCOMMAND
|
||||||
#!/usr/bin/env ruby
|
#!/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 File.expand_path('../helper', __FILE__)
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'open3'
|
||||||
# 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
|
|
||||||
|
|
||||||
class TestRakeFunctional < Rake::TestCase
|
class TestRakeFunctional < Rake::TestCase
|
||||||
|
|
||||||
|
@ -59,16 +27,14 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
rake
|
rake
|
||||||
|
|
||||||
assert_match(/^DEFAULT$/, @out)
|
assert_match(/^DEFAULT$/, @out)
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rake_error_on_bad_task
|
def test_rake_error_on_bad_task
|
||||||
rakefile_default
|
rakefile_default
|
||||||
|
|
||||||
rake "xyz"
|
rake '-t', 'xyz'
|
||||||
|
|
||||||
assert_match(/rake aborted/, @err)
|
assert_match(/rake aborted/, @err)
|
||||||
assert_status(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_env_available_at_top_scope
|
def test_env_available_at_top_scope
|
||||||
|
@ -77,16 +43,14 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
rake "TESTTOPSCOPE=1"
|
rake "TESTTOPSCOPE=1"
|
||||||
|
|
||||||
assert_match(/^TOPSCOPE$/, @out)
|
assert_match(/^TOPSCOPE$/, @out)
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_env_available_at_task_scope
|
def test_env_available_at_task_scope
|
||||||
rakefile_default
|
rakefile_default
|
||||||
|
|
||||||
rake "TESTTASKSCOPE=1 task_scope"
|
rake 'TESTTASKSCOPE=1', 'task_scope'
|
||||||
|
|
||||||
assert_match(/^TASKSCOPE$/, @out)
|
assert_match(/^TASKSCOPE$/, @out)
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multi_desc
|
def test_multi_desc
|
||||||
|
@ -283,8 +247,6 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
rake "--dry-run"
|
rake "--dry-run"
|
||||||
|
|
||||||
refute_match(/No such file/, @out)
|
refute_match(/No such file/, @out)
|
||||||
|
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Test for the trace/dry_run bug found by Brian Chandler
|
# Test for the trace/dry_run bug found by Brian Chandler
|
||||||
|
@ -298,7 +260,6 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
rake "--trace"
|
rake "--trace"
|
||||||
|
|
||||||
refute_match(/No such file/, @out)
|
refute_match(/No such file/, @out)
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_imports
|
def test_imports
|
||||||
|
@ -309,7 +270,6 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
|
assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
|
||||||
"'dynamic_deps' file should exist"
|
"'dynamic_deps' file should exist"
|
||||||
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
|
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rules_chaining_to_file_task
|
def test_rules_chaining_to_file_task
|
||||||
|
@ -319,7 +279,6 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
|
|
||||||
assert File.exist?(File.join(@tempdir, 'play.app')),
|
assert File.exist?(File.join(@tempdir, 'play.app')),
|
||||||
"'play.app' file should exist"
|
"'play.app' file should exist"
|
||||||
assert_status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_file_creation_task
|
def test_file_creation_task
|
||||||
|
@ -335,7 +294,7 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
def test_dash_f_with_no_arg_foils_rakefile_lookup
|
def test_dash_f_with_no_arg_foils_rakefile_lookup
|
||||||
rakefile_rakelib
|
rakefile_rakelib
|
||||||
|
|
||||||
rake "-I rakelib -rtest1 -f"
|
rake '-I', 'rakelib', '-rtest1', '-f'
|
||||||
|
|
||||||
assert_match(/^TEST1$/, @out)
|
assert_match(/^TEST1$/, @out)
|
||||||
end
|
end
|
||||||
|
@ -343,8 +302,9 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
def test_dot_rake_files_can_be_loaded_with_dash_r
|
def test_dot_rake_files_can_be_loaded_with_dash_r
|
||||||
rakefile_rakelib
|
rakefile_rakelib
|
||||||
|
|
||||||
rake "-I rakelib -rtest2 -f"
|
rake '-I', 'rakelib', '-rtest2', '-f'
|
||||||
|
|
||||||
|
assert_empty @err
|
||||||
assert_match(/^TEST2$/, @out)
|
assert_match(/^TEST2$/, @out)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -412,22 +372,6 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
|
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
|
||||||
end
|
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
|
def test_comment_before_task_acts_like_desc
|
||||||
rakefile_comments
|
rakefile_comments
|
||||||
|
|
||||||
|
@ -469,42 +413,38 @@ class TestRakeFunctional < Rake::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_file_list_is_requirable_separately
|
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 "1\n", @out
|
||||||
assert_equal 0, @status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Run a shell Ruby command with command line options (using the
|
# Run a shell Ruby command with command line options (using the
|
||||||
# default test options). Output is captured in @out, @err and
|
# default test options). Output is captured in @out and @err
|
||||||
# @status.
|
|
||||||
def ruby(*option_list)
|
def ruby(*option_list)
|
||||||
run_ruby(@ruby_options + option_list)
|
run_ruby(@ruby_options + option_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run a command line rake with the give rake options. Default
|
# Run a command line rake with the give rake options. Default
|
||||||
# command line ruby options are included. Output is captured in
|
# command line ruby options are included. Output is captured in
|
||||||
# @out, @err and @status.
|
# @out and @err
|
||||||
def rake(*rake_options)
|
def rake(*rake_options)
|
||||||
run_ruby @ruby_options + [@rake_path] + rake_options
|
run_ruby @ruby_options + [@rake_path] + rake_options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Low level ruby command runner ...
|
# Low level ruby command runner ...
|
||||||
def run_ruby(option_list)
|
def run_ruby(option_list)
|
||||||
shell = Session::Shell.new
|
puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
|
||||||
command = "#{Gem.ruby} #{option_list.join ' '}"
|
|
||||||
puts "COMMAND: [#{command}]" if @verbose
|
inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list)
|
||||||
@out, @err = shell.execute command
|
inn.close
|
||||||
@status = shell.exit_status
|
|
||||||
puts "STATUS: [#{@status}]" if @verbose
|
@out = out.read
|
||||||
|
@err = err.read
|
||||||
|
|
||||||
puts "OUTPUT: [#{@out}]" if @verbose
|
puts "OUTPUT: [#{@out}]" if @verbose
|
||||||
puts "ERROR: [#{@err}]" if @verbose
|
puts "ERROR: [#{@err}]" if @verbose
|
||||||
puts "PWD: [#{Dir.pwd}]" if @verbose
|
puts "PWD: [#{Dir.pwd}]" if @verbose
|
||||||
shell.close
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_status(expected_status=0)
|
|
||||||
assert_equal expected_status, @status
|
|
||||||
end
|
end
|
||||||
end if defined?(Session)
|
|
||||||
|
|
|
@ -208,10 +208,7 @@ class TestRakeTask < Rake::TestCase
|
||||||
b = task :b
|
b = task :b
|
||||||
c = task :c
|
c = task :c
|
||||||
|
|
||||||
faux_stamp = 100
|
assert_in_delta Time.now, a.timestamp, 0.1, 'computer too slow?'
|
||||||
flexmock(Time, :now => faux_stamp)
|
|
||||||
|
|
||||||
assert_equal faux_stamp, a.timestamp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_timestamp_returns_latest_prereq_timestamp
|
def test_timestamp_returns_latest_prereq_timestamp
|
||||||
|
@ -219,12 +216,11 @@ class TestRakeTask < Rake::TestCase
|
||||||
b = task :b
|
b = task :b
|
||||||
c = task :c
|
c = task :c
|
||||||
|
|
||||||
faux_stamp = 100
|
now = Time.now
|
||||||
flexmock(Time, :now => faux_stamp-10)
|
def b.timestamp() Time.now + 10 end
|
||||||
flexmock(b, :timestamp => faux_stamp - 1)
|
def c.timestamp() Time.now + 5 end
|
||||||
flexmock(c, :timestamp => faux_stamp)
|
|
||||||
|
|
||||||
assert_equal faux_stamp, a.timestamp
|
assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_investigation_output
|
def test_investigation_output
|
||||||
|
|
|
@ -51,38 +51,31 @@ class TestRakeTaskArgumentParsing < Rake::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_terminal_width_using_stty
|
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,
|
assert_equal 1235, @app.terminal_width
|
||||||
:unix? => true,
|
|
||||||
:dynamic_width_stty => 1235,
|
|
||||||
:dynamic_width_tput => 0)
|
|
||||||
|
|
||||||
assert_equal 1235, app.terminal_width
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_terminal_width_using_tput
|
def test_terminal_width_using_tput
|
||||||
app = Rake::Application.new
|
def @app.unix?() true end
|
||||||
flexmock(app,
|
def @app.dynamic_width_stty() 0 end
|
||||||
:unix? => true,
|
def @app.dynamic_width_tput() 1236 end
|
||||||
:dynamic_width_stty => 0,
|
|
||||||
:dynamic_width_tput => 1236)
|
|
||||||
|
|
||||||
assert_equal 1236, app.terminal_width
|
assert_equal 1236, @app.terminal_width
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_terminal_width_using_hardcoded_80
|
def test_terminal_width_using_hardcoded_80
|
||||||
app = Rake::Application.new
|
def @app.unix?() true end
|
||||||
flexmock(app, :unix? => false)
|
|
||||||
|
|
||||||
assert_equal 80, app.terminal_width
|
assert_equal 80, @app.terminal_width
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_terminal_width_with_failure
|
def test_terminal_width_with_failure
|
||||||
app = Rake::Application.new
|
def @app.unix?() raise end
|
||||||
flexmock(app).should_receive(:unix?).and_throw(RuntimeError)
|
|
||||||
|
|
||||||
assert_equal 80, app.terminal_width
|
assert_equal 80, @app.terminal_width
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_rakeopt
|
def test_no_rakeopt
|
||||||
|
|
|
@ -19,6 +19,14 @@ class TestRakeTaskManager < Rake::TestCase
|
||||||
assert_equal @tm, t.application
|
assert_equal @tm, t.application
|
||||||
end
|
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
|
def test_name_lookup
|
||||||
t = @tm.define_task(Rake::Task, :t)
|
t = @tm.define_task(Rake::Task, :t)
|
||||||
assert_equal t, @tm[:t]
|
assert_equal t, @tm[:t]
|
||||||
|
|
|
@ -160,11 +160,14 @@ class TestRakeTaskWithArguments < Rake::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_values_at
|
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)
|
a, b, c = args.values_at(:a, :b, :c)
|
||||||
assert_equal %w[1 2 3], [a, b, c]
|
assert_equal %w[1 2 3], [a, b, c]
|
||||||
}
|
}
|
||||||
|
|
||||||
t.invoke(*%w[1 2 3])
|
t.invoke(*%w[1 2 3])
|
||||||
|
|
||||||
|
# HACK no assertions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ class TestRakeTestTask < Rake::TestCase
|
||||||
t.loader = :testrb
|
t.loader = :testrb
|
||||||
end
|
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)
|
assert_match(/^-S testrb +".*"$/, test_task.run_code)
|
||||||
end
|
end
|
||||||
|
@ -103,7 +103,7 @@ class TestRakeTestTask < Rake::TestCase
|
||||||
t.loader = :testrb
|
t.loader = :testrb
|
||||||
end
|
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)
|
assert_match(/^-S testrb +$/, test_task.run_code)
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,28 +5,43 @@ class TestRakeTopLevelFunctions < Rake::TestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
@app = Rake.application
|
@app = Object.new
|
||||||
Rake.application = flexmock("app")
|
|
||||||
Rake.application.should_receive(:deprecate).
|
def @app.called
|
||||||
and_return { |old, new, call| @app.deprecate(old, new, call) }
|
@called
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def @app.method_missing(*a, &b)
|
||||||
Rake.application = @app
|
@called ||= []
|
||||||
|
@called << [a, b]
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
super
|
Rake.application = @app
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_namespace
|
def test_namespace
|
||||||
Rake.application.should_receive(:in_namespace).with("xyz", any).once
|
block = proc do end
|
||||||
namespace "xyz" do end
|
|
||||||
|
namespace("xyz", &block)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:in_namespace, 'xyz'], block]
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_import
|
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')
|
import('x', 'y', 'z')
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:add_import, 'x'], nil],
|
||||||
|
[[:add_import, 'y'], nil],
|
||||||
|
[[:add_import, 'z'], nil],
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_when_writing
|
def test_when_writing
|
||||||
|
@ -51,23 +66,43 @@ class TestRakeTopLevelFunctions < Rake::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_constants_task
|
def test_missing_constants_task
|
||||||
Rake.application.should_receive(:const_warning).with(:Task).once
|
|
||||||
Object.const_missing(:Task)
|
Object.const_missing(:Task)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:const_warning, :Task], nil]
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_constants_file_task
|
def test_missing_constants_file_task
|
||||||
Rake.application.should_receive(:const_warning).with(:FileTask).once
|
|
||||||
Object.const_missing(:FileTask)
|
Object.const_missing(:FileTask)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:const_warning, :FileTask], nil]
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_constants_file_creation_task
|
def test_missing_constants_file_creation_task
|
||||||
Rake.application.should_receive(:const_warning).with(:FileCreationTask).once
|
|
||||||
Object.const_missing(:FileCreationTask)
|
Object.const_missing(:FileCreationTask)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:const_warning, :FileCreationTask], nil]
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_constants_rake_app
|
def test_missing_constants_rake_app
|
||||||
Rake.application.should_receive(:const_warning).with(:RakeApp).once
|
|
||||||
Object.const_missing(:RakeApp)
|
Object.const_missing(:RakeApp)
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
[[:const_warning, :RakeApp], nil]
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal expected, @app.called
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_missing_other_constant
|
def test_missing_other_constant
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue