Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove requirement for session gem from rake tests

  • Loading branch information...
commit 3680bf61101fbedaa5ec3a1d6b961ad538ee5797 1 parent 412a19c
@drbrain drbrain authored
View
33 Rakefile
@@ -12,7 +12,7 @@ require 'rubygems'
system_rake = File.join RbConfig::CONFIG['rubylibdir'], 'rake.rb'
# Use our rake, not the installed rake from system
-if $".include? system_rake then
+if $".include? system_rake or $".grep(/rake\/name_space\.rb$/).empty? then
exec Gem.ruby, '-Ilib', 'bin/rake', *ARGV
end
@@ -155,41 +155,22 @@ if ! defined?(Gem)
puts "Package Target requires RubyGems"
else
SPEC = Gem::Specification.new do |s|
-
- #### Basic information.
-
s.name = 'rake'
s.version = $package_version
s.summary = "Ruby based make-like utility."
- s.description = <<-EOF
- Rake is a Make-like program implemented in Ruby. Tasks
- and dependencies are specified in standard Ruby syntax.
+ s.description = <<-EOF.delete "\n"
+Rake is a Make-like program implemented in Ruby. Tasks and dependencies are
+specified in standard Ruby syntax.
EOF
- #### Dependencies and requirements.
-
s.required_ruby_version = '>= 1.8.6'
s.required_rubygems_version = '>= 1.3.2'
s.add_development_dependency 'minitest', '~> 2.1'
- s.add_development_dependency 'session', '~> 2.4'
-
- #### Which files are to be included in this gem? Everything! (Except CVS directories.)
s.files = PKG_FILES.to_a
- #### C code extensions.
-
- #s.extensions << "ext/rmagic/extconf.rb"
-
- #### Load-time details: library and application (you will need one or both).
-
- s.require_path = 'lib' # Use these for libraries.
-
- s.bindir = "bin" # Use these for applications.
s.executables = ["rake"]
- #### Documentation and testing.
-
s.extra_rdoc_files = FileList[
'README.rdoc',
'MIT-LICENSE',
@@ -200,16 +181,10 @@ else
s.rdoc_options = BASE_RDOC_OPTIONS
- #### Author and project details.
-
s.author = "Jim Weirich"
s.email = "jim@weirichhouse.org"
s.homepage = "http://rake.rubyforge.org"
s.rubyforge_project = "rake"
-# if ENV['CERT_DIR']
-# s.signing_key = File.join(ENV['CERT_DIR'], 'gem-private_key.pem')
-# s.cert_chain = [File.join(ENV['CERT_DIR'], 'gem-public_cert.pem')]
-# end
end
Gem::PackageTask.new(SPEC) do |pkg|
View
15 lib/rake/application.rb
@@ -85,14 +85,12 @@ def load_rakefile
# Run the top level tasks of a Rake application.
def top_level
- standard_exception_handling do
- if options.show_tasks
- display_tasks_and_comments
- elsif options.show_prereqs
- display_prerequisites
- else
- top_level_tasks.each { |task_name| invoke_task(task_name) }
- end
+ if options.show_tasks
+ display_tasks_and_comments
+ elsif options.show_prereqs
+ display_prerequisites
+ else
+ top_level_tasks.each { |task_name| invoke_task(task_name) }
end
end
@@ -348,6 +346,7 @@ def standard_rake_options
],
['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
"Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')",
+ # HACK Use File::PATH_SEPARATOR
lambda { |value| options.rakelib = value.split(':') }
],
['--require', '-r MODULE', "Require MODULE before executing rakefile.",
View
12 test/helper.rb
@@ -1,5 +1,4 @@
require 'rubygems'
-require 'minitest/unit'
require 'minitest/autorun'
require 'rake'
require 'tmpdir'
@@ -428,17 +427,6 @@ def rakefile_rbext
end
end
- def rakefile_statusreturn
- rakefile <<-STATUSRETURN
-task :exit5 do
- exit(5)
-end
-
-task :normal do
-end
- STATUSRETURN
- end
-
def rakefile_unittest
rakefile '# Empty Rakefile for Unit Test'
View
61 test/test_rake_application.rb
@@ -405,6 +405,67 @@ def test_deprecation_message
assert_match(/at c$/i, err)
end
+ def test_standard_exception_handling_invalid_option
+ out, err = capture_io do
+ e = assert_raises SystemExit do
+ @app.standard_exception_handling do
+ raise OptionParser::InvalidOption, 'blah'
+ end
+ end
+
+ assert_equal 1, e.status
+ end
+
+ assert_empty out
+ assert_equal "invalid option: blah\n", err
+ end
+
+ def test_standard_exception_handling_other
+ out, err = capture_io do
+ e = assert_raises SystemExit do
+ @app.standard_exception_handling do
+ raise 'blah'
+ end
+ end
+
+ assert_equal 1, e.status
+ end
+
+ assert_empty out
+ assert_match "rake aborted!\n", err
+ assert_match "blah\n", err
+ end
+
+ def test_standard_exception_handling_system_exit
+ out, err = capture_io do
+ e = assert_raises SystemExit do
+ @app.standard_exception_handling do
+ exit 0
+ end
+ end
+
+ assert_equal 0, e.status
+ end
+
+ assert_empty out
+ assert_empty err
+ end
+
+ def test_standard_exception_handling_system_exit_nonzero
+ out, err = capture_io do
+ e = assert_raises SystemExit do
+ @app.standard_exception_handling do
+ exit 5
+ end
+ end
+
+ assert_equal 5, e.status
+ end
+
+ assert_empty out
+ assert_empty err
+ end
+
def util_loader
loader = Object.new
View
97 test/test_rake_functional.rb
@@ -1,38 +1,6 @@
-begin
- old_verbose = $VERBOSE
- $VERBOSE = nil
- require 'session'
-rescue LoadError
- if File::ALT_SEPARATOR
- puts "Unable to run functional tests on MS Windows. Skipping."
- else
- puts "Unable to run functional tests -- please run \"gem install session\""
- end
-ensure
- $VERBOSE = old_verbose
-end
-
-if defined?(Session)
- if File::ALT_SEPARATOR
- puts "Unable to run functional tests on MS Windows. Skipping."
- end
-end
-
require File.expand_path('../helper', __FILE__)
require 'fileutils'
-
-# Version 2.1.9 of session has a bug where the @debug instance
-# variable is not initialized, causing warning messages. This snippet
-# of code fixes that problem.
-module Session
- class AbstractSession
- alias old_initialize initialize
- def initialize(*args)
- @debug = nil
- old_initialize(*args)
- end
- end
-end if defined? Session
+require 'open3'
class TestRakeFunctional < Rake::TestCase
@@ -59,16 +27,15 @@ def test_rake_default
rake
assert_match(/^DEFAULT$/, @out)
- assert_status
end
def test_rake_error_on_bad_task
rakefile_default
- rake "xyz"
+ rake '-t', 'xyz'
+ puts @err
assert_match(/rake aborted/, @err)
- assert_status(1)
end
def test_env_available_at_top_scope
@@ -77,16 +44,14 @@ def test_env_available_at_top_scope
rake "TESTTOPSCOPE=1"
assert_match(/^TOPSCOPE$/, @out)
- assert_status
end
def test_env_available_at_task_scope
rakefile_default
- rake "TESTTASKSCOPE=1 task_scope"
+ rake 'TESTTASKSCOPE=1', 'task_scope'
assert_match(/^TASKSCOPE$/, @out)
- assert_status
end
def test_multi_desc
@@ -283,8 +248,6 @@ def test_dry_run_bug
rake "--dry-run"
refute_match(/No such file/, @out)
-
- assert_status
end
# Test for the trace/dry_run bug found by Brian Chandler
@@ -298,7 +261,6 @@ def test_trace_bug
rake "--trace"
refute_match(/No such file/, @out)
- assert_status
end
def test_imports
@@ -309,7 +271,6 @@ def test_imports
assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
"'dynamic_deps' file should exist"
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
- assert_status
end
def test_rules_chaining_to_file_task
@@ -319,7 +280,6 @@ def test_rules_chaining_to_file_task
assert File.exist?(File.join(@tempdir, 'play.app')),
"'play.app' file should exist"
- assert_status
end
def test_file_creation_task
@@ -335,7 +295,7 @@ def test_file_creation_task
def test_dash_f_with_no_arg_foils_rakefile_lookup
rakefile_rakelib
- rake "-I rakelib -rtest1 -f"
+ rake '-I', 'rakelib', '-rtest1', '-f'
assert_match(/^TEST1$/, @out)
end
@@ -343,8 +303,9 @@ def test_dash_f_with_no_arg_foils_rakefile_lookup
def test_dot_rake_files_can_be_loaded_with_dash_r
rakefile_rakelib
- rake "-I rakelib -rtest2 -f"
+ rake '-I', 'rakelib', '-rtest2', '-f'
+ assert_empty @err
assert_match(/^TEST2$/, @out)
end
@@ -412,22 +373,6 @@ def test_file_task_dependencies_scoped_by_namespaces
assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
end
- def test_rake_returns_status_error_values
- rakefile_statusreturn
-
- rake "exit5"
-
- assert_status 5
- end
-
- def test_rake_returns_no_status_error_on_normal_exit
- rakefile_statusreturn
-
- rake "normal"
-
- assert_status 0
- end
-
def test_comment_before_task_acts_like_desc
rakefile_comments
@@ -469,42 +414,38 @@ def test_correct_number_of_tasks_reported
end
def test_file_list_is_requirable_separately
- ruby "-rrake/file_list", "-e 'puts Rake::FileList[\"a\"].size'"
+ ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size'
assert_equal "1\n", @out
- assert_equal 0, @status
end
private
# Run a shell Ruby command with command line options (using the
- # default test options). Output is captured in @out, @err and
- # @status.
+ # default test options). Output is captured in @out and @err
def ruby(*option_list)
run_ruby(@ruby_options + option_list)
end
# Run a command line rake with the give rake options. Default
# command line ruby options are included. Output is captured in
- # @out, @err and @status.
+ # @out and @err
def rake(*rake_options)
run_ruby @ruby_options + [@rake_path] + rake_options
end
# Low level ruby command runner ...
def run_ruby(option_list)
- shell = Session::Shell.new
- command = "#{Gem.ruby} #{option_list.join ' '}"
- puts "COMMAND: [#{command}]" if @verbose
- @out, @err = shell.execute command
- @status = shell.exit_status
- puts "STATUS: [#{@status}]" if @verbose
+ puts "COMMAND: [#{Gem.ruby} #{option_list.join ' '}]" if @verbose
+
+ inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list)
+ inn.close
+
+ @out = out.read
+ @err = err.read
+
puts "OUTPUT: [#{@out}]" if @verbose
puts "ERROR: [#{@err}]" if @verbose
puts "PWD: [#{Dir.pwd}]" if @verbose
- shell.close
end
- def assert_status(expected_status=0)
- assert_equal expected_status, @status
- end
-end if defined?(Session)
+end
View
8 test/test_rake_task_manager.rb
@@ -19,6 +19,14 @@ def test_define_task
assert_equal @tm, t.application
end
+ def test_index
+ e = assert_raises RuntimeError do
+ @tm['bad']
+ end
+
+ assert_equal "Don't know how to build task 'bad'", e.message
+ end
+
def test_name_lookup
t = @tm.define_task(Rake::Task, :t)
assert_equal t, @tm[:t]
Please sign in to comment.
Something went wrong with that request. Please try again.