summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rake/helper.rb506
-rw-r--r--test/rake/support/rakefile_definitions.rb444
-rw-r--r--test/rake/support/ruby_runner.rb33
-rw-r--r--test/rake/test_rake_application.rb42
-rw-r--r--test/rake/test_rake_application_options.rb69
-rw-r--r--test/rake/test_rake_backtrace.rb52
-rw-r--r--test/rake/test_rake_clean.rb40
-rw-r--r--test/rake/test_rake_definitions.rb5
-rw-r--r--test/rake/test_rake_dsl.rb37
-rw-r--r--test/rake/test_rake_file_creation_task.rb4
-rw-r--r--test/rake/test_rake_file_list.rb47
-rw-r--r--test/rake/test_rake_file_task.rb12
-rw-r--r--test/rake/test_rake_file_utils.rb8
-rw-r--r--test/rake/test_rake_ftp_file.rb41
-rw-r--r--test/rake/test_rake_functional.rb42
-rw-r--r--test/rake/test_rake_invocation_chain.rb18
-rw-r--r--test/rake/test_rake_linked_list.rb84
-rw-r--r--test/rake/test_rake_makefile_loader.rb4
-rw-r--r--test/rake/test_rake_multi_task.rb5
-rw-r--r--test/rake/test_rake_name_space.rb2
-rw-r--r--test/rake/test_rake_path_map.rb35
-rw-r--r--test/rake/test_rake_rake_test_loader.rb5
-rw-r--r--test/rake/test_rake_rdoc_task.rb83
-rw-r--r--test/rake/test_rake_reduce_compat.rb47
-rw-r--r--test/rake/test_rake_rules.rb65
-rw-r--r--test/rake/test_rake_scope.rb44
-rw-r--r--test/rake/test_rake_task.rb86
-rw-r--r--test/rake/test_rake_task_arguments.rb37
-rw-r--r--test/rake/test_rake_task_manager.rb31
-rw-r--r--test/rake/test_rake_task_manager_argument_resolution.rb17
-rw-r--r--test/rake/test_rake_task_with_arguments.rb24
-rw-r--r--test/rake/test_rake_test_task.rb3
-rw-r--r--test/rake/test_rake_thread_pool.rb67
-rw-r--r--test/rake/test_rake_top_level_functions.rb40
-rw-r--r--test/rake/test_sys.rb20
-rw-r--r--test/rake/test_thread_history_display.rb22
-rw-r--r--test/rake/test_trace_output.rb9
37 files changed, 1135 insertions, 995 deletions
diff --git a/test/rake/helper.rb b/test/rake/helper.rb
index 9817e8f0cd..74cab7559f 100644
--- a/test/rake/helper.rb
+++ b/test/rake/helper.rb
@@ -11,6 +11,9 @@ require 'rake'
require 'tmpdir'
require File.expand_path('../file_creation', __FILE__)
+require_relative 'support/ruby_runner'
+require_relative 'support/rakefile_definitions'
+
begin
require_relative '../ruby/envutil'
rescue NoMethodError, LoadError
@@ -33,26 +36,30 @@ class Rake::TestCase < MiniTest::Unit::TestCase
test_dir = File.basename File.dirname File.expand_path __FILE__
- @rake_root = if test_dir == 'test' then
- # rake repository
- File.expand_path '../../', __FILE__
- else
- # ruby repository
- File.expand_path '../../../', __FILE__
- end
+ @rake_root =
+ if test_dir == 'test'
+ # rake repository
+ File.expand_path '../../', __FILE__
+ else
+ # ruby repository
+ File.expand_path '../../../', __FILE__
+ end
+
+ @verbose = ENV['VERBOSE']
@rake_exec = File.join @rake_root, 'bin', 'rake'
@rake_lib = File.join @rake_root, 'lib'
-
- @orig_PWD = Dir.pwd
- @orig_APPDATA = ENV['APPDATA']
- @orig_HOME = ENV['HOME']
- @orig_HOMEDRIVE = ENV['HOMEDRIVE']
- @orig_HOMEPATH = ENV['HOMEPATH']
- @orig_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
- @orig_RAKE_SYSTEM = ENV['RAKE_SYSTEM']
- @orig_RAKEOPT = ENV['RAKEOPT']
- @orig_USERPROFILE = ENV['USERPROFILE']
+ @ruby_options = ["-I#{@rake_lib}", "-I."]
+
+ @orig_pwd = Dir.pwd
+ @orig_appdata = ENV['APPDATA']
+ @orig_home = ENV['HOME']
+ @orig_homedrive = ENV['HOMEDRIVE']
+ @orig_homepath = ENV['HOMEPATH']
+ @orig_rake_columns = ENV['RAKE_COLUMNS']
+ @orig_rake_system = ENV['RAKE_SYSTEM']
+ @orig_rakeopt = ENV['RAKEOPT']
+ @orig_userprofile = ENV['USERPROFILE']
ENV.delete 'RAKE_COLUMNS'
ENV.delete 'RAKE_SYSTEM'
ENV.delete 'RAKEOPT'
@@ -70,22 +77,22 @@ class Rake::TestCase < MiniTest::Unit::TestCase
end
def teardown
- Dir.chdir @orig_PWD
+ Dir.chdir @orig_pwd
FileUtils.rm_rf @tempdir
- if @orig_APPDATA then
- ENV['APPDATA'] = @orig_APPDATA
+ if @orig_appdata
+ ENV['APPDATA'] = @orig_appdata
else
ENV.delete 'APPDATA'
end
- ENV['HOME'] = @orig_HOME
- ENV['HOMEDRIVE'] = @orig_HOMEDRIVE
- ENV['HOMEPATH'] = @orig_HOMEPATH
- ENV['RAKE_COLUMNS'] = @orig_RAKE_COLUMNS
- ENV['RAKE_SYSTEM'] = @orig_RAKE_SYSTEM
- ENV['RAKEOPT'] = @orig_RAKEOPT
- ENV['USERPROFILE'] = @orig_USERPROFILE
+ ENV['HOME'] = @orig_home
+ ENV['HOMEDRIVE'] = @orig_homedrive
+ ENV['HOMEPATH'] = @orig_homepath
+ ENV['RAKE_COLUMNS'] = @orig_rake_columns
+ ENV['RAKE_SYSTEM'] = @orig_rake_system
+ ENV['RAKEOPT'] = @orig_rakeopt
+ ENV['USERPROFILE'] = @orig_userprofile
end
def ignore_deprecations
@@ -111,452 +118,11 @@ end
ENV['RAKE_SYSTEM'] = @system_dir
end
- def rakefile contents
+ def rakefile(contents)
open 'Rakefile', 'w' do |io|
io << contents
end
end
- def rakefile_access
- rakefile <<-ACCESS
-TOP_LEVEL_CONSTANT = 0
-
-def a_top_level_function
-end
-
-task :default => [:work, :obj, :const]
-
-task :work do
- begin
- a_top_level_function
- puts "GOOD:M Top level methods can be called in tasks"
- rescue NameError => ex
- puts "BAD:M Top level methods can not be called in tasks"
- end
-end
-
-# TODO: remove `disabled_' when DeprecatedObjectDSL removed
-task :obj
-task :disabled_obj do
- begin
- Object.new.instance_eval { task :xyzzy }
- puts "BAD:D Rake DSL are polluting objects"
- rescue StandardError => ex
- puts "GOOD:D Rake DSL are not polluting objects"
- end
-end
-
-task :const do
- begin
- TOP_LEVEL_CONSTANT
- puts "GOOD:C Top level constants are available in tasks"
- rescue StandardError => ex
- puts "BAD:C Top level constants are NOT available in tasks"
- end
-end
- ACCESS
- end
-
- def rakefile_chains
- rakefile <<-DEFAULT
-task :default => "play.app"
-
-file "play.scpt" => "base" do |t|
- cp t.prerequisites.first, t.name
-end
-
-rule ".app" => ".scpt" do |t|
- cp t.source, t.name
-end
-
-file 'base' do
- touch 'base'
-end
- DEFAULT
- end
-
- def rakefile_comments
- rakefile <<-COMMENTS
-# comment for t1
-task :t1 do
-end
-
-# no comment or task because there's a blank line
-
-task :t2 do
-end
-
-desc "override comment for t3"
-# this is not the description
-multitask :t3 do
-end
-
-# this is not the description
-desc "override comment for t4"
-file :t4 do
-end
- COMMENTS
- end
-
- def rakefile_default
- rakefile <<-DEFAULT
-if ENV['TESTTOPSCOPE']
- puts "TOPSCOPE"
-end
-
-task :default do
- puts "DEFAULT"
-end
-
-task :other => [:default] do
- puts "OTHER"
-end
-
-task :task_scope do
- if ENV['TESTTASKSCOPE']
- puts "TASKSCOPE"
- end
-end
- DEFAULT
- end
-
- def rakefile_dryrun
- rakefile <<-DRYRUN
-task :default => ["temp_main"]
-
-file "temp_main" => [:all_apps] do touch "temp_main" end
-
-task :all_apps => [:one, :two]
-task :one => ["temp_one"]
-task :two => ["temp_two"]
-
-file "temp_one" do |t|
- touch "temp_one"
-end
-file "temp_two" do |t|
- touch "temp_two"
-end
-
-task :clean do
- ["temp_one", "temp_two", "temp_main"].each do |file|
- rm_f file
- end
-end
- DRYRUN
-
- FileUtils.touch 'temp_main'
- FileUtils.touch 'temp_two'
- end
-
- def rakefile_extra
- rakefile 'task :default'
-
- FileUtils.mkdir_p 'rakelib'
-
- open File.join('rakelib', 'extra.rake'), 'w' do |io|
- io << <<-EXTRA_RAKE
-# Added for testing
-
-namespace :extra do
- desc "An Extra Task"
- task :extra do
- puts "Read all about it"
- end
-end
- EXTRA_RAKE
- end
- end
-
- def rakefile_file_creation
- rakefile <<-'FILE_CREATION'
-N = 2
-
-task :default => :run
-
-BUILD_DIR = 'build'
-task :clean do
- rm_rf 'build'
- rm_rf 'src'
-end
-
-task :run
-
-TARGET_DIR = 'build/copies'
-
-FileList['src/*'].each do |src|
- directory TARGET_DIR
- target = File.join TARGET_DIR, File.basename(src)
- file target => [src, TARGET_DIR] do
- cp src, target
- # sleep 3 if src !~ /foo#{N-1}$/ # I'm commenting out this sleep, it doesn't seem to do anything.
- end
- task :run => target
-end
-
-task :prep => :clean do
- mkdir_p 'src'
- N.times do |n|
- touch "src/foo#{n}"
- end
-end
- FILE_CREATION
- end
-
- def rakefile_imports
- rakefile <<-IMPORTS
-require 'rake/loaders/makefile'
-
-task :default
-
-task :other do
- puts "OTHER"
-end
-
-file "dynamic_deps" do |t|
- open(t.name, "w") do |f| f.puts "puts 'DYNAMIC'" end
-end
-
-import "dynamic_deps"
-import "static_deps"
-import "static_deps"
-import "deps.mf"
-puts "FIRST"
- IMPORTS
-
- open 'deps.mf', 'w' do |io|
- io << <<-DEPS
-default: other
- DEPS
- end
-
- open "static_deps", "w" do |f|
- f.puts 'puts "STATIC"'
- end
- end
-
- def rakefile_multidesc
- rakefile <<-MULTIDESC
-task :b
-
-desc "A"
-task :a
-
-desc "B"
-task :b
-
-desc "A2"
-task :a
-
-task :c
-
-desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
-task :d
- MULTIDESC
- end
-
- def rakefile_namespace
- rakefile <<-NAMESPACE
-desc "copy"
-task :copy do
- puts "COPY"
-end
-
-namespace "nest" do
- desc "nest copy"
- task :copy do
- puts "NEST COPY"
- end
- task :xx => :copy
-end
-
-anon_ns = namespace do
- desc "anonymous copy task"
- task :copy do
- puts "ANON COPY"
- end
-end
-
-desc "Top level task to run the anonymous version of copy"
-task :anon => anon_ns[:copy]
-
-namespace "very" do
- namespace "nested" do
- task "run" => "rake:copy"
- end
-end
-
-namespace "a" do
- desc "Run task in the 'a' namespace"
- task "run" do
- puts "IN A"
- end
-end
-
-namespace "b" do
- desc "Run task in the 'b' namespace"
- task "run" => "a:run" do
- puts "IN B"
- end
-end
-
-namespace "file1" do
- file "xyz.rb" do
- puts "XYZ1"
- end
-end
-
-namespace "file2" do
- file "xyz.rb" do
- puts "XYZ2"
- end
-end
-
-namespace "scopedep" do
- task :prepare do
- touch "scopedep.rb"
- puts "PREPARE"
- end
- file "scopedep.rb" => [:prepare] do
- puts "SCOPEDEP"
- end
-end
- NAMESPACE
- end
-
- def rakefile_nosearch
- FileUtils.touch 'dummy'
- end
-
- def rakefile_rakelib
- FileUtils.mkdir_p 'rakelib'
-
- Dir.chdir 'rakelib' do
- open 'test1.rb', 'w' do |io|
- io << <<-TEST1
-task :default do
- puts "TEST1"
-end
- TEST1
- end
-
- open 'test2.rake', 'w' do |io|
- io << <<-TEST1
-task :default do
- puts "TEST2"
-end
- TEST1
- end
- end
- end
-
- def rakefile_rbext
- open 'rakefile.rb', 'w' do |io|
- io << 'task :default do puts "OK" end'
- end
- end
-
- def rakefile_unittest
- rakefile '# Empty Rakefile for Unit Test'
-
- readme = File.join 'subdir', 'README'
- FileUtils.mkdir_p File.dirname readme
-
- FileUtils.touch readme
- end
-
- def rakefile_verbose
- rakefile <<-VERBOSE
-task :standalone_verbose_true do
- verbose true
- sh "#{RUBY} -e '0'"
-end
-
-task :standalone_verbose_false do
- verbose false
- sh "#{RUBY} -e '0'"
-end
-
-task :inline_verbose_default do
- sh "#{RUBY} -e '0'"
-end
-
-task :inline_verbose_false do
- sh "#{RUBY} -e '0'", :verbose => false
-end
-
-task :inline_verbose_true do
- sh "#{RUBY} -e '0'", :verbose => true
-end
-
-task :block_verbose_true do
- verbose(true) do
- sh "#{RUBY} -e '0'"
- end
-end
-
-task :block_verbose_false do
- verbose(false) do
- sh "#{RUBY} -e '0'"
- end
-end
- VERBOSE
- end
-
- def rakefile_test_signal
- rakefile <<-TEST_SIGNAL
-require 'rake/testtask'
-
-Rake::TestTask.new(:a) do |t|
- t.test_files = ['a_test.rb']
-end
-
-Rake::TestTask.new(:b) do |t|
- t.test_files = ['b_test.rb']
-end
-
-task :test do
- Rake::Task[:a].invoke
- Rake::Task[:b].invoke
-end
-
-task :default => :test
- TEST_SIGNAL
- open 'a_test.rb', 'w' do |io|
- io << 'puts "ATEST"' << "\n"
- io << '$stdout.flush' << "\n"
- io << 'Process.kill("TERM", $$)' << "\n"
- end
- open 'b_test.rb', 'w' do |io|
- io << 'puts "BTEST"' << "\n"
- io << '$stdout.flush' << "\n"
- end
- end
-
- def rakefile_failing_test_task
- rakefile <<-TEST_TASK
-require 'rake/testtask'
-
-task :default => :test
-Rake::TestTask.new(:test) do |t|
- t.test_files = ['a_test.rb']
-end
- TEST_TASK
- open 'a_test.rb', 'w' do |io|
- io << "require 'minitest/autorun'\n"
- io << "class ExitTaskTest < MiniTest::Unit::TestCase\n"
- io << " def test_exit\n"
- io << " assert false, 'this should fail'\n"
- io << " end\n"
- io << "end\n"
- end
- end
-
- def rakefile_stand_alone_filelist
- open 'stand_alone_filelist.rb', 'w' do |io|
- io << "require 'rake/file_list'\n"
- io << "FL = Rake::FileList['*.rb']\n"
- io << "puts FL\n"
- end
- end
-
+ include RakefileDefinitions
end
diff --git a/test/rake/support/rakefile_definitions.rb b/test/rake/support/rakefile_definitions.rb
new file mode 100644
index 0000000000..5cc2ae1293
--- /dev/null
+++ b/test/rake/support/rakefile_definitions.rb
@@ -0,0 +1,444 @@
+module RakefileDefinitions
+ include FileUtils
+
+ def rakefile_access
+ rakefile <<-ACCESS
+TOP_LEVEL_CONSTANT = 0
+
+def a_top_level_function
+end
+
+task :default => [:work, :obj, :const]
+
+task :work do
+ begin
+ a_top_level_function
+ puts "GOOD:M Top level methods can be called in tasks"
+ rescue NameError => ex
+ puts "BAD:M Top level methods can not be called in tasks"
+ end
+end
+
+# TODO: remove `disabled_' when DeprecatedObjectDSL removed
+task :obj
+task :disabled_obj do
+ begin
+ Object.new.instance_eval { task :xyzzy }
+ puts "BAD:D Rake DSL are polluting objects"
+ rescue StandardError => ex
+ puts "GOOD:D Rake DSL are not polluting objects"
+ end
+end
+
+task :const do
+ begin
+ TOP_LEVEL_CONSTANT
+ puts "GOOD:C Top level constants are available in tasks"
+ rescue StandardError => ex
+ puts "BAD:C Top level constants are NOT available in tasks"
+ end
+end
+ ACCESS
+ end
+
+ def rakefile_chains
+ rakefile <<-DEFAULT
+task :default => "play.app"
+
+file "play.scpt" => "base" do |t|
+ cp t.prerequisites.first, t.name
+end
+
+rule ".app" => ".scpt" do |t|
+ cp t.source, t.name
+end
+
+file 'base' do
+ touch 'base'
+end
+ DEFAULT
+ end
+
+ def rakefile_comments
+ rakefile <<-COMMENTS
+# comment for t1
+task :t1 do
+end
+
+# no comment or task because there's a blank line
+
+task :t2 do
+end
+
+desc "override comment for t3"
+# this is not the description
+multitask :t3 do
+end
+
+# this is not the description
+desc "override comment for t4"
+file :t4 do
+end
+ COMMENTS
+ end
+
+ def rakefile_default
+ rakefile <<-DEFAULT
+if ENV['TESTTOPSCOPE']
+ puts "TOPSCOPE"
+end
+
+task :default do
+ puts "DEFAULT"
+end
+
+task :other => [:default] do
+ puts "OTHER"
+end
+
+task :task_scope do
+ if ENV['TESTTASKSCOPE']
+ puts "TASKSCOPE"
+ end
+end
+ DEFAULT
+ end
+
+ def rakefile_dryrun
+ rakefile <<-DRYRUN
+task :default => ["temp_main"]
+
+file "temp_main" => [:all_apps] do touch "temp_main" end
+
+task :all_apps => [:one, :two]
+task :one => ["temp_one"]
+task :two => ["temp_two"]
+
+file "temp_one" do |t|
+ touch "temp_one"
+end
+file "temp_two" do |t|
+ touch "temp_two"
+end
+
+task :clean do
+ ["temp_one", "temp_two", "temp_main"].each do |file|
+ rm_f file
+ end
+end
+ DRYRUN
+
+ FileUtils.touch 'temp_main'
+ FileUtils.touch 'temp_two'
+ end
+
+ def rakefile_extra
+ rakefile 'task :default'
+
+ FileUtils.mkdir_p 'rakelib'
+
+ open File.join('rakelib', 'extra.rake'), 'w' do |io|
+ io << <<-EXTRA_RAKE
+# Added for testing
+
+namespace :extra do
+ desc "An Extra Task"
+ task :extra do
+ puts "Read all about it"
+ end
+end
+ EXTRA_RAKE
+ end
+ end
+
+ def rakefile_file_creation
+ rakefile <<-'FILE_CREATION'
+N = 2
+
+task :default => :run
+
+BUILD_DIR = 'build'
+task :clean do
+ rm_rf 'build'
+ rm_rf 'src'
+end
+
+task :run
+
+TARGET_DIR = 'build/copies'
+
+FileList['src/*'].each do |src|
+ directory TARGET_DIR
+ target = File.join TARGET_DIR, File.basename(src)
+ file target => [src, TARGET_DIR] do
+ cp src, target
+ end
+ task :run => target
+end
+
+task :prep => :clean do
+ mkdir_p 'src'
+ N.times do |n|
+ touch "src/foo#{n}"
+ end
+end
+ FILE_CREATION
+ end
+
+ def rakefile_imports
+ rakefile <<-IMPORTS
+require 'rake/loaders/makefile'
+
+task :default
+
+task :other do
+ puts "OTHER"
+end
+
+file "dynamic_deps" do |t|
+ open(t.name, "w") do |f| f.puts "puts 'DYNAMIC'" end
+end
+
+import "dynamic_deps"
+import "static_deps"
+import "static_deps"
+import "deps.mf"
+puts "FIRST"
+ IMPORTS
+
+ open 'deps.mf', 'w' do |io|
+ io << <<-DEPS
+default: other
+ DEPS
+ end
+
+ open "static_deps", "w" do |f|
+ f.puts 'puts "STATIC"'
+ end
+ end
+
+ def rakefile_multidesc
+ rakefile <<-MULTIDESC
+task :b
+
+desc "A"
+task :a
+
+desc "B"
+task :b
+
+desc "A2"
+task :a
+
+task :c
+
+desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+task :d
+ MULTIDESC
+ end
+
+ def rakefile_namespace
+ rakefile <<-NAMESPACE
+desc "copy"
+task :copy do
+ puts "COPY"
+end
+
+namespace "nest" do
+ desc "nest copy"
+ task :copy do
+ puts "NEST COPY"
+ end
+ task :xx => :copy
+end
+
+anon_ns = namespace do
+ desc "anonymous copy task"
+ task :copy do
+ puts "ANON COPY"
+ end
+end
+
+desc "Top level task to run the anonymous version of copy"
+task :anon => anon_ns[:copy]
+
+namespace "very" do
+ namespace "nested" do
+ task "run" => "rake:copy"
+ end
+end
+
+namespace "a" do
+ desc "Run task in the 'a' namespace"
+ task "run" do
+ puts "IN A"
+ end
+end
+
+namespace "b" do
+ desc "Run task in the 'b' namespace"
+ task "run" => "a:run" do
+ puts "IN B"
+ end
+end
+
+namespace "file1" do
+ file "xyz.rb" do
+ puts "XYZ1"
+ end
+end
+
+namespace "file2" do
+ file "xyz.rb" do
+ puts "XYZ2"
+ end
+end
+
+namespace "scopedep" do
+ task :prepare do
+ touch "scopedep.rb"
+ puts "PREPARE"
+ end
+ file "scopedep.rb" => [:prepare] do
+ puts "SCOPEDEP"
+ end
+end
+ NAMESPACE
+ end
+
+ def rakefile_nosearch
+ FileUtils.touch 'dummy'
+ end
+
+ def rakefile_rakelib
+ FileUtils.mkdir_p 'rakelib'
+
+ Dir.chdir 'rakelib' do
+ open 'test1.rb', 'w' do |io|
+ io << <<-TEST1
+task :default do
+ puts "TEST1"
+end
+ TEST1
+ end
+
+ open 'test2.rake', 'w' do |io|
+ io << <<-TEST1
+task :default do
+ puts "TEST2"
+end
+ TEST1
+ end
+ end
+ end
+
+ def rakefile_rbext
+ open 'rakefile.rb', 'w' do |io|
+ io << 'task :default do puts "OK" end'
+ end
+ end
+
+ def rakefile_unittest
+ rakefile '# Empty Rakefile for Unit Test'
+
+ readme = File.join 'subdir', 'README'
+ FileUtils.mkdir_p File.dirname readme
+
+ FileUtils.touch readme
+ end
+
+ def rakefile_verbose
+ rakefile <<-VERBOSE
+task :standalone_verbose_true do
+ verbose true
+ sh "#{RUBY} -e '0'"
+end
+
+task :standalone_verbose_false do
+ verbose false
+ sh "#{RUBY} -e '0'"
+end
+
+task :inline_verbose_default do
+ sh "#{RUBY} -e '0'"
+end
+
+task :inline_verbose_false do
+ sh "#{RUBY} -e '0'", :verbose => false
+end
+
+task :inline_verbose_true do
+ sh "#{RUBY} -e '0'", :verbose => true
+end
+
+task :block_verbose_true do
+ verbose(true) do
+ sh "#{RUBY} -e '0'"
+ end
+end
+
+task :block_verbose_false do
+ verbose(false) do
+ sh "#{RUBY} -e '0'"
+ end
+end
+ VERBOSE
+ end
+
+ def rakefile_test_signal
+ rakefile <<-TEST_SIGNAL
+require 'rake/testtask'
+
+Rake::TestTask.new(:a) do |t|
+ t.test_files = ['a_test.rb']
+end
+
+Rake::TestTask.new(:b) do |t|
+ t.test_files = ['b_test.rb']
+end
+
+task :test do
+ Rake::Task[:a].invoke
+ Rake::Task[:b].invoke
+end
+
+task :default => :test
+ TEST_SIGNAL
+ open 'a_test.rb', 'w' do |io|
+ io << 'puts "ATEST"' << "\n"
+ io << '$stdout.flush' << "\n"
+ io << 'Process.kill("TERM", $$)' << "\n"
+ end
+ open 'b_test.rb', 'w' do |io|
+ io << 'puts "BTEST"' << "\n"
+ io << '$stdout.flush' << "\n"
+ end
+ end
+
+ def rakefile_failing_test_task
+ rakefile <<-TEST_TASK
+require 'rake/testtask'
+
+task :default => :test
+Rake::TestTask.new(:test) do |t|
+ t.test_files = ['a_test.rb']
+end
+ TEST_TASK
+ open 'a_test.rb', 'w' do |io|
+ io << "require 'minitest/autorun'\n"
+ io << "class ExitTaskTest < MiniTest::Unit::TestCase\n"
+ io << " def test_exit\n"
+ io << " assert false, 'this should fail'\n"
+ io << " end\n"
+ io << "end\n"
+ end
+ end
+
+ def rakefile_stand_alone_filelist
+ open 'stand_alone_filelist.rb', 'w' do |io|
+ io << "require 'rake/file_list'\n"
+ io << "FL = Rake::FileList['*.rb']\n"
+ io << "puts FL\n"
+ end
+ end
+end
diff --git a/test/rake/support/ruby_runner.rb b/test/rake/support/ruby_runner.rb
new file mode 100644
index 0000000000..404e61a668
--- /dev/null
+++ b/test/rake/support/ruby_runner.rb
@@ -0,0 +1,33 @@
+module RubyRunner
+ include FileUtils
+
+ # Run a shell Ruby command with command line options (using the
+ # 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 and @err
+ def rake(*rake_options)
+ run_ruby @ruby_options + [@rake_exec] + rake_options
+ end
+
+ # Low level ruby command runner ...
+ def run_ruby(option_list)
+ puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
+
+ inn, out, err, wait = Open3.popen3(RUBY, *option_list)
+ inn.close
+
+ @exit = wait ? wait.value : $?
+ @out = out.read
+ @err = err.read
+
+ puts "OUTPUT: [#{@out}]" if @verbose
+ puts "ERROR: [#{@err}]" if @verbose
+ puts "EXIT: [#{@exit.inspect}]" if @verbose
+ puts "PWD: [#{Dir.pwd}]" if @verbose
+ end
+end
diff --git a/test/rake/test_rake_application.rb b/test/rake/test_rake_application.rb
index f2358552c8..aa5ed39f80 100644
--- a/test/rake/test_rake_application.rb
+++ b/test/rake/test_rake_application.rb
@@ -9,13 +9,6 @@ class TestRakeApplication < Rake::TestCase
@app.options.rakelib = []
end
- def test_constant_warning
- _, err = capture_io do @app.instance_eval { const_warning("Task") } end
- assert_match(/warning/i, err)
- assert_match(/deprecated/i, err)
- assert_match(/Task/i, err)
- end
-
def test_display_tasks
@app.options.show_tasks = :tasks
@app.options.show_task_pattern = //
@@ -30,13 +23,14 @@ class TestRakeApplication < Rake::TestCase
@app.terminal_columns = 80
@app.options.show_tasks = :tasks
@app.options.show_task_pattern = //
- @app.last_description = "1234567890" * 8
+ numbers = "1234567890" * 8
+ @app.last_description = numbers
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
+ assert_match(/# #{numbers[0, 65]}\.\.\./, out)
end
def test_display_tasks_with_task_name_wider_than_tty_display
@@ -45,7 +39,7 @@ class TestRakeApplication < Rake::TestCase
@app.options.show_task_pattern = //
task_name = "task name" * 80
@app.last_description = "something short"
- @app.define_task(Rake::Task, task_name )
+ @app.define_task(Rake::Task, task_name)
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
@@ -60,7 +54,7 @@ class TestRakeApplication < Rake::TestCase
description = "something short"
task_name = "task name" * 80
@app.last_description = "something short"
- @app.define_task(Rake::Task, task_name )
+ @app.define_task(Rake::Task, task_name)
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
@@ -79,18 +73,19 @@ class TestRakeApplication < Rake::TestCase
assert_match(/# #{@app.last_description}/, out)
end
- def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
+ def test_truncating_comments_to_a_non_tty
@app.terminal_columns = 80
@app.options.show_tasks = :tasks
@app.options.show_task_pattern = //
@app.tty_output = false
- @app.last_description = "1234567890" * 8
+ numbers = "1234567890" * 8
+ @app.last_description = numbers
@app.define_task(Rake::Task, "t")
out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
assert_match(/^rake t/, out)
- assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
+ assert_match(/# #{numbers[0, 65]}\.\.\./, out)
end
def test_describe_tasks
@@ -121,7 +116,7 @@ class TestRakeApplication < Rake::TestCase
def test_not_finding_rakefile
@app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
- assert( ! @app.instance_eval do have_rakefile end )
+ assert(! @app.instance_eval do have_rakefile end)
assert_nil @app.rakefile
end
@@ -252,7 +247,7 @@ class TestRakeApplication < Rake::TestCase
end
def test_terminal_columns
- old_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
+ old_rake_columns = ENV['RAKE_COLUMNS']
ENV['RAKE_COLUMNS'] = '42'
@@ -260,10 +255,10 @@ class TestRakeApplication < Rake::TestCase
assert_equal 42, app.terminal_columns
ensure
- if old_RAKE_COLUMNS then
+ if old_rake_columns
ENV['RAKE_COLUMNS'].delete
else
- ENV['RAKE_COLUMNS'] = old_RAKE_COLUMNS
+ ENV['RAKE_COLUMNS'] = old_rake_columns
end
end
@@ -296,7 +291,7 @@ class TestRakeApplication < Rake::TestCase
# HACK no assertions
end
- def test_handle_options_should_strip_options_from_ARGV
+ def test_handle_options_should_strip_options_from_argv
assert !@app.options.trace
valid_option = '--trace'
@@ -439,15 +434,6 @@ class TestRakeApplication < Rake::TestCase
ARGV.clear
end
- def test_deprecation_message
- _, err = capture_io do
- @app.deprecate("a", "b", "c")
- end
- assert_match(/'a' is deprecated/i, err)
- 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
diff --git a/test/rake/test_rake_application_options.rb b/test/rake/test_rake_application_options.rb
index 6a8aba652b..b3220b8a97 100644
--- a/test/rake/test_rake_application_options.rb
+++ b/test/rake/test_rake_application_options.rb
@@ -1,6 +1,6 @@
require File.expand_path('../helper', __FILE__)
-TESTING_REQUIRE = [ ]
+TESTING_REQUIRE = []
class TestRakeApplicationOptions < Rake::TestCase
@@ -22,15 +22,12 @@ class TestRakeApplicationOptions < Rake::TestCase
end
def clear_argv
- while ! ARGV.empty?
- ARGV.pop
- end
+ ARGV.pop until ARGV.empty?
end
def test_default_options
opts = command_line
assert_nil opts.backtrace
- assert_nil opts.classic_namespace
assert_nil opts.dryrun
assert_nil opts.ignore_system
assert_nil opts.load_system
@@ -147,7 +144,11 @@ class TestRakeApplicationOptions < Rake::TestCase
def test_rakelib
dirs = %w(A B C).join(File::PATH_SEPARATOR)
- flags(['--rakelibdir', dirs], ["--rakelibdir=#{dirs}"], ['-R', dirs], ["-R#{dirs}"]) do |opts|
+ flags(
+ ['--rakelibdir', dirs],
+ ["--rakelibdir=#{dirs}"],
+ ['-R', dirs],
+ ["-R#{dirs}"]) do |opts|
assert_equal ['A', 'B', 'C'], opts.rakelib
end
end
@@ -186,9 +187,10 @@ class TestRakeApplicationOptions < Rake::TestCase
end
def test_quiet
+ Rake::FileUtilsExt.verbose_flag = true
flags('--quiet', '-q') do |opts|
- assert ! Rake::FileUtilsExt.verbose_flag
- assert ! opts.silent
+ assert ! Rake::FileUtilsExt.verbose_flag, "verbose flag shoud be false"
+ assert ! opts.silent, "should not be silent"
end
end
@@ -199,9 +201,10 @@ class TestRakeApplicationOptions < Rake::TestCase
end
def test_silent
+ Rake::FileUtilsExt.verbose_flag = true
flags('--silent', '-s') do |opts|
- assert ! Rake::FileUtilsExt.verbose_flag
- assert opts.silent
+ assert ! Rake::FileUtilsExt.verbose_flag, "verbose flag should be false"
+ assert opts.silent, "should be silent"
end
end
@@ -353,18 +356,16 @@ class TestRakeApplicationOptions < Rake::TestCase
end
def test_verbose
- out, = capture_io do
- flags('--verbose', '-V') do |opts|
- assert Rake::FileUtilsExt.verbose_flag
- assert ! opts.silent
+ capture_io do
+ flags('--verbose', '-v') do |opts|
+ assert Rake::FileUtilsExt.verbose_flag, "verbose should be true"
+ assert ! opts.silent, "opts should not be silent"
end
end
-
- assert_equal "rake, version #{Rake::VERSION}\n", out
end
def test_version
- out, = capture_io do
+ out, _ = capture_io do
flags '--version', '-V'
end
@@ -373,22 +374,6 @@ class TestRakeApplicationOptions < Rake::TestCase
assert_equal :exit, @exit
end
- def test_classic_namespace
- _, err = capture_io do
- flags(['--classic-namespace'],
- ['-C', '-T', '-P', '-n', '-s', '-t']) do |opts|
- assert opts.classic_namespace
- assert_equal opts.show_tasks, $show_tasks
- assert_equal opts.show_prereqs, $show_prereqs
- assert_equal opts.trace, $trace
- assert_equal opts.dryrun, $dryrun
- assert_equal opts.silent, $silent
- end
- end
-
- assert_match(/deprecated/, err)
- end
-
def test_bad_option
_, err = capture_io do
ex = assert_raises(OptionParser::InvalidOption) do
@@ -418,9 +403,21 @@ class TestRakeApplicationOptions < Rake::TestCase
def test_environment_definition
ENV.delete('TESTKEY')
- command_line("a", "TESTKEY=12")
- assert_equal ["a"], @tasks.sort
- assert '12', ENV['TESTKEY']
+ command_line("TESTKEY=12")
+ assert_equal '12', ENV['TESTKEY']
+ end
+
+ def test_multiline_environment_definition
+ ENV.delete('TESTKEY')
+ command_line("TESTKEY=a\nb\n")
+ assert_equal "a\nb\n", ENV['TESTKEY']
+ end
+
+ def test_environment_and_tasks_together
+ ENV.delete('TESTKEY')
+ command_line("a", "b", "TESTKEY=12")
+ assert_equal ["a", "b"], @tasks.sort
+ assert_equal '12', ENV['TESTKEY']
end
def test_rake_explicit_task_library
diff --git a/test/rake/test_rake_backtrace.rb b/test/rake/test_rake_backtrace.rb
index cfd58f2aac..8db3b5ab54 100644
--- a/test/rake/test_rake_backtrace.rb
+++ b/test/rake/test_rake_backtrace.rb
@@ -1,7 +1,36 @@
require File.expand_path('../helper', __FILE__)
require 'open3'
+class TestBacktraceSuppression < Rake::TestCase
+ def test_bin_rake_suppressed
+ paths = ["something/bin/rake:12"]
+
+ actual = Rake::Backtrace.collapse(paths)
+
+ assert_equal [], actual
+ end
+
+ def test_system_dir_suppressed
+ path = RbConfig::CONFIG['rubylibprefix']
+ paths = [path + ":12"]
+
+ actual = Rake::Backtrace.collapse(paths)
+
+ assert_equal [], actual
+ end
+
+ def test_near_system_dir_isnt_suppressed
+ path = RbConfig::CONFIG['rubylibprefix']
+ paths = [" " + path + ":12"]
+
+ actual = Rake::Backtrace.collapse(paths)
+
+ assert_equal paths, actual
+ end
+end
+
class TestRakeBacktrace < Rake::TestCase
+ include RubyRunner
def setup
super
@@ -10,15 +39,9 @@ class TestRakeBacktrace < Rake::TestCase
Dir.pwd =~ Rake::Backtrace::SUPPRESS_PATTERN
end
- # TODO: factor out similar code in test_rake_functional.rb
- def rake(*args)
- Open3.popen3(RUBY, "-I", @rake_lib, @rake_exec, *args) { |_, _, err, _|
- err.read
- }
- end
-
- def invoke(task_name)
- rake task_name.to_s
+ def invoke(*args)
+ rake(*args)
+ @err
end
def test_single_collapse
@@ -28,7 +51,7 @@ class TestRakeBacktrace < Rake::TestCase
end
}
- lines = invoke(:foo).split("\n")
+ lines = invoke("foo").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "foooo!", lines[1]
@@ -46,7 +69,7 @@ class TestRakeBacktrace < Rake::TestCase
end
}
- lines = invoke(:foo).split("\n")
+ lines = invoke("foo").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "barrr!", lines[1]
@@ -62,12 +85,12 @@ class TestRakeBacktrace < Rake::TestCase
end
}
- lines = rake("baz").split("\n")
+ lines = invoke("baz").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "bazzz!", lines[1]
assert_something_matches %r!Rakefile!i, lines
- lines = rake("--suppress-backtrace", ".ak.file", "baz").split("\n")
+ lines = invoke("--suppress-backtrace", ".ak.file", "baz").split("\n")
assert_equal "rake aborted!", lines[0]
assert_equal "bazzz!", lines[1]
refute_match %r!Rakefile!i, lines[2]
@@ -83,7 +106,8 @@ class TestRakeBacktrace < Rake::TestCase
return
end
end
- flunk "expected #{pattern.inspect} to match something in:\n #{lines.join("\n ")}"
+ flunk "expected #{pattern.inspect} to match something in:\n" +
+ "#{lines.join("\n ")}"
end
end
diff --git a/test/rake/test_rake_clean.rb b/test/rake/test_rake_clean.rb
index 1541c69359..a6539fb213 100644
--- a/test/rake/test_rake_clean.rb
+++ b/test/rake/test_rake_clean.rb
@@ -2,13 +2,45 @@ require File.expand_path('../helper', __FILE__)
require 'rake/clean'
class TestRakeClean < Rake::TestCase
- include Rake
def test_clean
load 'rake/clean.rb', true
- assert Task['clean'], "Should define clean"
- assert Task['clobber'], "Should define clobber"
- assert Task['clobber'].prerequisites.include?("clean"),
+ assert Rake::Task['clean'], "Should define clean"
+ assert Rake::Task['clobber'], "Should define clobber"
+ assert Rake::Task['clobber'].prerequisites.include?("clean"),
"Clobber should require clean"
end
+
+ def test_cleanup
+ file_name = create_undeletable_file
+
+ out, _ = capture_io do
+ Rake::Cleaner.cleanup(file_name, verbose: false)
+ end
+ assert_match(/failed to remove/i, out)
+
+ ensure
+ remove_undeletable_file
+ end
+
+ private
+
+ def create_undeletable_file
+ dir_name = File.join(@tempdir, "deletedir")
+ file_name = File.join(dir_name, "deleteme")
+ FileUtils.mkdir(dir_name)
+ FileUtils.touch(file_name)
+ FileUtils.chmod(0, file_name)
+ FileUtils.chmod(0, dir_name)
+ file_name
+ end
+
+ def remove_undeletable_file
+ dir_name = File.join(@tempdir, "deletedir")
+ file_name = File.join(dir_name, "deleteme")
+ FileUtils.chmod(0777, dir_name)
+ FileUtils.chmod(0777, file_name)
+ Rake::Cleaner.cleanup(file_name, verbose: false)
+ Rake::Cleaner.cleanup(dir_name, verbose: false)
+ end
end
diff --git a/test/rake/test_rake_definitions.rb b/test/rake/test_rake_definitions.rb
index 839c40419e..4b2de9d1d2 100644
--- a/test/rake/test_rake_definitions.rb
+++ b/test/rake/test_rake_definitions.rb
@@ -34,12 +34,12 @@ class TestRakeDefinitions < Rake::TestCase
t = Task[n1]
assert Task === t, "Should be a Task"
assert_equal n1.to_s, t.name
- assert_equal [n2.to_s], t.prerequisites.collect{|n| n.to_s}
+ assert_equal [n2.to_s], t.prerequisites.map { |n| n.to_s }
t.invoke
t2 = Task[n2]
assert_equal FileList[], t2.prerequisites
t3 = Task[n3]
- assert_equal [n1.to_s, n2.to_s], t3.prerequisites.collect{|n|n.to_s}
+ assert_equal [n1.to_s, n2.to_s], t3.prerequisites.map { |n| n.to_s }
end
def test_incremental_definitions
@@ -77,4 +77,3 @@ class TestRakeDefinitions < Rake::TestCase
end
end
-
diff --git a/test/rake/test_rake_dsl.rb b/test/rake/test_rake_dsl.rb
index de83b89ab4..ad52f760b6 100644
--- a/test/rake/test_rake_dsl.rb
+++ b/test/rake/test_rake_dsl.rb
@@ -33,45 +33,8 @@ class TestRakeDsl < Rake::TestCase
refute_nil Rake::Task["bob:t"]
end
- class Foo
- def initialize
- task :foo_deprecated_a => "foo_deprecated_b" do
- print "a"
- end
- file "foo_deprecated_b" do
- print "b"
- end
- end
- end
-
- def test_deprecated_object_dsl
- out, err = capture_io do
- Foo.new
- Rake.application.invoke_task :foo_deprecated_a
- end
- assert_equal("ba", out)
- assert_match(/deprecated/, err)
- assert_match(/Foo\#task/, err)
- assert_match(/Foo\#file/, err)
- assert_match(/test_rake_dsl\.rb:\d+/, err)
- end
-
def test_no_commands_constant
assert ! defined?(Commands), "should not define Commands"
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
diff --git a/test/rake/test_rake_file_creation_task.rb b/test/rake/test_rake_file_creation_task.rb
index d486d2f0d4..d8dcd965a3 100644
--- a/test/rake/test_rake_file_creation_task.rb
+++ b/test/rake/test_rake_file_creation_task.rb
@@ -21,7 +21,7 @@ class TestRakeFileCreationTask < Rake::TestCase
FileUtils.rm_rf fc_task.name
assert fc_task.needed?, "file should be needed"
FileUtils.mkdir fc_task.name
- assert_equal nil, fc_task.prerequisites.collect{|n| Task[n].timestamp}.max
+ assert_equal nil, fc_task.prerequisites.map { |n| Task[n].timestamp }.max
assert ! fc_task.needed?, "file should not be needed"
end
@@ -51,6 +51,6 @@ class TestRakeFileCreationTask < Rake::TestCase
def test_very_early_timestamp
t1 = Rake.application.intern(FileCreationTask, OLDFILE)
assert t1.timestamp < Time.now
- assert t1.timestamp < Time.now - 1000000
+ assert t1.timestamp < Time.now - 1_000_000
end
end
diff --git a/test/rake/test_rake_file_list.rb b/test/rake/test_rake_file_list.rb
index 08939fb6ed..899f3bc509 100644
--- a/test/rake/test_rake_file_list.rb
+++ b/test/rake/test_rake_file_list.rb
@@ -166,7 +166,7 @@ class TestRakeFileList < Rake::TestCase
def test_excluding_via_block
fl = FileList['a.c', 'b.c', 'xyz.c']
fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
- assert fl.exclude?("xyz.c"), "Should exclude xyz.c"
+ assert fl.excluded_from_list?("xyz.c"), "Should exclude xyz.c"
assert_equal ['a.c', 'b.c'], fl
end
@@ -404,24 +404,24 @@ class TestRakeFileList < Rake::TestCase
def test_exclude_with_alternate_file_seps
fl = FileList.new
- assert fl.exclude?("x/CVS/y")
- assert fl.exclude?("x\\CVS\\y")
- assert fl.exclude?("x/.svn/y")
- assert fl.exclude?("x\\.svn\\y")
- assert fl.exclude?("x/core")
- assert fl.exclude?("x\\core")
+ assert fl.excluded_from_list?("x/CVS/y")
+ assert fl.excluded_from_list?("x\\CVS\\y")
+ assert fl.excluded_from_list?("x/.svn/y")
+ assert fl.excluded_from_list?("x\\.svn\\y")
+ assert fl.excluded_from_list?("x/core")
+ assert fl.excluded_from_list?("x\\core")
end
def test_add_default_exclude_list
fl = FileList.new
fl.exclude(/~\d+$/)
- assert fl.exclude?("x/CVS/y")
- assert fl.exclude?("x\\CVS\\y")
- assert fl.exclude?("x/.svn/y")
- assert fl.exclude?("x\\.svn\\y")
- assert fl.exclude?("x/core")
- assert fl.exclude?("x\\core")
- assert fl.exclude?("x/abc~1")
+ assert fl.excluded_from_list?("x/CVS/y")
+ assert fl.excluded_from_list?("x\\CVS\\y")
+ assert fl.excluded_from_list?("x/.svn/y")
+ assert fl.excluded_from_list?("x\\.svn\\y")
+ assert fl.excluded_from_list?("x/core")
+ assert fl.excluded_from_list?("x\\core")
+ assert fl.excluded_from_list?("x/abc~1")
end
def test_basic_array_functions
@@ -482,12 +482,12 @@ class TestRakeFileList < Rake::TestCase
a = ['b', 'a']
b = ['b', 'b']
c = ['b', 'c']
- assert_equal( 1, fl <=> a )
- assert_equal( 0, fl <=> b )
- assert_equal( -1, fl <=> c )
- assert_equal( -1, a <=> fl )
- assert_equal( 0, b <=> fl )
- assert_equal( 1, c <=> fl )
+ assert_equal(1, fl <=> a)
+ assert_equal(0, fl <=> b)
+ assert_equal(-1, fl <=> c)
+ assert_equal(-1, a <=> fl)
+ assert_equal(0, b <=> fl)
+ assert_equal(1, c <=> fl)
end
def test_array_equality
@@ -503,7 +503,7 @@ class TestRakeFileList < Rake::TestCase
def test_enumeration_methods
a = FileList['a', 'b']
- b = a.collect { |it| it.upcase }
+ b = a.map { |it| it.upcase }
assert_equal ['A', 'B'], b
assert_equal FileList, b.class
@@ -519,7 +519,7 @@ class TestRakeFileList < Rake::TestCase
assert_equal ['a', 'b'], b
assert_equal FileList, b.class
- b = a.find_all { |it| it == 'b'}
+ b = a.select { |it| it == 'b' }
assert_equal ['b'], b
assert_equal FileList, b.class
@@ -609,7 +609,7 @@ class TestRakeFileList < Rake::TestCase
assert_equal FileList, r.class
f = FileList['a', 'b', 'c', 'd']
- r = f.values_at(1,3)
+ r = f.values_at(1, 3)
assert_equal ['b', 'd'], r
assert_equal FileList, r.class
end
@@ -625,4 +625,3 @@ class TestRakeFileList < Rake::TestCase
end
end
-
diff --git a/test/rake/test_rake_file_task.rb b/test/rake/test_rake_file_task.rb
index 0ed32e5655..fa3241b78b 100644
--- a/test/rake/test_rake_file_task.rb
+++ b/test/rake/test_rake_file_task.rb
@@ -26,7 +26,7 @@ class TestRakeFileTask < Rake::TestCase
open(ftask.name, "w") { |f| f.puts "HI" }
- assert_equal nil, ftask.prerequisites.collect{|n| Task[n].timestamp}.max
+ assert_equal nil, ftask.prerequisites.map { |n| Task[n].timestamp }.max
assert ! ftask.needed?, "file should not be needed"
ensure
File.delete(ftask.name) rescue nil
@@ -55,16 +55,16 @@ class TestRakeFileTask < Rake::TestCase
task(name => :phony)
- assert ! t1.needed?, "unless the non-file task has a timestamp"
+ assert t1.needed?, "unless the non-file task has a timestamp"
end
def test_file_times_old_depends_on_new
create_timed_files(OLDFILE, NEWFILE)
- t1 = Rake.application.intern(FileTask,OLDFILE).enhance([NEWFILE])
+ t1 = Rake.application.intern(FileTask, OLDFILE).enhance([NEWFILE])
t2 = Rake.application.intern(FileTask, NEWFILE)
assert ! t2.needed?, "Should not need to build new file"
- preq_stamp = t1.prerequisites.collect{|t| Task[t].timestamp}.max
+ preq_stamp = t1.prerequisites.map { |t| Task[t].timestamp }.max
assert_equal t2.timestamp, preq_stamp
assert t1.timestamp < preq_stamp, "T1 should be older"
assert t1.needed?, "Should need to rebuild old file because of new"
@@ -79,7 +79,7 @@ class TestRakeFileTask < Rake::TestCase
Task[:obj].invoke
Task[NEWFILE].invoke
- assert ! @runs.include?(NEWFILE)
+ assert @runs.include?(NEWFILE)
end
def test_existing_file_depends_on_non_existing_file
@@ -112,7 +112,7 @@ class TestRakeFileTask < Rake::TestCase
Task[NEWFILE].invoke
rescue Exception
end
- assert( ! File.exist?(NEWFILE), "NEWFILE should be deleted")
+ assert(! File.exist?(NEWFILE), "NEWFILE should be deleted")
end
def load_phony
diff --git a/test/rake/test_rake_file_utils.rb b/test/rake/test_rake_file_utils.rb
index 90565e3ebd..37d33dc39a 100644
--- a/test/rake/test_rake_file_utils.rb
+++ b/test/rake/test_rake_file_utils.rb
@@ -44,15 +44,19 @@ class TestRakeFileUtils < Rake::TestCase
class BadLink
include Rake::FileUtilsExt
attr_reader :cp_args
+
def initialize(klass)
@failure_class = klass
end
+
def cp(*args)
@cp_args = args
end
+
def ln(*args)
fail @failure_class, "ln not supported"
end
+
public :safe_ln
end
@@ -94,7 +98,7 @@ class TestRakeFileUtils < Rake::TestCase
assert_equal true, nowrite
nowrite false
assert_equal false, nowrite
- nowrite(true){
+ nowrite(true) {
assert_equal true, nowrite
}
assert_equal false, nowrite
@@ -250,7 +254,7 @@ class TestRakeFileUtils < Rake::TestCase
assert_equal ['..', 'a', 'b'], Rake::FileUtilsExt.split_all('../a/b')
end
- def command name, text
+ def command(name, text)
open name, 'w', 0750 do |io|
io << text
end
diff --git a/test/rake/test_rake_ftp_file.rb b/test/rake/test_rake_ftp_file.rb
index 7f41faf0dd..5749b8a5ef 100644
--- a/test/rake/test_rake_ftp_file.rb
+++ b/test/rake/test_rake_ftp_file.rb
@@ -5,10 +5,11 @@ require 'rake/contrib/ftptools'
class FakeDate
def self.today
- Date.new(2003,10,3)
+ Date.new(2003, 10, 3)
end
+
def self.now
- Time.local(2003,10,3,12,00,00)
+ Time.local(2003, 10, 3, 12, 00, 00)
end
end
@@ -17,43 +18,57 @@ class TestRakeFtpFile < Rake::TestCase
def setup
super
- Rake::FtpFile.class_eval { @date_class = FakeDate; @time_class = FakeDate }
+ Rake::FtpFile.class_eval {
+ @date_class = FakeDate
+ @time_class = FakeDate
+ }
end
def test_general
- file = Rake::FtpFile.new("here", "-rw-r--r-- 1 a279376 develop 121770 Mar 6 14:50 wiki.pl")
+ file = Rake::FtpFile.new(
+ "here",
+ "-rw-r--r-- 1 a279376 develop 121770 Mar 6 14:50 wiki.pl")
assert_equal "wiki.pl", file.name
assert_equal "here/wiki.pl", file.path
assert_equal "a279376", file.owner
assert_equal "develop", file.group
assert_equal 0644, file.mode
- assert_equal 121770, file.size
- assert_equal Time.mktime(2003,3,6,14,50,0,0), file.time
+ assert_equal 121_770, file.size
+ assert_equal Time.mktime(2003, 3, 6, 14, 50, 0, 0), file.time
assert ! file.directory?
assert ! file.symlink?
end
def test_far_date
- file = Rake::FtpFile.new(".", "drwxr-xr-x 3 a279376 develop 4096 Nov 26 2001 vss")
- assert_equal Time.mktime(2001,11,26,0,0,0,0), file.time
+ file = Rake::FtpFile.new(
+ ".",
+ "drwxr-xr-x 3 a279376 develop 4096 Nov 26 2001 vss")
+ assert_equal Time.mktime(2001, 11, 26, 0, 0, 0, 0), file.time
end
def test_close_date
- file = Rake::FtpFile.new(".", "drwxr-xr-x 3 a279376 develop 4096 Nov 26 15:35 vss")
- assert_equal Time.mktime(2002,11,26,15,35,0,0), file.time
+ file = Rake::FtpFile.new(
+ ".",
+ "drwxr-xr-x 3 a279376 develop 4096 Nov 26 15:35 vss")
+ assert_equal Time.mktime(2002, 11, 26, 15, 35, 0, 0), file.time
end
def test_directory
- file = Rake::FtpFile.new(".", "drwxrwxr-x 9 a279376 develop 4096 Mar 13 14:32 working")
+ file = Rake::FtpFile.new(
+ ".",
+ "drwxrwxr-x 9 a279376 develop 4096 Mar 13 14:32 working")
assert file.directory?
assert !file.symlink?
end
def test_symlink
- file = Rake::FtpFile.new(".", "lrwxrwxrwx 1 a279376 develop 64 Mar 26 2002 xtrac -> /home/a279376/working/ics/development/java/com/fmr/fwp/ics/xtrac")
+ file = Rake::FtpFile.new(
+ ".",
+ "lrwxrwxrwx 1 a279376 develop 64 Mar 26 2002 " +
+ "xtrac -> /home/a279376/working/ics/development/java/" +
+ "com/fmr/fwp/ics/xtrac")
assert_equal 'xtrac', file.name
assert file.symlink?
assert !file.directory?
end
end
-
diff --git a/test/rake/test_rake_functional.rb b/test/rake/test_rake_functional.rb
index 23249b97fb..f2ce2f78f0 100644
--- a/test/rake/test_rake_functional.rb
+++ b/test/rake/test_rake_functional.rb
@@ -3,13 +3,11 @@ require 'fileutils'
require 'open3'
class TestRakeFunctional < Rake::TestCase
+ include RubyRunner
def setup
super
- @ruby_options = ["-I#{@rake_lib}", "-I."]
- @verbose = ENV['VERBOSE']
-
if @verbose
puts
puts
@@ -68,7 +66,7 @@ class TestRakeFunctional < Rake::TestCase
rake "--describe"
- assert_match %r{^rake a\n *A / A2 *$}m, @out
+ assert_match %r{^rake a\n *A\n *A2 *$}m, @out
assert_match %r{^rake b\n *B *$}m, @out
assert_match %r{^rake d\n *x{80}}m, @out
refute_match %r{^rake c\n}m, @out
@@ -420,8 +418,10 @@ class TestRakeFunctional < Rake::TestCase
status = $?
if @verbose
puts " SIG status = #{$?.inspect}"
- puts " SIG status.respond_to?(:signaled?) = #{$?.respond_to?(:signaled?).inspect}"
- puts " SIG status.signaled? = #{status.signaled?}" if status.respond_to?(:signaled?)
+ puts " SIG status.respond_to?(:signaled?) = " +
+ "#{$?.respond_to?(:signaled?).inspect}"
+ puts " SIG status.signaled? = #{status.signaled?}" if
+ status.respond_to?(:signaled?)
end
status.respond_to?(:signaled?) && status.signaled?
end
@@ -463,34 +463,4 @@ class TestRakeFunctional < Rake::TestCase
RUBY_VERSION < "1.9" || defined?(JRUBY_VERSION)
end
- # Run a shell Ruby command with command line options (using the
- # 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 and @err
- def rake(*rake_options)
- run_ruby @ruby_options + [@rake_exec] + rake_options
- end
-
- # Low level ruby command runner ...
- def run_ruby(option_list)
- puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
-
- inn, out, err, wait = Open3.popen3(RUBY, *option_list)
- inn.close
-
- @exit = wait ? wait.value : $?
- @out = out.read
- @err = err.read
-
- puts "OUTPUT: [#{@out}]" if @verbose
- puts "ERROR: [#{@err}]" if @verbose
- puts "EXIT: [#{@exit.inspect}]" if @verbose
- puts "PWD: [#{Dir.pwd}]" if @verbose
- end
-
end
diff --git a/test/rake/test_rake_invocation_chain.rb b/test/rake/test_rake_invocation_chain.rb
index 1aab1eac81..0176339bd4 100644
--- a/test/rake/test_rake_invocation_chain.rb
+++ b/test/rake/test_rake_invocation_chain.rb
@@ -1,11 +1,12 @@
require File.expand_path('../helper', __FILE__)
class TestRakeInvocationChain < Rake::TestCase
+ include Rake
def setup
super
- @empty = Rake::InvocationChain::EMPTY
+ @empty = InvocationChain.empty
@first_member = "A"
@second_member = "B"
@@ -13,7 +14,19 @@ class TestRakeInvocationChain < Rake::TestCase
@two = @one.append(@second_member)
end
- def test_append
+ def test_conj_on_invocation_chains
+ list = InvocationChain.empty.conj("B").conj("A")
+ assert_equal InvocationChain.make("A", "B"), list
+ assert_equal InvocationChain, list.class
+ end
+
+ def test_make_on_invocation_chains
+ assert_equal @empty, InvocationChain.make()
+ assert_equal @one, InvocationChain.make(@first_member)
+ assert_equal @two, InvocationChain.make(@second_member, @first_member)
+ end
+
+ def test_append_with_one_argument
chain = @empty.append("A")
assert_equal 'TOP => A', chain.to_s # HACK
@@ -49,4 +62,3 @@ class TestRakeInvocationChain < Rake::TestCase
end
end
-
diff --git a/test/rake/test_rake_linked_list.rb b/test/rake/test_rake_linked_list.rb
new file mode 100644
index 0000000000..10957fba6d
--- /dev/null
+++ b/test/rake/test_rake_linked_list.rb
@@ -0,0 +1,84 @@
+require File.expand_path('../helper', __FILE__)
+
+class TestLinkedList < Rake::TestCase
+ include Rake
+
+ def test_empty_list
+ empty = LinkedList::EMPTY
+ assert empty.empty?, "should be empty"
+ end
+
+ def test_list_with_one_item
+ list = LinkedList.make(:one)
+ assert ! list.empty?, "should not be empty"
+ assert_equal :one, list.head
+ assert_equal LinkedList::EMPTY, list.tail
+ end
+
+ def test_make_with_no_arguments
+ empty = LinkedList.make()
+ assert_equal LinkedList::EMPTY, empty
+ end
+
+ def test_make_with_one_argument
+ list = LinkedList.make(:one)
+ assert ! list.empty?
+ assert_equal :one, list.head
+ assert_equal LinkedList::EMPTY, list.tail
+ end
+
+ def test_make_with_two_arguments
+ list = LinkedList.make(:one, :two)
+ assert ! list.empty?
+ assert_equal :one, list.head
+ assert_equal :two, list.tail.head
+ assert_equal LinkedList::EMPTY, list.tail.tail
+ end
+
+ def test_list_with_several_items
+ list = LinkedList.make(:one, :two, :three)
+
+ assert ! list.empty?, "should not be empty"
+ assert_equal :one, list.head
+ assert_equal :two, list.tail.head
+ assert_equal :three, list.tail.tail.head
+ assert_equal LinkedList::EMPTY, list.tail.tail.tail
+ end
+
+ def test_lists_are_structurally_equivalent
+ list = LinkedList.make(1, 2, 3)
+ same = LinkedList.make(1, 2, 3)
+ diff = LinkedList.make(1, 2, 4)
+ short = LinkedList.make(1, 2)
+
+ assert_equal list, same
+ refute_equal list, diff
+ refute_equal list, short
+ refute_equal short, list
+ end
+
+ def test_converstion_to_string
+ list = LinkedList.make(:one, :two, :three)
+ assert_equal "LL(one, two, three)", list.to_s
+ assert_equal "LL()", LinkedList.make().to_s
+ end
+
+ def test_converstion_with_inspect
+ list = LinkedList.make(:one, :two, :three)
+ assert_equal "LL(:one, :two, :three)", list.inspect
+ assert_equal "LL()", LinkedList.make().inspect
+ end
+
+ def test_lists_are_enumerable
+ list = LinkedList.make(1, 2, 3)
+ new_list = list.map { |item| item + 10 }
+ expected = [11, 12, 13]
+ assert_equal expected, new_list
+ end
+
+ def test_conjunction
+ list = LinkedList.make.conj("C").conj("B").conj("A")
+ assert_equal LinkedList.make("A", "B", "C"), list
+ end
+
+end
diff --git a/test/rake/test_rake_makefile_loader.rb b/test/rake/test_rake_makefile_loader.rb
index bd3c99ba71..9e9265ad18 100644
--- a/test/rake/test_rake_makefile_loader.rb
+++ b/test/rake/test_rake_makefile_loader.rb
@@ -38,7 +38,9 @@ g\ 0: g1 g\ 2 g\ 3 g4
assert_equal %w(d1 d2).sort, Task['d'].prerequisites.sort
assert_equal %w(e1 f1).sort, Task['e'].prerequisites.sort
assert_equal %w(e1 f1).sort, Task['f'].prerequisites.sort
- assert_equal ["g1", "g 2", "g 3", "g4"].sort, Task['g 0'].prerequisites.sort
+ assert_equal(
+ ["g1", "g 2", "g 3", "g4"].sort,
+ Task['g 0'].prerequisites.sort)
assert_equal 7, Task.tasks.size
end
end
diff --git a/test/rake/test_rake_multi_task.rb b/test/rake/test_rake_multi_task.rb
index 22d13d27a0..fe10caf1db 100644
--- a/test/rake/test_rake_multi_task.rb
+++ b/test/rake/test_rake_multi_task.rb
@@ -49,11 +49,10 @@ class TestRakeMultiTask < Rake::TestCase
end
def test_multitasks_with_parameters
- task :a, [:arg] do |t,args| add_run(args[:arg]) end
- multitask :b, [:arg] => [:a] do |t,args| add_run(args[:arg]+'mt') end
+ task :a, [:arg] do |t, args| add_run(args[:arg]) end
+ multitask :b, [:arg] => [:a] do |t, args| add_run(args[:arg] + 'mt') end
Task[:b].invoke "b"
assert @runs[0] == "b"
assert @runs[1] == "bmt"
end
end
-
diff --git a/test/rake/test_rake_name_space.rb b/test/rake/test_rake_name_space.rb
index b1f2ed00b2..3ab977d013 100644
--- a/test/rake/test_rake_name_space.rb
+++ b/test/rake/test_rake_name_space.rb
@@ -38,6 +38,6 @@ class TestRakeNameSpace < Rake::TestCase
assert_equal ["n:nn:z", "n:x", "n:y"],
ns.tasks.map { |tsk| tsk.name }
- assert_equal ["n:nn:z"], nns.tasks.map {|t| t.name}
+ assert_equal ["n:nn:z"], nns.tasks.map { |t| t.name }
end
end
diff --git a/test/rake/test_rake_path_map.rb b/test/rake/test_rake_path_map.rb
index 32ffb854b1..b76a9491f9 100644
--- a/test/rake/test_rake_path_map.rb
+++ b/test/rake/test_rake_path_map.rb
@@ -52,7 +52,7 @@ class TestRakePathMap < Rake::TestCase
assert_equal "", "dir/.depends".pathmap("%x")
end
- def test_X_returns_everything_but_extension
+ def test_x_returns_everything_but_extension
assert_equal "abc", "abc".pathmap("%X")
assert_equal "abc", "abc.rb".pathmap("%X")
assert_equal "abc.xyz", "abc.xyz.rb".pathmap("%X")
@@ -142,16 +142,27 @@ class TestRakePathMap < Rake::TestCase
def test_complex_patterns
sep = "".pathmap("%s")
- assert_equal "dir/abc.rb", "dir/abc.rb".pathmap("%d/%n%x")
- assert_equal "./abc.rb", "abc.rb".pathmap("%d/%n%x")
- assert_equal "Your file extension is '.rb'",
- "dir/abc.rb".pathmap("Your file extension is '%x'")
- assert_equal "bin/org/onstepback/proj/A.class",
- "src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class")
- assert_equal "src_work/bin/org/onstepback/proj/A.class",
- "src_work/src/org/onstepback/proj/A.java".pathmap('%{\bsrc\b,bin}X.class')
- assert_equal ".depends.bak", ".depends".pathmap("%X.bak")
- assert_equal "d#{sep}a/b/c#{sep}file.txt", "a/b/c/d/file.txt".pathmap("%-1d%s%3d%s%f")
+ assert_equal(
+ "dir/abc.rb",
+ "dir/abc.rb".pathmap("%d/%n%x"))
+ assert_equal(
+ "./abc.rb",
+ "abc.rb".pathmap("%d/%n%x"))
+ assert_equal(
+ "Your file extension is '.rb'",
+ "dir/abc.rb".pathmap("Your file extension is '%x'"))
+ assert_equal(
+ "bin/org/onstepback/proj/A.class",
+ "src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class"))
+ assert_equal(
+ "src_work/bin/org/onstepback/proj/A.class",
+ "src_work/src/org/onstepback/proj/A.java"
+ .pathmap('%{\bsrc\b,bin}X.class'))
+ assert_equal(
+ ".depends.bak",
+ ".depends".pathmap("%X.bak"))
+ assert_equal(
+ "d#{sep}a/b/c#{sep}file.txt",
+ "a/b/c/d/file.txt".pathmap("%-1d%s%3d%s%f"))
end
end
-
diff --git a/test/rake/test_rake_rake_test_loader.rb b/test/rake/test_rake_rake_test_loader.rb
index 7b5337c234..0485c4c8ac 100644
--- a/test/rake/test_rake_rake_test_loader.rb
+++ b/test/rake/test_rake_rake_test_loader.rb
@@ -3,7 +3,7 @@ require File.expand_path('../helper', __FILE__)
class TestRakeRakeTestLoader < Rake::TestCase
def test_pattern
- orig_LOADED_FEATURES = $:.dup
+ orig_loaded_features = $:.dup
FileUtils.touch 'foo.rb'
FileUtils.touch 'test_a.rb'
FileUtils.touch 'test_b.rb'
@@ -14,8 +14,7 @@ class TestRakeRakeTestLoader < Rake::TestCase
assert_equal %w[-v], ARGV
ensure
- $:.replace orig_LOADED_FEATURES
+ $:.replace orig_loaded_features
end
end
-
diff --git a/test/rake/test_rake_rdoc_task.rb b/test/rake/test_rake_rdoc_task.rb
deleted file mode 100644
index 0d24ef04a3..0000000000
--- a/test/rake/test_rake_rdoc_task.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-require File.expand_path('../helper', __FILE__)
-begin
- old_stderr = $stderr
- dev_null = File.exist?('/dev/null') ? '/dev/null' : 'NUL'
- $stderr = open dev_null, 'w'
- require 'rake/rdoctask'
-ensure
- $stderr.close
- $stderr = old_stderr
-end
-
-class TestRakeRDocTask < Rake::TestCase
- include Rake
-
- def setup
- super
-
- Task.clear
- end
-
- def test_tasks_creation
- Rake::RDocTask.new
- assert Task[:rdoc]
- assert Task[:clobber_rdoc]
- assert Task[:rerdoc]
- end
-
- def test_tasks_creation_with_custom_name_symbol
- rd = Rake::RDocTask.new(:rdoc_dev)
- assert Task[:rdoc_dev]
- assert Task[:clobber_rdoc_dev]
- assert Task[:rerdoc_dev]
- assert_equal :rdoc_dev, rd.name
- end
-
- def test_tasks_creation_with_custom_name_string
- rd = Rake::RDocTask.new("rdoc_dev")
- assert Task[:rdoc_dev]
- assert Task[:clobber_rdoc_dev]
- assert Task[:rerdoc_dev]
- assert_equal "rdoc_dev", rd.name
- end
-
- def test_tasks_creation_with_custom_name_hash
- options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" }
- rd = Rake::RDocTask.new(options)
- assert Task[:"rdoc"]
- assert Task[:"rdoc:clean"]
- assert Task[:"rdoc:force"]
- assert_raises(RuntimeError) { Task[:clobber_rdoc] }
- assert_equal options, rd.name
- end
-
- def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
- Rake::RDocTask.new(:clobber_rdoc => "rdoc:clean")
- assert Task[:rdoc]
- assert Task[:"rdoc:clean"]
- assert Task[:rerdoc]
- end
-
- def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
- assert_raises(ArgumentError) do
- Rake::RDocTask.new(:foo => "bar")
- end
-
- begin
- Rake::RDocTask.new(:foo => "bar")
- rescue ArgumentError => e
- assert_match(/foo/, e.message)
- end
- end
-
- def test_inline_source_option_is_only_appended_if_option_not_already_given
- rd = Rake::RDocTask.new
- rd.options << '--inline-source'
- assert_equal 1, rd.option_list.grep('--inline-source').size
-
- rd = Rake::RDocTask.new
- rd.options << '-S'
- assert_equal 1, rd.option_list.grep('-S').size
- assert_equal 0, rd.option_list.grep('--inline-source').size
- end
-end
diff --git a/test/rake/test_rake_reduce_compat.rb b/test/rake/test_rake_reduce_compat.rb
index 6da8e4259c..d295266540 100644
--- a/test/rake/test_rake_reduce_compat.rb
+++ b/test/rake/test_rake_reduce_compat.rb
@@ -2,19 +2,11 @@ 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)
- Open3.popen3(RUBY, "-I", @rake_lib, @rake_exec, *args) { |_, out, _, _|
- out.read
- }
- end
+ include RubyRunner
def invoke_normal(task_name)
rake task_name.to_s
- end
-
- def invoke_reduce_compat(task_name)
- rake "--reduce-compat", task_name.to_s
+ @out
end
def test_no_deprecated_dsl
@@ -28,38 +20,7 @@ class TestRakeReduceCompat < Rake::TestCase
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)
+ assert_equal "nil", invoke_normal(:check_task).chomp
+ assert_equal "nil", invoke_normal(:check_file).chomp
end
end
diff --git a/test/rake/test_rake_rules.rb b/test/rake/test_rake_rules.rb
index 664aa983e5..376b99889c 100644
--- a/test/rake/test_rake_rules.rb
+++ b/test/rake/test_rake_rules.rb
@@ -102,7 +102,7 @@ class TestRakeRules < Rake::TestCase
verbose(false) do
create_file(".foo")
- rule '.o' => lambda{".foo"} do |t|
+ rule '.o' => lambda { ".foo" } do |t|
@runs << "#{t.name} - #{t.source}"
end
Task[OBJFILE].invoke
@@ -113,7 +113,7 @@ class TestRakeRules < Rake::TestCase
def test_file_names_containing_percent_can_be_wrapped_in_lambda
verbose(false) do
create_file("foo%x")
- rule '.o' => lambda{"foo%x"} do |t|
+ rule '.o' => lambda { "foo%x" } do |t|
@runs << "#{t.name} - #{t.source}"
end
Task[OBJFILE].invoke
@@ -186,7 +186,7 @@ class TestRakeRules < Rake::TestCase
def test_rule_with_two_sources_runs_if_both_sources_are_present
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
- rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
+ rule OBJFILE => [lambda { SRCFILE }, lambda { SRCFILE2 }] do
@runs << :RULE
end
Task[OBJFILE].invoke
@@ -196,7 +196,7 @@ class TestRakeRules < Rake::TestCase
def test_rule_with_two_sources_but_one_missing_does_not_run
create_timed_files(OBJFILE, SRCFILE)
delete_file(SRCFILE2)
- rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
+ rule OBJFILE => [lambda { SRCFILE }, lambda { SRCFILE2 }] do
@runs << :RULE
end
Task[OBJFILE].invoke
@@ -222,10 +222,10 @@ class TestRakeRules < Rake::TestCase
def test_second_rule_runs_when_first_rule_doesnt
create_timed_files(OBJFILE, SRCFILE)
delete_file(SRCFILE2)
- rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
+ rule OBJFILE => [lambda { SRCFILE }, lambda { SRCFILE2 }] do
@runs << :RULE1
end
- rule OBJFILE => [lambda{SRCFILE}] do
+ rule OBJFILE => [lambda { SRCFILE }] do
@runs << :RULE2
end
Task[OBJFILE].invoke
@@ -234,10 +234,10 @@ class TestRakeRules < Rake::TestCase
def test_second_rule_doest_run_if_first_triggers
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
- rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
+ rule OBJFILE => [lambda { SRCFILE }, lambda { SRCFILE2 }] do
@runs << :RULE1
end
- rule OBJFILE => [lambda{SRCFILE}] do
+ rule OBJFILE => [lambda { SRCFILE }] do
@runs << :RULE2
end
Task[OBJFILE].invoke
@@ -246,10 +246,10 @@ class TestRakeRules < Rake::TestCase
def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
- rule OBJFILE => [lambda{SRCFILE}] do
+ rule OBJFILE => [lambda { SRCFILE }] do
@runs << :RULE1
end
- rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
+ rule OBJFILE => [lambda { SRCFILE }, lambda { SRCFILE2 }] do
@runs << :RULE2
end
Task[OBJFILE].invoke
@@ -298,9 +298,9 @@ class TestRakeRules < Rake::TestCase
actions = []
create_file("abc.xml")
rule '.y' => '.xml' do actions << 'y' end
- rule '.c' => '.y' do actions << 'c' end
- rule '.o' => '.c' do actions << 'o' end
- rule '.exe' => '.o' do actions << 'exe' end
+ rule '.c' => '.y' do actions << 'c'end
+ rule '.o' => '.c' do actions << 'o'end
+ rule '.exe' => '.o' do actions << 'exe'end
Task["abc.exe"].invoke
assert_equal ['y', 'c', 'o', 'exe'], actions
end
@@ -319,9 +319,44 @@ class TestRakeRules < Rake::TestCase
end
def test_rules_with_bad_dependents_will_fail
- rule "a" => [ 1 ] do |t| puts t.name end
+ rule "a" => [1] do |t| puts t.name end
assert_raises(RuntimeError) do Task['a'].invoke end
end
-end
+ def test_string_rule_with_args
+ delete_file(OBJFILE)
+ create_file(SRCFILE)
+ rule '.o', [:a] => SRCFILE do |t, args|
+ assert_equal 'arg', args.a
+ end
+ Task[OBJFILE].invoke('arg')
+ end
+ def test_regex_rule_with_args
+ delete_file(OBJFILE)
+ create_file(SRCFILE)
+ rule(/.o$/, [:a] => SRCFILE) do |t, args|
+ assert_equal 'arg', args.a
+ end
+ Task[OBJFILE].invoke('arg')
+ end
+
+ def test_string_rule_with_args_and_lambda_prereq
+ delete_file(OBJFILE)
+ create_file(SRCFILE)
+ rule '.o', [:a] => [lambda{SRCFILE}]do |t, args|
+ assert_equal 'arg', args.a
+ end
+ Task[OBJFILE].invoke('arg')
+ end
+
+ def test_regex_rule_with_args_and_lambda_prereq
+ delete_file(OBJFILE)
+ create_file(SRCFILE)
+ rule(/.o$/, [:a] => [lambda{SRCFILE}]) do |t, args|
+ assert_equal 'arg', args.a
+ end
+ Task[OBJFILE].invoke('arg')
+ end
+
+end
diff --git a/test/rake/test_rake_scope.rb b/test/rake/test_rake_scope.rb
new file mode 100644
index 0000000000..ef06618ba9
--- /dev/null
+++ b/test/rake/test_rake_scope.rb
@@ -0,0 +1,44 @@
+require File.expand_path('../helper', __FILE__)
+
+class TestRakeScope < Rake::TestCase
+ include Rake
+
+ def test_path_against_empty_scope
+ scope = Scope.make
+ assert_equal scope, Scope::EMPTY
+ assert_equal scope.path, ""
+ end
+
+ def test_path_against_one_element
+ scope = Scope.make(:one)
+ assert_equal "one", scope.path
+ end
+
+ def test_path_against_two_elements
+ scope = Scope.make(:inner, :outer)
+ assert_equal "outer:inner", scope.path
+ end
+
+ def test_path_with_task_name
+ scope = Scope.make(:inner, :outer)
+ assert_equal "outer:inner:task", scope.path_with_task_name("task")
+ end
+
+ def test_path_with_task_name_against_empty_scope
+ scope = Scope.make
+ assert_equal "task", scope.path_with_task_name("task")
+ end
+
+ def test_conj_against_two_elements
+ scope = Scope.make.conj("B").conj("A")
+ assert_equal Scope.make("A", "B"), scope
+ end
+
+ def test_trim
+ scope = Scope.make("A", "B")
+ assert_equal scope, scope.trim(0)
+ assert_equal scope.tail, scope.trim(1)
+ assert_equal scope.tail.tail, scope.trim(2)
+ assert_equal scope.tail.tail, scope.trim(3)
+ end
+end
diff --git a/test/rake/test_rake_task.rb b/test/rake/test_rake_task.rb
index 7d844ac22b..2ab995a6ff 100644
--- a/test/rake/test_rake_task.rb
+++ b/test/rake/test_rake_task.rb
@@ -32,7 +32,6 @@ class TestRakeTask < Rake::TestCase
end
def test_inspect
-# t = task(:foo, :needs => [:bar, :baz])
t = task(:foo => [:bar, :baz])
assert_equal "<Rake::Task foo => [bar, baz]>", t.inspect
end
@@ -157,8 +156,8 @@ class TestRakeTask < Rake::TestCase
def test_multi_invocations
runs = []
p = proc do |t| runs << t.name end
- task({:t1=>[:t2,:t3]}, &p)
- task({:t2=>[:t3]}, &p)
+ task({ :t1 => [:t2, :t3] }, &p)
+ task({ :t2 => [:t3] }, &p)
task(:t3, &p)
Task[:t1].invoke
assert_equal ["t1", "t2", "t3"], runs.sort
@@ -167,7 +166,7 @@ class TestRakeTask < Rake::TestCase
def test_task_list
task :t2
task :t1 => [:t2]
- assert_equal ["t1", "t2"], Task.tasks.collect {|t| t.name}
+ assert_equal ["t1", "t2"], Task.tasks.map { |t| t.name }
end
def test_task_gives_name_on_to_s
@@ -221,6 +220,31 @@ class TestRakeTask < Rake::TestCase
assert_equal [b, c], a.prerequisite_tasks
end
+ def test_all_prerequisite_tasks_includes_all_prerequisites
+ a = task :a => "b"
+ b = task :b => ["c", "d"]
+ c = task :c => "e"
+ d = task :d
+ e = task :e
+
+ assert_equal [b, c, d, e], a.all_prerequisite_tasks.sort_by { |t| t.name }
+ end
+
+ def test_all_prerequisite_tasks_does_not_include_duplicates
+ a = task :a => ["b", "c"]
+ b = task :b => "c"
+ c = task :c
+
+ assert_equal [b, c], a.all_prerequisite_tasks.sort_by { |t| t.name }
+ end
+
+ def test_all_prerequisite_tasks_includes_self_on_cyclic_dependencies
+ a = task :a => "b"
+ b = task :b => "a"
+
+ assert_equal [a, b], a.all_prerequisite_tasks.sort_by { |t| t.name }
+ end
+
def test_timestamp_returns_now_if_all_prereqs_have_no_times
a = task :a => ["b", "c"]
task :b
@@ -238,7 +262,7 @@ class TestRakeTask < Rake::TestCase
def b.timestamp() Time.now + 10 end
def c.timestamp() Time.now + 5 end
- assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?'
+ assert_in_delta now, a.timestamp, 0.1, 'computer too slow?'
end
def test_always_multitask
@@ -247,15 +271,15 @@ class TestRakeTask < Rake::TestCase
t_a = task(:a) do |t|
sleep 0.02
- mx.synchronize{ result << t.name }
+ mx.synchronize { result << t.name }
end
t_b = task(:b) do |t|
- mx.synchronize{ result << t.name }
+ mx.synchronize { result << t.name }
end
- t_c = task(:c => [:a,:b]) do |t|
- mx.synchronize{ result << t.name }
+ t_c = task(:c => [:a, :b]) do |t|
+ mx.synchronize { result << t.name }
end
t_c.invoke
@@ -283,6 +307,30 @@ class TestRakeTask < Rake::TestCase
assert_match(/pre-requisites:\s*--t[23]/, out)
end
+ # NOTE: Rail-ties uses comment=.
+ def test_comment_setting
+ t = task(:t, :name, :rev)
+ t.comment = "A Comment"
+ assert_equal "A Comment", t.comment
+ end
+
+ def test_comments_with_sentences
+ desc "Comment 1. Comment 2."
+ t = task(:t, :name, :rev)
+ assert_equal "Comment 1", t.comment
+ end
+
+ def test_comments_with_tabbed_sentences
+ desc "Comment 1.\tComment 2."
+ t = task(:t, :name, :rev)
+ assert_equal "Comment 1", t.comment
+ end
+
+ def test_comments_with_decimal_points
+ desc "Revision 1.2.3."
+ t = task(:t, :name, :rev)
+ assert_equal "Revision 1.2.3", t.comment
+ end
def test_extended_comments
desc %{
@@ -294,7 +342,7 @@ class TestRakeTask < Rake::TestCase
}
t = task(:t, :name, :rev)
assert_equal "[name,rev]", t.arg_description
- assert_equal "This is a comment.", t.comment
+ assert_equal "This is a comment", t.comment
assert_match(/^\s*name -- Name/, t.full_comment)
assert_match(/^\s*rev -- Software/, t.full_comment)
assert_match(/\A\s*This is a comment\.$/, t.full_comment)
@@ -308,9 +356,21 @@ class TestRakeTask < Rake::TestCase
assert_equal "line one / line two", t.comment
end
- def test_settable_comments
+ def test_duplicate_comments
+ desc "line one"
t = task(:t)
- t.comment = "HI"
- assert_equal "HI", t.comment
+ desc "line one"
+ task(:t)
+ assert_equal "line one", t.comment
+ end
+
+ def test_interspersed_duplicate_comments
+ desc "line one"
+ t = task(:t)
+ desc "line two"
+ task(:t)
+ desc "line one"
+ task(:t)
+ assert_equal "line one / line two", t.comment
end
end
diff --git a/test/rake/test_rake_task_arguments.rb b/test/rake/test_rake_task_arguments.rb
index 7001a4aeb2..061178e23e 100644
--- a/test/rake/test_rake_task_arguments.rb
+++ b/test/rake/test_rake_task_arguments.rb
@@ -26,8 +26,8 @@ class TestRakeTaskArguments < Rake::TestCase
end
def test_enumerable_behavior
- ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2 ,3])
- assert_equal [10, 20, 30], ta.collect { |k,v| v * 10 }.sort
+ ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
+ assert_equal [10, 20, 30], ta.map { |k, v| v * 10 }.sort
end
def test_named_args
@@ -85,4 +85,37 @@ class TestRakeTaskArguments < Rake::TestCase
ta.with_defaults({ "cc" => "default_val" })
assert_nil ta[:cc]
end
+
+ def test_all_and_extra_arguments_without_named_arguments
+ app = Rake::Application.new
+ _, args = app.parse_task_string("task[1,two,more]")
+ ta = Rake::TaskArguments.new([], args)
+ assert_equal [], ta.names
+ assert_equal ['1', 'two', 'more'], ta.to_a
+ assert_equal ['1', 'two', 'more'], ta.extras
+ end
+
+ def test_all_and_extra_arguments_with_named_arguments
+ app = Rake::Application.new
+ _, args = app.parse_task_string("task[1,two,more,still more]")
+ ta = Rake::TaskArguments.new([:first, :second], args)
+ assert_equal [:first, :second], ta.names
+ assert_equal "1", ta[:first]
+ assert_equal "two", ta[:second]
+ assert_equal ['1', 'two', 'more', 'still more'], ta.to_a
+ assert_equal ['more', 'still more'], ta.extras
+ end
+
+ def test_extra_args_with_less_than_named_arguments
+ app = Rake::Application.new
+ _, args = app.parse_task_string("task[1,two]")
+ ta = Rake::TaskArguments.new([:first, :second, :third], args)
+ assert_equal [:first, :second, :third], ta.names
+ assert_equal "1", ta[:first]
+ assert_equal "two", ta[:second]
+ assert_equal nil, ta[:third]
+ assert_equal ['1', 'two'], ta.to_a
+ assert_equal [], ta.extras
+ end
+
end
diff --git a/test/rake/test_rake_task_manager.rb b/test/rake/test_rake_task_manager.rb
index 110ce65d4c..5ec4c0e65c 100644
--- a/test/rake/test_rake_task_manager.rb
+++ b/test/rake/test_rake_task_manager.rb
@@ -37,7 +37,7 @@ class TestRakeTaskManager < Rake::TestCase
t = @tm.define_task(Rake::Task, :t)
assert_equal "x:t", t.name
end
- assert_equal ["x:t"], @tm.tasks.collect { |t| t.name }
+ assert_equal ["x:t"], @tm.tasks.map { |t| t.name }
end
def test_anonymous_namespace
@@ -55,7 +55,7 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal "fn", t.name
end
- assert_equal ["fn"], @tm.tasks.collect { |t| t.name }
+ assert_equal ["fn"], @tm.tasks.map { |t| t.name }
end
def test_namespace_yields_same_namespace_as_returned
@@ -93,7 +93,7 @@ class TestRakeTaskManager < Rake::TestCase
bb = @tm.define_task(Rake::Task, :bb)
bot_z = @tm.define_task(Rake::Task, :z)
- assert_equal ["a", "b"], @tm.current_scope
+ assert_equal Rake::Scope.make("b", "a"), @tm.current_scope
assert_equal bb, @tm["a:b:bb"]
assert_equal aa, @tm["a:aa"]
@@ -101,10 +101,11 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal bot_z, @tm["z"]
assert_equal mid_z, @tm["^z"]
assert_equal top_z, @tm["^^z"]
+ assert_equal top_z, @tm["^^^z"] # Over the top
assert_equal top_z, @tm["rake:z"]
end
- assert_equal ["a"], @tm.current_scope
+ assert_equal Rake::Scope.make("a"), @tm.current_scope
assert_equal bb, @tm["a:b:bb"]
assert_equal aa, @tm["a:aa"]
@@ -113,18 +114,19 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal aa, @tm["aa"]
assert_equal mid_z, @tm["z"]
assert_equal top_z, @tm["^z"]
+ assert_equal top_z, @tm["^^z"] # Over the top
assert_equal top_z, @tm["rake:z"]
end
- assert_equal [], @tm.current_scope
+ assert_equal Rake::Scope.make, @tm.current_scope
- assert_equal [], xx.scope
- assert_equal ['a'], aa.scope
- assert_equal ['a', 'b'], bb.scope
+ assert_equal Rake::Scope.make, xx.scope
+ assert_equal Rake::Scope.make('a'), aa.scope
+ assert_equal Rake::Scope.make('b', 'a'), bb.scope
end
def test_lookup_with_explicit_scopes
- t1, t2, t3, s = (0...4).collect { nil }
+ t1, t2, t3, s = (0...4).map { nil }
t1 = @tm.define_task(Rake::Task, :t)
@tm.in_namespace("a") do
t2 = @tm.define_task(Rake::Task, :t)
@@ -133,11 +135,11 @@ class TestRakeTaskManager < Rake::TestCase
t3 = @tm.define_task(Rake::Task, :t)
end
end
- assert_equal t1, @tm[:t, []]
- assert_equal t2, @tm[:t, ["a"]]
- assert_equal t3, @tm[:t, ["a", "b"]]
- assert_equal s, @tm[:s, ["a", "b"]]
- assert_equal s, @tm[:s, ["a"]]
+ assert_equal t1, @tm[:t, Rake::Scope.make]
+ assert_equal t2, @tm[:t, Rake::Scope.make("a")]
+ assert_equal t3, @tm[:t, Rake::Scope.make("b", "a")]
+ assert_equal s, @tm[:s, Rake::Scope.make("b", "a")]
+ assert_equal s, @tm[:s, Rake::Scope.make("a")]
end
def test_correctly_scoped_prerequisites_are_invoked
@@ -154,4 +156,3 @@ class TestRakeTaskManager < Rake::TestCase
end
end
-
diff --git a/test/rake/test_rake_task_manager_argument_resolution.rb b/test/rake/test_rake_task_manager_argument_resolution.rb
index 35e0862ef7..43fa2ac447 100644
--- a/test/rake/test_rake_task_manager_argument_resolution.rb
+++ b/test/rake/test_rake_task_manager_argument_resolution.rb
@@ -2,28 +2,11 @@ require File.expand_path('../helper', __FILE__)
class TestRakeTaskManagerArgumentResolution < Rake::TestCase
- def setup
- super
-
- Rake.application.options.ignore_deprecate = true
- end
-
- def teardown
- Rake.application.options.ignore_deprecate = false
-
- super
- end
-
def test_good_arg_patterns
assert_equal [:t, [], []], task(:t)
assert_equal [:t, [], [:x]], task(:t => :x)
assert_equal [:t, [], [:x, :y]], task(:t => [:x, :y])
- assert_equal [:t, [:a, :b], []], task(:t, :a, :b)
- assert_equal [:t, [], [:x]], task(:t, :needs => :x)
- assert_equal [:t, [:a, :b], [:x]], task(:t, :a, :b, :needs => :x)
- assert_equal [:t, [:a, :b], [:x, :y]], task(:t, :a, :b, :needs => [:x, :y])
-
assert_equal [:t, [:a, :b], []], task(:t, [:a, :b])
assert_equal [:t, [:a, :b], [:x]], task(:t, [:a, :b] => :x)
assert_equal [:t, [:a, :b], [:x, :y]], task(:t, [:a, :b] => [:x, :y])
diff --git a/test/rake/test_rake_task_with_arguments.rb b/test/rake/test_rake_task_with_arguments.rb
index cf4c157256..9d56ffbe8a 100644
--- a/test/rake/test_rake_task_with_arguments.rb
+++ b/test/rake/test_rake_task_with_arguments.rb
@@ -33,21 +33,11 @@ class TestRakeTaskWithArguments < Rake::TestCase
assert_equal ["pre"], t.prerequisites
end
- def test_name_args_and_explicit_needs
- ignore_deprecations do
- t = task(:t, :x, :y, :needs => [:pre])
- assert_equal "t", t.name
- assert_equal [:x, :y], t.arg_names
- assert_equal ["pre"], t.prerequisites
- end
- end
-
- def test_illegal_keys_in_task_name_hash
- ignore_deprecations do
- assert_raises RuntimeError do
- task(:t, :x, :y => 1, :needs => [:pre])
- end
- end
+ def test_name_args_and_prereqs
+ t = task(:t, [:x, :y] => [:pre])
+ assert_equal "t", t.name
+ assert_equal [:x, :y], t.arg_names
+ assert_equal ["pre"], t.prerequisites
end
def test_arg_list_is_empty_if_no_args_given
@@ -91,7 +81,7 @@ class TestRakeTaskWithArguments < Rake::TestCase
def test_arguments_are_passed_to_block
t = task(:t, :a, :b) { |tt, args|
- assert_equal( { :a => 1, :b => 2 }, args.to_hash )
+ assert_equal({ :a => 1, :b => 2 }, args.to_hash)
}
t.invoke(1, 2)
end
@@ -131,7 +121,7 @@ class TestRakeTaskWithArguments < Rake::TestCase
assert_equal "T", t.comment
assert_equal "[a,b]", t.arg_description
assert_equal "tt[a,b]", t.name_with_args
- assert_equal [:a, :b],t.arg_names
+ assert_equal [:a, :b], t.arg_names
end
def test_named_args_are_passed_to_prereqs
diff --git a/test/rake/test_rake_test_task.rb b/test/rake/test_rake_test_task.rb
index 1a6d23e425..637accc291 100644
--- a/test/rake/test_rake_test_task.rb
+++ b/test/rake/test_rake_test_task.rb
@@ -28,7 +28,7 @@ class TestRakeTestTask < Rake::TestCase
assert Task.task_defined?(:example)
end
- def test_file_list_ENV_TEST
+ def test_file_list_env_test
ENV['TEST'] = 'testfile.rb'
tt = Rake::TestTask.new do |t|
t.pattern = '*'
@@ -117,4 +117,3 @@ class TestRakeTestTask < Rake::TestCase
end
end
-
diff --git a/test/rake/test_rake_thread_pool.rb b/test/rake/test_rake_thread_pool.rb
index cc8163a9e0..93f32fb35a 100644
--- a/test/rake/test_rake_thread_pool.rb
+++ b/test/rake/test_rake_thread_pool.rb
@@ -7,21 +7,28 @@ class TestRakeTestThreadPool < Rake::TestCase
def test_pool_executes_in_current_thread_for_zero_threads
pool = ThreadPool.new(0)
- f = pool.future{Thread.current}
+ f = pool.future { Thread.current }
pool.join
assert_equal Thread.current, f.value
end
def test_pool_executes_in_other_thread_for_pool_of_size_one
pool = ThreadPool.new(1)
- f = pool.future{Thread.current}
+ f = pool.future { Thread.current }
pool.join
refute_equal Thread.current, f.value
end
def test_pool_executes_in_two_other_threads_for_pool_of_size_two
pool = ThreadPool.new(2)
- threads = 2.times.collect{ pool.future{ sleep 0.1; Thread.current } }.each{|f|f.value}
+ threads = 2.times.map {
+ pool.future {
+ sleep 0.1
+ Thread.current
+ }
+ }.each { |f|
+ f.value
+ }
refute_equal threads[0], threads[1]
refute_equal Thread.current, threads[0]
@@ -35,22 +42,20 @@ class TestRakeTestThreadPool < Rake::TestCase
10.times.each do
pool.future do
sleep 0.02
- t_mutex.synchronize{ threads << Thread.current }
+ t_mutex.synchronize { threads << Thread.current }
end
end
pool.join
assert_equal 2, threads.count
end
- def test_pool_future_captures_arguments
+ def test_pool_future_does_not_duplicate_arguments
pool = ThreadPool.new(2)
- a = 'a'
- b = 'b'
- c = 5 # 5 throws an exception with 5.dup. It should be ignored
- pool.future(a,c){ |a_var,ignore| a_var.capitalize!; b.capitalize! }
+ obj = Object.new
+ captured = nil
+ pool.future(obj) { |var| captured = var }
pool.join
- assert_equal 'a', a
- assert_equal 'b'.capitalize, b
+ assert_equal obj, captured
end
def test_pool_join_empties_queue
@@ -69,35 +74,49 @@ class TestRakeTestThreadPool < Rake::TestCase
}
pool.join
- assert_equal true, pool.__send__(:__queue__).empty?, "queue should be empty"
+ assert_equal(
+ true,
+ pool.__send__(:__queue__).empty?,
+ "queue should be empty")
end
+ CustomError = Class.new(StandardError)
+
# test that throwing an exception way down in the blocks propagates
# to the top
def test_exceptions
pool = ThreadPool.new(10)
deep_exception_block = lambda do |count|
- next raise Exception.new if ( count < 1 )
- pool.future(count-1, &deep_exception_block).value
+ raise CustomError if count < 1
+ pool.future(count - 1, &deep_exception_block).value
end
- assert_raises(Exception) do
+ assert_raises(CustomError) do
pool.future(2, &deep_exception_block).value
end
-
end
def test_pool_prevents_deadlock
pool = ThreadPool.new(5)
common_dependency_a = pool.future { sleep 0.2 }
- futures_a = 10.times.collect { pool.future{ common_dependency_a.value; sleep(rand() * 0.01) } }
+ futures_a = 10.times.map {
+ pool.future {
+ common_dependency_a.value
+ sleep(rand() * 0.01)
+ }
+ }
common_dependency_b = pool.future { futures_a.each { |f| f.value } }
- futures_b = 10.times.collect { pool.future{ common_dependency_b.value; sleep(rand() * 0.01) } }
+ futures_b = 10.times.map {
+ pool.future {
+ common_dependency_b.value
+ sleep(rand() * 0.01)
+ }
+ }
- futures_b.each{|f|f.value}
+ futures_b.each { |f| f.value }
pool.join
end
@@ -108,15 +127,15 @@ class TestRakeTestThreadPool < Rake::TestCase
b = 5
c = 3
- result = a.times.collect do
+ result = a.times.map do
pool.future do
- b.times.collect do
+ b.times.map do
pool.future { sleep rand * 0.001; c }
- end.inject(0) { |m,f| m+f.value }
+ end.reduce(0) { |m, f| m + f.value }
end
- end.inject(0) { |m,f| m+f.value }
+ end.reduce(0) { |m, f| m + f.value }
- assert_equal( (a*b*c), result )
+ assert_equal a * b * c, result
pool.join
end
diff --git a/test/rake/test_rake_top_level_functions.rb b/test/rake/test_rake_top_level_functions.rb
index 4cc4b4cfdd..fee702dc13 100644
--- a/test/rake/test_rake_top_level_functions.rb
+++ b/test/rake/test_rake_top_level_functions.rb
@@ -65,46 +65,6 @@ class TestRakeTopLevelFunctions < Rake::TestCase
Rake::FileUtilsExt.nowrite_flag = false
end
- def test_missing_constants_task
- Object.const_missing(:Task)
-
- expected = [
- [[:const_warning, :Task], nil]
- ]
-
- assert_equal expected, @app.called
- end
-
- def test_missing_constants_file_task
- Object.const_missing(:FileTask)
-
- expected = [
- [[:const_warning, :FileTask], nil]
- ]
-
- assert_equal expected, @app.called
- end
-
- def test_missing_constants_file_creation_task
- Object.const_missing(:FileCreationTask)
-
- expected = [
- [[:const_warning, :FileCreationTask], nil]
- ]
-
- assert_equal expected, @app.called
- end
-
- def test_missing_constants_rake_app
- Object.const_missing(:RakeApp)
-
- expected = [
- [[:const_warning, :RakeApp], nil]
- ]
-
- assert_equal expected, @app.called
- end
-
def test_missing_other_constant
assert_raises(NameError) do Object.const_missing(:Xyz) end
end
diff --git a/test/rake/test_sys.rb b/test/rake/test_sys.rb
deleted file mode 100644
index 21f7e2c708..0000000000
--- a/test/rake/test_sys.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../helper', __FILE__)
-begin
- old_verbose = $VERBOSE
- $VERBOSE = nil
- require 'rake/contrib/sys'
-ensure
- $VERBOSE = old_verbose
-end
-
-class TestSys < Rake::TestCase
-
- def test_split_all
- assert_equal ['a'], Sys.split_all('a')
- assert_equal ['..'], Sys.split_all('..')
- assert_equal ['/'], Sys.split_all('/')
- assert_equal ['a', 'b'], Sys.split_all('a/b')
- assert_equal ['/', 'a', 'b'], Sys.split_all('/a/b')
- assert_equal ['..', 'a', 'b'], Sys.split_all('../a/b')
- end
-end
diff --git a/test/rake/test_thread_history_display.rb b/test/rake/test_thread_history_display.rb
index 2ac83b0dc0..bb5879cff5 100644
--- a/test/rake/test_thread_history_display.rb
+++ b/test/rake/test_thread_history_display.rb
@@ -5,7 +5,7 @@ require 'rake/thread_history_display'
class TestThreadHistoryDisplay < Rake::TestCase
def setup
super
- @time = 1000000
+ @time = 1_000_000
@stats = []
@display = Rake::ThreadHistoryDisplay.new(@stats)
end
@@ -60,24 +60,34 @@ class TestThreadHistoryDisplay < Rake::TestCase
end
def test_thread_deleted
- @stats << event(:thread_deleted, :deleted_thread => 123456, :thread_count => 12)
+ @stats << event(
+ :thread_deleted,
+ :deleted_thread => 123_456,
+ :thread_count => 12)
out, _ = capture_io do
@display.show
end
- assert_match(/^ *1000000 +A +thread_deleted( +deleted_thread:B| +thread_count:12){2}$/, out)
+ assert_match(
+ /^ *1000000 +A +thread_deleted( +deleted_thread:B| +thread_count:12){2}$/,
+ out)
end
def test_thread_created
- @stats << event(:thread_created, :new_thread => 123456, :thread_count => 13)
+ @stats << event(
+ :thread_created,
+ :new_thread => 123_456,
+ :thread_count => 13)
out, _ = capture_io do
@display.show
end
- assert_match(/^ *1000000 +A +thread_created( +new_thread:B| +thread_count:13){2}$/, out)
+ assert_match(
+ /^ *1000000 +A +thread_created( +new_thread:B| +thread_count:13){2}$/,
+ out)
end
private
- def event(type, data={})
+ def event(type, data = {})
result = {
:event => type,
:time => @time / 1_000_000.0,
diff --git a/test/rake/test_trace_output.rb b/test/rake/test_trace_output.rb
index 750ea1447e..f9aead989d 100644
--- a/test/rake/test_trace_output.rb
+++ b/test/rake/test_trace_output.rb
@@ -6,10 +6,12 @@ class TestTraceOutput < Rake::TestCase
class PrintSpy
attr_reader :result, :calls
+
def initialize
@result = ""
@calls = 0
end
+
def print(string)
@result << string
@calls += 1
@@ -30,6 +32,13 @@ class TestTraceOutput < Rake::TestCase
assert_equal 1, spy.calls
end
+ def test_trace_handles_nil_objects
+ spy = PrintSpy.new
+ trace_on(spy, "HI\n", nil, "LO")
+ assert_equal "HI\nLO\n", spy.result
+ assert_equal 1, spy.calls
+ end
+
def test_trace_issues_single_io_for_args_multiple_strings_and_alternate_sep
old_sep = $\
$\ = "\r"