2011-06-23 18:11:55 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
|
|
|
require 'rake/testtask'
|
|
|
|
|
|
|
|
class TestRakeTestTask < Rake::TestCase
|
|
|
|
include Rake
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_initialize
|
2011-06-23 18:11:55 -04:00
|
|
|
tt = Rake::TestTask.new do |t| end
|
|
|
|
refute_nil tt
|
|
|
|
assert_equal :test, tt.name
|
|
|
|
assert_equal ['lib'], tt.libs
|
|
|
|
assert_equal 'test/test*.rb', tt.pattern
|
|
|
|
assert_equal false, tt.verbose
|
|
|
|
assert Task.task_defined?(:test)
|
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_initialize_override
|
2011-06-23 18:11:55 -04:00
|
|
|
tt = Rake::TestTask.new(:example) do |t|
|
2014-07-14 23:07:37 -04:00
|
|
|
t.description = "Run example tests"
|
2011-06-23 18:11:55 -04:00
|
|
|
t.libs = ['src', 'ext']
|
|
|
|
t.pattern = 'test/tc_*.rb'
|
|
|
|
t.verbose = true
|
|
|
|
end
|
|
|
|
refute_nil tt
|
2014-07-14 23:07:37 -04:00
|
|
|
assert_equal "Run example tests", tt.description
|
2011-06-23 18:11:55 -04:00
|
|
|
assert_equal :example, tt.name
|
|
|
|
assert_equal ['src', 'ext'], tt.libs
|
|
|
|
assert_equal 'test/tc_*.rb', tt.pattern
|
|
|
|
assert_equal true, tt.verbose
|
|
|
|
assert Task.task_defined?(:example)
|
|
|
|
end
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
def test_file_list_env_test
|
2011-06-23 18:11:55 -04:00
|
|
|
ENV['TEST'] = 'testfile.rb'
|
|
|
|
tt = Rake::TestTask.new do |t|
|
|
|
|
t.pattern = '*'
|
|
|
|
end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
assert_equal ["testfile.rb"], tt.file_list.to_a
|
2011-06-27 22:45:29 -04:00
|
|
|
ensure
|
|
|
|
ENV.delete 'TEST'
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_libs_equals
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
|
|
|
t.libs << ["A", "B"]
|
|
|
|
end
|
|
|
|
|
|
|
|
path = %w[lib A B].join File::PATH_SEPARATOR
|
|
|
|
|
|
|
|
assert_equal "-I\"#{path}\"", test_task.ruby_opts_string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_libs_equals_empty
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
|
|
|
t.libs = []
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', test_task.ruby_opts_string
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pattern_equals
|
2011-06-23 18:11:55 -04:00
|
|
|
tt = Rake::TestTask.new do |t|
|
2011-06-27 22:45:29 -04:00
|
|
|
t.pattern = '*.rb'
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
2011-06-27 22:45:29 -04:00
|
|
|
assert_equal ['*.rb'], tt.file_list.to_a
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_pattern_equals_test_files_equals
|
2011-06-23 18:11:55 -04:00
|
|
|
tt = Rake::TestTask.new do |t|
|
|
|
|
t.test_files = FileList['a.rb', 'b.rb']
|
|
|
|
t.pattern = '*.rb'
|
|
|
|
end
|
|
|
|
assert_equal ['a.rb', 'b.rb', '*.rb'], tt.file_list.to_a
|
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_run_code_direct
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
2011-06-23 18:11:55 -04:00
|
|
|
t.loader = :direct
|
|
|
|
end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
|
|
|
assert_equal '-e "ARGV.each{|f| require f}"', test_task.run_code
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_code_rake
|
2014-07-14 23:07:37 -04:00
|
|
|
spec = Gem::Specification.new 'rake', 0
|
|
|
|
spec.loaded_from = File.join Gem::Specification.dirs.last, 'rake-0.gemspec'
|
|
|
|
rake, Gem.loaded_specs['rake'] = Gem.loaded_specs['rake'], spec
|
|
|
|
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
|
|
|
t.loader = :rake
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/\A-I".*?" ".*?"\Z/, test_task.run_code)
|
|
|
|
ensure
|
|
|
|
Gem.loaded_specs['rake'] = rake
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_code_rake_default_gem
|
|
|
|
default_spec = Gem::Specification.new 'rake', 0
|
|
|
|
default_spec.loaded_from = File.join Gem::Specification.default_specifications_dir, 'rake-0.gemspec'
|
|
|
|
rake, Gem.loaded_specs['rake'] = Gem.loaded_specs['rake'], default_spec
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
test_task = Rake::TestTask.new do |t|
|
|
|
|
t.loader = :rake
|
|
|
|
end
|
|
|
|
|
2014-07-21 02:29:53 -04:00
|
|
|
assert_match(/\A(-I".*?" *)* ".*?"\Z/, test_task.run_code)
|
2014-07-14 23:07:37 -04:00
|
|
|
ensure
|
|
|
|
Gem.loaded_specs['rake'] = rake
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_run_code_testrb_ruby_1_8_2
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
2011-06-23 18:11:55 -04:00
|
|
|
t.loader = :testrb
|
|
|
|
end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
2011-07-23 01:38:50 -04:00
|
|
|
def test_task.ruby_version() '1.8.2' end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
assert_match(/^-S testrb +".*"$/, test_task.run_code)
|
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_run_code_testrb_ruby_1_8_6
|
|
|
|
test_task = Rake::TestTask.new do |t|
|
2011-06-23 18:11:55 -04:00
|
|
|
t.loader = :testrb
|
|
|
|
end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
2011-07-23 01:38:50 -04:00
|
|
|
def test_task.ruby_version() '1.8.6' end
|
2011-06-27 22:45:29 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
assert_match(/^-S testrb +$/, test_task.run_code)
|
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
def test_test_files_equals
|
|
|
|
tt = Rake::TestTask.new do |t|
|
|
|
|
t.test_files = FileList['a.rb', 'b.rb']
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 22:45:29 -04:00
|
|
|
assert_equal ["a.rb", 'b.rb'], tt.file_list.to_a
|
2011-06-23 18:11:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|