* lib/rake.rb, lib/rake/*.rb: Upgrade to rake-10.3.2

[fix GH-668]
* test/rake/*.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2014-07-15 03:07:37 +00:00
parent 031e1570b9
commit 6361928083
63 changed files with 1077 additions and 307 deletions

View File

@ -1,3 +1,9 @@
Tue Jul 15 12:00:03 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/rake.rb, lib/rake/*.rb: Upgrade to rake-10.3.2
[fix GH-668]
* test/rake/*.rb: ditto.
Mon Jul 14 19:14:51 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp> Mon Jul 14 19:14:51 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: modify WIN32OLE class document and * ext/win32ole/win32ole.c: modify WIN32OLE class document and

View File

@ -1,5 +1,4 @@
#-- #--
# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com) # Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
@ -21,9 +20,14 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
#++ #++
module Rake
VERSION = '10.3.2'
end
require 'rake/version' require 'rake/version'
# :stopdoc: # :stopdoc:
# TODO: Remove in Rake 11
RAKEVERSION = Rake::VERSION RAKEVERSION = Rake::VERSION
# :startdoc: # :startdoc:
@ -41,6 +45,7 @@ require 'rake/ext/time'
require 'rake/win32' require 'rake/win32'
require 'rake/linked_list' require 'rake/linked_list'
require 'rake/cpu_counter'
require 'rake/scope' require 'rake/scope'
require 'rake/task_argument_error' require 'rake/task_argument_error'
require 'rake/rule_recursion_overflow_error' require 'rake/rule_recursion_overflow_error'

View File

@ -24,11 +24,13 @@
require 'rbconfig' require 'rbconfig'
# ##
# Alternate implementations of system() and backticks `` on Windows # Alternate implementations of system() and backticks `` on Windows
# for ruby-1.8 and earlier. # for ruby-1.8 and earlier.
# #--
module Rake::AltSystem # TODO: Remove in Rake 11
module Rake::AltSystem # :nodoc: all
WINDOWS = RbConfig::CONFIG["host_os"] =~ WINDOWS = RbConfig::CONFIG["host_os"] =~
%r!(msdos|mswin|djgpp|mingw|[Ww]indows)! %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!

View File

@ -12,10 +12,10 @@ module Rake
CommandLineOptionError = Class.new(StandardError) CommandLineOptionError = Class.new(StandardError)
###################################################################### ##
# Rake main application object. When invoking +rake+ from the # Rake main application object. When invoking +rake+ from the
# command line, a Rake::Application object is created and run. # command line, a Rake::Application object is created and run.
#
class Application class Application
include TaskManager include TaskManager
include TraceOutput include TraceOutput
@ -84,7 +84,7 @@ module Rake
standard_exception_handling do standard_exception_handling do
@name = app_name @name = app_name
handle_options handle_options
collect_tasks collect_command_line_tasks
end end
end end
@ -117,8 +117,8 @@ module Rake
thread_pool.join thread_pool.join
if options.job_stats if options.job_stats
stats = thread_pool.statistics stats = thread_pool.statistics
puts "Maximum active threads: #{stats[:max_active_threads]}" puts "Maximum active threads: #{stats[:max_active_threads]} + main"
puts "Total threads in play: #{stats[:total_threads_in_play]}" puts "Total threads in play: #{stats[:total_threads_in_play]} + main"
end end
ThreadHistoryDisplay.new(thread_pool.history).show if ThreadHistoryDisplay.new(thread_pool.history).show if
options.job_stats == :history options.job_stats == :history
@ -138,30 +138,41 @@ module Rake
# Return the thread pool used for multithreaded processing. # Return the thread pool used for multithreaded processing.
def thread_pool # :nodoc: def thread_pool # :nodoc:
@thread_pool ||= ThreadPool.new(options.thread_pool_size || FIXNUM_MAX) @thread_pool ||= ThreadPool.new(options.thread_pool_size || Rake.suggested_thread_count-1)
end end
# private ---------------------------------------------------------------- # internal ----------------------------------------------------------------
def invoke_task(task_string) # Invokes a task with arguments that are extracted from +task_string+
def invoke_task(task_string) # :nodoc:
name, args = parse_task_string(task_string) name, args = parse_task_string(task_string)
t = self[name] t = self[name]
t.invoke(*args) t.invoke(*args)
end end
def parse_task_string(string) def parse_task_string(string) # :nodoc:
if string =~ /^([^\[]+)(\[(.*)\])$/ /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
name = $1
args = $3.split(/\s*,\s*/) name = $1
else remaining_args = $2
name = string
args = [] return string, [] unless name
end return name, [] if remaining_args.empty?
[name, args]
args = []
begin
/((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
remaining_args = $2
args << $1.gsub(/\\(.)/, '\1')
end while remaining_args
return name, args
end end
# Provide standard exception handling for the given block. # Provide standard exception handling for the given block.
def standard_exception_handling def standard_exception_handling # :nodoc:
yield yield
rescue SystemExit rescue SystemExit
# Exit silently with current status # Exit silently with current status
@ -177,22 +188,47 @@ module Rake
# Exit the program because of an unhandle exception. # Exit the program because of an unhandle exception.
# (may be overridden by subclasses) # (may be overridden by subclasses)
def exit_because_of_exception(ex) def exit_because_of_exception(ex) # :nodoc:
exit(false) exit(false)
end end
# Display the error message that caused the exception. # Display the error message that caused the exception.
def display_error_message(ex) def display_error_message(ex) # :nodoc:
trace "#{name} aborted!" trace "#{name} aborted!"
trace ex.message display_exception_details(ex)
trace "Tasks: #{ex.chain}" if has_chain?(ex)
trace "(See full trace by running task with --trace)" unless
options.backtrace
end
def display_exception_details(ex) # :nodoc:
seen = Thread.current[:rake_display_exception_details_seen] ||= []
return if seen.include? ex
seen << ex
display_exception_message_details(ex)
display_exception_backtrace(ex)
display_exception_details(ex.cause) if has_cause?(ex)
end
def has_cause?(ex) # :nodoc:
ex.respond_to?(:cause) && ex.cause
end
def display_exception_message_details(ex) # :nodoc:
if ex.instance_of?(RuntimeError)
trace ex.message
else
trace "#{ex.class.name}: #{ex.message}"
end
end
def display_exception_backtrace(ex) # :nodoc:
if options.backtrace if options.backtrace
trace ex.backtrace.join("\n") trace ex.backtrace.join("\n")
else else
trace Backtrace.collapse(ex.backtrace).join("\n") trace Backtrace.collapse(ex.backtrace).join("\n")
end end
trace "Tasks: #{ex.chain}" if has_chain?(ex)
trace "(See full trace by running task with --trace)" unless
options.backtrace
end end
# Warn about deprecated usage. # Warn about deprecated usage.
@ -200,7 +236,7 @@ module Rake
# Example: # Example:
# Rake.application.deprecate("import", "Rake.import", caller.first) # Rake.application.deprecate("import", "Rake.import", caller.first)
# #
def deprecate(old_usage, new_usage, call_site) def deprecate(old_usage, new_usage, call_site) # :nodoc:
unless options.ignore_deprecate unless options.ignore_deprecate
$stderr.puts "WARNING: '#{old_usage}' is deprecated. " + $stderr.puts "WARNING: '#{old_usage}' is deprecated. " +
"Please use '#{new_usage}' instead.\n" + "Please use '#{new_usage}' instead.\n" +
@ -209,14 +245,14 @@ module Rake
end end
# Does the exception have a task invocation chain? # Does the exception have a task invocation chain?
def has_chain?(exception) def has_chain?(exception) # :nodoc:
exception.respond_to?(:chain) && exception.chain exception.respond_to?(:chain) && exception.chain
end end
private :has_chain? private :has_chain?
# True if one of the files in RAKEFILES is in the current directory. # True if one of the files in RAKEFILES is in the current directory.
# If a match is found, it is copied into @rakefile. # If a match is found, it is copied into @rakefile.
def have_rakefile def have_rakefile # :nodoc:
@rakefiles.each do |fn| @rakefiles.each do |fn|
if File.exist?(fn) if File.exist?(fn)
others = FileList.glob(fn, File::FNM_CASEFOLD) others = FileList.glob(fn, File::FNM_CASEFOLD)
@ -229,23 +265,23 @@ module Rake
end end
# True if we are outputting to TTY, false otherwise # True if we are outputting to TTY, false otherwise
def tty_output? def tty_output? # :nodoc:
@tty_output @tty_output
end end
# Override the detected TTY output state (mostly for testing) # Override the detected TTY output state (mostly for testing)
def tty_output=(tty_output_state) def tty_output=(tty_output_state) # :nodoc:
@tty_output = tty_output_state @tty_output = tty_output_state
end end
# We will truncate output if we are outputting to a TTY or if we've been # We will truncate output if we are outputting to a TTY or if we've been
# given an explicit column width to honor # given an explicit column width to honor
def truncate_output? def truncate_output? # :nodoc:
tty_output? || @terminal_columns.nonzero? tty_output? || @terminal_columns.nonzero?
end end
# Display the tasks and comments. # Display the tasks and comments.
def display_tasks_and_comments def display_tasks_and_comments # :nodoc:
displayable_tasks = tasks.select { |t| displayable_tasks = tasks.select { |t|
(options.show_all_tasks || t.comment) && (options.show_all_tasks || t.comment) &&
t.name =~ options.show_task_pattern t.name =~ options.show_task_pattern
@ -284,7 +320,7 @@ module Rake
end end
end end
def terminal_width def terminal_width # :nodoc:
if @terminal_columns.nonzero? if @terminal_columns.nonzero?
result = @terminal_columns result = @terminal_columns
else else
@ -296,28 +332,28 @@ module Rake
end end
# Calculate the dynamic width of the # Calculate the dynamic width of the
def dynamic_width def dynamic_width # :nodoc:
@dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput) @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
end end
def dynamic_width_stty def dynamic_width_stty # :nodoc:
%x{stty size 2>/dev/null}.split[1].to_i %x{stty size 2>/dev/null}.split[1].to_i
end end
def dynamic_width_tput def dynamic_width_tput # :nodoc:
%x{tput cols 2>/dev/null}.to_i %x{tput cols 2>/dev/null}.to_i
end end
def unix? def unix? # :nodoc:
RbConfig::CONFIG['host_os'] =~ RbConfig::CONFIG['host_os'] =~
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
end end
def windows? def windows? # :nodoc:
Win32.windows? Win32.windows?
end end
def truncate(string, width) def truncate(string, width) # :nodoc:
if string.nil? if string.nil?
"" ""
elsif string.length <= width elsif string.length <= width
@ -328,19 +364,19 @@ module Rake
end end
# Display the tasks and prerequisites # Display the tasks and prerequisites
def display_prerequisites def display_prerequisites # :nodoc:
tasks.each do |t| tasks.each do |t|
puts "#{name} #{t.name}" puts "#{name} #{t.name}"
t.prerequisites.each { |pre| puts " #{pre}" } t.prerequisites.each { |pre| puts " #{pre}" }
end end
end end
def trace(*strings) def trace(*strings) # :nodoc:
options.trace_output ||= $stderr options.trace_output ||= $stderr
trace_on(options.trace_output, *strings) trace_on(options.trace_output, *strings)
end end
def sort_options(options) def sort_options(options) # :nodoc:
options.sort_by { |opt| options.sort_by { |opt|
opt.select { |o| o =~ /^-/ }.map { |o| o.downcase }.sort.reverse opt.select { |o| o =~ /^-/ }.map { |o| o.downcase }.sort.reverse
} }
@ -349,11 +385,11 @@ module Rake
# A list of all the standard options used in rake, suitable for # A list of all the standard options used in rake, suitable for
# passing to OptionParser. # passing to OptionParser.
def standard_rake_options def standard_rake_options # :nodoc:
sort_options( sort_options(
[ [
['--all', '-A', ['--all', '-A',
"Show all tasks, even uncommented ones", "Show all tasks, even uncommented ones (in combination with -T or -D)",
lambda { |value| lambda { |value|
options.show_all_tasks = value options.show_all_tasks = value
} }
@ -365,6 +401,12 @@ module Rake
select_trace_output(options, 'backtrace', value) select_trace_output(options, 'backtrace', value)
} }
], ],
['--build-all', '-B',
"Build all prerequisites, including those which are up-to-date.",
lambda { |value|
options.build_all = true
}
],
['--comments', ['--comments',
"Show commented tasks only", "Show commented tasks only",
lambda { |value| lambda { |value|
@ -407,9 +449,17 @@ module Rake
], ],
['--jobs', '-j [NUMBER]', ['--jobs', '-j [NUMBER]',
"Specifies the maximum number of tasks to execute in parallel. " + "Specifies the maximum number of tasks to execute in parallel. " +
"(default is 2)", "(default is number of CPU cores + 4)",
lambda { |value| lambda { |value|
options.thread_pool_size = [(value || 2).to_i, 2].max if value.nil? || value == ''
value = FIXNUM_MAX
elsif value =~ /^\d+$/
value = value.to_i
else
value = Rake.suggested_thread_count
end
value = 1 if value < 1
options.thread_pool_size = value - 1
} }
], ],
['--job-stats [LEVEL]', ['--job-stats [LEVEL]',
@ -443,8 +493,8 @@ module Rake
"Do not log messages to standard output.", "Do not log messages to standard output.",
lambda { |value| Rake.verbose(false) } lambda { |value| Rake.verbose(false) }
], ],
['--rakefile', '-f [FILE]', ['--rakefile', '-f [FILENAME]',
"Use FILE as the rakefile.", "Use FILENAME as the rakefile to search for.",
lambda { |value| lambda { |value|
value ||= '' value ||= ''
@rakefiles.clear @rakefiles.clear
@ -545,14 +595,14 @@ module Rake
]) ])
end end
def select_tasks_to_show(options, show_tasks, value) def select_tasks_to_show(options, show_tasks, value) # :nodoc:
options.show_tasks = show_tasks options.show_tasks = show_tasks
options.show_task_pattern = Regexp.new(value || '') options.show_task_pattern = Regexp.new(value || '')
Rake::TaskManager.record_task_metadata = true Rake::TaskManager.record_task_metadata = true
end end
private :select_tasks_to_show private :select_tasks_to_show
def select_trace_output(options, trace_option, value) def select_trace_output(options, trace_option, value) # :nodoc:
value = value.strip unless value.nil? value = value.strip unless value.nil?
case value case value
when 'stdout' when 'stdout'
@ -567,7 +617,7 @@ module Rake
private :select_trace_output private :select_trace_output
# Read and handle the command line options. # Read and handle the command line options.
def handle_options def handle_options # :nodoc:
options.rakelib = ['rakelib'] options.rakelib = ['rakelib']
options.trace_output = $stderr options.trace_output = $stderr
@ -588,7 +638,7 @@ module Rake
# Similar to the regular Ruby +require+ command, but will check # Similar to the regular Ruby +require+ command, but will check
# for *.rake files in addition to *.rb files. # for *.rake files in addition to *.rb files.
def rake_require(file_name, paths=$LOAD_PATH, loaded=$") def rake_require(file_name, paths=$LOAD_PATH, loaded=$") # :nodoc:
fn = file_name + ".rake" fn = file_name + ".rake"
return false if loaded.include?(fn) return false if loaded.include?(fn)
paths.each do |path| paths.each do |path|
@ -602,7 +652,7 @@ module Rake
fail LoadError, "Can't find #{file_name}" fail LoadError, "Can't find #{file_name}"
end end
def find_rakefile_location def find_rakefile_location # :nodoc:
here = Dir.pwd here = Dir.pwd
until (fn = have_rakefile) until (fn = have_rakefile)
Dir.chdir("..") Dir.chdir("..")
@ -614,7 +664,7 @@ module Rake
Dir.chdir(Rake.original_dir) Dir.chdir(Rake.original_dir)
end end
def print_rakefile_directory(location) def print_rakefile_directory(location) # :nodoc:
$stderr.puts "(in #{Dir.pwd})" unless $stderr.puts "(in #{Dir.pwd})" unless
options.silent or original_dir == location options.silent or original_dir == location
end end
@ -645,13 +695,13 @@ module Rake
load_imports load_imports
end end
def glob(path, &block) def glob(path, &block) # :nodoc:
FileList.glob(path.gsub("\\", '/')).each(&block) FileList.glob(path.gsub("\\", '/')).each(&block)
end end
private :glob private :glob
# The directory path containing the system wide rakefiles. # The directory path containing the system wide rakefiles.
def system_dir def system_dir # :nodoc:
@system_dir ||= @system_dir ||=
begin begin
if ENV['RAKE_SYSTEM'] if ENV['RAKE_SYSTEM']
@ -677,7 +727,7 @@ module Rake
# Collect the list of tasks on the command line. If no tasks are # Collect the list of tasks on the command line. If no tasks are
# given, return a list containing only the default task. # given, return a list containing only the default task.
# Environmental assignments are processed at this time as well. # Environmental assignments are processed at this time as well.
def collect_tasks def collect_command_line_tasks # :nodoc:
@top_level_tasks = [] @top_level_tasks = []
ARGV.each do |arg| ARGV.each do |arg|
if arg =~ /^(\w+)=(.*)$/m if arg =~ /^(\w+)=(.*)$/m
@ -691,28 +741,33 @@ module Rake
# Default task name ("default"). # Default task name ("default").
# (May be overridden by subclasses) # (May be overridden by subclasses)
def default_task_name def default_task_name # :nodoc:
"default" "default"
end end
# Add a file to the list of files to be imported. # Add a file to the list of files to be imported.
def add_import(fn) def add_import(fn) # :nodoc:
@pending_imports << fn @pending_imports << fn
end end
# Load the pending list of imported files. # Load the pending list of imported files.
def load_imports def load_imports # :nodoc:
while fn = @pending_imports.shift while fn = @pending_imports.shift
next if @imported.member?(fn) next if @imported.member?(fn)
fn_task = lookup(fn) and fn_task.invoke fn_task = lookup(fn) and fn_task.invoke
ext = File.extname(fn) ext = File.extname(fn)
loader = @loaders[ext] || @default_loader loader = @loaders[ext] || @default_loader
loader.load(fn) loader.load(fn)
if fn_task = lookup(fn) and fn_task.needed?
fn_task.reenable
fn_task.invoke
loader.load(fn)
end
@imported << fn @imported << fn
end end
end end
def rakefile_location(backtrace=caller) def rakefile_location(backtrace=caller) # :nodoc:
backtrace.map { |t| t[/([^:]+):/, 1] } backtrace.map { |t| t[/([^:]+):/, 1] }
re = /^#{@rakefile}$/ re = /^#{@rakefile}$/

View File

@ -1,5 +1,5 @@
module Rake module Rake
module Backtrace module Backtrace # :nodoc: all
SYS_KEYS = RbConfig::CONFIG.keys.grep(/(prefix|libdir)/) SYS_KEYS = RbConfig::CONFIG.keys.grep(/(prefix|libdir)/)
SYS_PATHS = RbConfig::CONFIG.values_at(*SYS_KEYS).uniq + SYS_PATHS = RbConfig::CONFIG.values_at(*SYS_KEYS).uniq +
[ File.join(File.dirname(__FILE__), "..") ] [ File.join(File.dirname(__FILE__), "..") ]
@ -9,6 +9,9 @@ module Rake
map { |f| File.expand_path(f) }. map { |f| File.expand_path(f) }.
reject { |s| s.nil? || s =~ /^ *$/ } reject { |s| s.nil? || s =~ /^ *$/ }
SUPPRESSED_PATHS_RE = SUPPRESSED_PATHS.map { |f| Regexp.quote(f) }.join("|") SUPPRESSED_PATHS_RE = SUPPRESSED_PATHS.map { |f| Regexp.quote(f) }.join("|")
SUPPRESSED_PATHS_RE << "|^org\\/jruby\\/\\w+\\.java" if
Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
SUPPRESS_PATTERN = %r!(\A(#{SUPPRESSED_PATHS_RE})|bin/rake:\d+)!i SUPPRESS_PATTERN = %r!(\A(#{SUPPRESSED_PATHS_RE})|bin/rake:\d+)!i
def self.collapse(backtrace) def self.collapse(backtrace)

View File

@ -31,9 +31,30 @@ module Rake
begin begin
rm_r file_name, opts rm_r file_name, opts
rescue StandardError => ex rescue StandardError => ex
puts "Failed to remove #{file_name}: #{ex}" puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name)
end end
end end
def file_already_gone?(file_name)
return false if File.exist?(file_name)
path = file_name
prev = nil
while path = File.dirname(path)
return false if cant_be_deleted?(path)
break if [prev, "."].include?(path)
prev = path
end
true
end
private_class_method :file_already_gone?
def cant_be_deleted?(path_name)
File.exist?(path_name) &&
(!File.readable?(path_name) || !File.executable?(path_name))
end
private_class_method :cant_be_deleted?
end end
end end

View File

@ -1,8 +1,8 @@
module Rake module Rake
# ########################################################################## ##
# Mixin for creating easily cloned objects. # Mixin for creating easily cloned objects.
#
module Cloneable module Cloneable # :nodoc:
# The hook that invoked by 'clone' and 'dup' methods. # The hook that invoked by 'clone' and 'dup' methods.
def initialize_copy(source) def initialize_copy(source)
super super

View File

@ -9,9 +9,7 @@ require 'rake/file_list'
module Rake # :nodoc: module Rake # :nodoc:
#################################################################### class FtpFile # :nodoc: all
# <b>Note:</b> <em> Not released for general use.</em>
class FtpFile
attr_reader :name, :size, :owner, :group, :time attr_reader :name, :size, :owner, :group, :time
def self.date def self.date
@ -68,9 +66,9 @@ module Rake # :nodoc:
end end
end end
#################################################################### ##
# Manage the uploading of files to an FTP account. # Manage the uploading of files to an FTP account.
class FtpUploader class FtpUploader # :nodoc:
# Log uploads to standard output when true. # Log uploads to standard output when true.
attr_accessor :verbose attr_accessor :verbose

View File

@ -14,8 +14,10 @@ HostInfo = Struct.new(:name, :webdir, :pkgdir)
# :startdoc: # :startdoc:
# TODO: Move to contrib/sshpublisher
#--
# Manage several publishers as a single entity. # Manage several publishers as a single entity.
class CompositePublisher class CompositePublisher # :nodoc:
def initialize def initialize
@publishers = [] @publishers = []
end end
@ -31,9 +33,11 @@ class CompositePublisher
end end
end end
# TODO: Remove in Rake 11, duplicated
#--
# Publish an entire directory to an existing remote directory using # Publish an entire directory to an existing remote directory using
# SSH. # SSH.
class SshDirPublisher class SshDirPublisher # :nodoc: all
def initialize(host, remote_dir, local_dir) def initialize(host, remote_dir, local_dir)
@host = host @host = host
@remote_dir = remote_dir @remote_dir = remote_dir
@ -45,8 +49,10 @@ class SshDirPublisher
end end
end end
# TODO: Remove in Rake 11, duplicated
#--
# Publish an entire directory to a fresh remote directory using SSH. # Publish an entire directory to a fresh remote directory using SSH.
class SshFreshDirPublisher < SshDirPublisher class SshFreshDirPublisher < SshDirPublisher # :nodoc: all
def upload def upload
run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
run %{ssh #{@host} mkdir #{@remote_dir}} run %{ssh #{@host} mkdir #{@remote_dir}}
@ -54,8 +60,10 @@ class SshFreshDirPublisher < SshDirPublisher
end end
end end
# TODO: Remove in Rake 11, duplicated
#--
# Publish a list of files to an existing remote directory. # Publish a list of files to an existing remote directory.
class SshFilePublisher class SshFilePublisher # :nodoc: all
# Create a publisher using the give host information. # Create a publisher using the give host information.
def initialize(host, remote_dir, local_dir, *files) def initialize(host, remote_dir, local_dir, *files)
@host = host @host = host

View File

@ -1,8 +1,10 @@
# TODO: Remove in Rake 11
require 'rake/contrib/sshpublisher' require 'rake/contrib/sshpublisher'
module Rake module Rake
class RubyForgePublisher < SshDirPublisher class RubyForgePublisher < SshDirPublisher # :nodoc: all
attr_reader :project, :proj_id, :user attr_reader :project, :proj_id, :user
def initialize(projname, user) def initialize(projname, user)

View File

@ -8,22 +8,30 @@ module Rake
class SshDirPublisher class SshDirPublisher
include Rake::DSL include Rake::DSL
# Creates an SSH publisher which will scp all files in +local_dir+ to
# +remote_dir+ on +host+
def initialize(host, remote_dir, local_dir) def initialize(host, remote_dir, local_dir)
@host = host @host = host
@remote_dir = remote_dir @remote_dir = remote_dir
@local_dir = local_dir @local_dir = local_dir
end end
# Uploads the files
def upload def upload
sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}} sh "scp", "-rq", "#{@local_dir}/*", "#{@host}:#{@remote_dir}"
end end
end end
# Publish an entire directory to a fresh remote directory using SSH. # Publish an entire directory to a fresh remote directory using SSH.
class SshFreshDirPublisher < SshDirPublisher class SshFreshDirPublisher < SshDirPublisher
# Uploads the files after removing the existing remote directory.
def upload def upload
sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil sh "ssh", @host, "rm", "-rf", @remote_dir rescue nil
sh %{ssh #{@host} mkdir #{@remote_dir}} sh "ssh", @host, "mkdir", @remote_dir
super super
end end
end end
@ -32,7 +40,9 @@ module Rake
class SshFilePublisher class SshFilePublisher
include Rake::DSL include Rake::DSL
# Create a publisher using the give host information. # Creates an SSH publisher which will scp all +files+ in +local_dir+ to
# +remote_dir+ on +host+.
def initialize(host, remote_dir, local_dir, *files) def initialize(host, remote_dir, local_dir, *files)
@host = host @host = host
@remote_dir = remote_dir @remote_dir = remote_dir
@ -40,10 +50,11 @@ module Rake
@files = files @files = files
end end
# Upload the local directory to the remote directory. # Uploads the files
def upload def upload
@files.each do |fn| @files.each do |fn|
sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}} sh "scp", "-q", "#{@local_dir}/#{fn}", "#{@host}:#{@remote_dir}"
end end
end end
end end

View File

@ -1,2 +1,4 @@
# TODO: Remove in Rake 11
fail "ERROR: 'rake/contrib/sys' is obsolete and no longer supported. " + fail "ERROR: 'rake/contrib/sys' is obsolete and no longer supported. " +
"Use 'FileUtils' instead." "Use 'FileUtils' instead."

109
lib/rake/cpu_counter.rb Normal file
View File

@ -0,0 +1,109 @@
require 'rbconfig'
# TODO: replace with IO.popen using array-style arguments in Rake 11
require 'open3'
module Rake
# Based on a script at:
# http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed
class CpuCounter # :nodoc: all
def self.count
new.count_with_default
end
def count_with_default(default=4)
count || default
rescue StandardError
default
end
def count
if defined?(Java::Java)
count_via_java_runtime
else
case RbConfig::CONFIG['host_os']
when /darwin9/
count_via_hwprefs_cpu_count
when /darwin/
count_via_hwprefs_thread_count || count_via_sysctl
when /linux/
count_via_cpuinfo
when /bsd/
count_via_sysctl
when /mswin|mingw/
count_via_win32
else
# Try everything
count_via_win32 ||
count_via_sysctl ||
count_via_hwprefs_thread_count ||
count_via_hwprefs_cpu_count
end
end
end
def count_via_java_runtime
Java::Java.lang.Runtime.getRuntime.availableProcessors
rescue StandardError
nil
end
def count_via_win32
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
cpu.to_enum.first.NumberOfCores
rescue StandardError, LoadError
nil
end
def count_via_cpuinfo
open('/proc/cpuinfo') { |f| f.readlines }.grep(/processor/).size
rescue StandardError
nil
end
def count_via_hwprefs_thread_count
run 'hwprefs', 'thread_count'
end
def count_via_hwprefs_cpu_count
run 'hwprefs', 'cpu_count'
end
def count_via_sysctl
run 'sysctl', '-n', 'hw.ncpu'
end
def run(command, *args)
cmd = resolve_command(command)
if cmd
Open3.popen3 cmd, *args do |inn, out, err,|
inn.close
err.read
out.read.to_i
end
else
nil
end
end
def resolve_command(command)
look_for_command("/usr/sbin", command) ||
look_for_command("/sbin", command) ||
in_path_command(command)
end
def look_for_command(dir, command)
path = File.join(dir, command)
File.exist?(path) ? path : nil
end
def in_path_command(command)
Open3.popen3 'which', command do |_, out,|
out.eof? ? nil : command
end
end
end
end

View File

@ -2,6 +2,10 @@ module Rake
# Default Rakefile loader used by +import+. # Default Rakefile loader used by +import+.
class DefaultLoader class DefaultLoader
##
# Loads a rakefile into the current application from +fn+
def load(fn) def load(fn)
Rake.load_rakefile(File.expand_path(fn)) Rake.load_rakefile(File.expand_path(fn))
end end

View File

@ -6,6 +6,9 @@ module Rake
## ##
# DSL is a module that provides #task, #desc, #namespace, etc. Use this # DSL is a module that provides #task, #desc, #namespace, etc. Use this
# when you'd like to use rake outside the top level scope. # when you'd like to use rake outside the top level scope.
#
# For a Rakefile you run from the comamnd line this module is automatically
# included.
module DSL module DSL
@ -21,14 +24,45 @@ module Rake
private private
# Declare a basic task. # :call-seq:
# task task_name
# task task_name: dependencies
# task task_name, arguments => dependencies
# task task_name, argument[, argument ...], :needs: dependencies
# #
# Example: # Declare a basic task. The +task_name+ is always the first argument. If
# task :clobber => [:clean] do # the task name contains a ":" it is defined in that namespace.
#
# The +dependencies+ may be a single task name or an Array of task names.
# The +argument+ (a single name) or +arguments+ (an Array of names) define
# the arguments provided to the task.
#
# The task, argument and dependency names may be either symbols or
# strings.
#
# A task with a single dependency:
#
# task clobber: %w[clean] do
# rm_rf "html" # rm_rf "html"
# end # end
# #
def task(*args, &block) # A task with an argument and a dependency:
#
# task :package, [:version] => :test do |t, args|
# # ...
# end
#
# To invoke this task from the command line:
#
# $ rake package[1.2.3]
#
# Alternate definition:
#
# task :package, :version, needs: :test do |t, args|
# # ...
# end
#
def task(*args, &block) # :doc:
Rake::Task.define_task(*args, &block) Rake::Task.define_task(*args, &block)
end end
@ -45,7 +79,7 @@ module Rake
# end # end
# end # end
# #
def file(*args, &block) def file(*args, &block) # :doc:
Rake::FileTask.define_task(*args, &block) Rake::FileTask.define_task(*args, &block)
end end
@ -61,7 +95,7 @@ module Rake
# Example: # Example:
# directory "testdata/doc" # directory "testdata/doc"
# #
def directory(*args, &block) def directory(*args, &block) # :doc:
result = file_create(*args, &block) result = file_create(*args, &block)
dir, _ = *Rake.application.resolve_args(args) dir, _ = *Rake.application.resolve_args(args)
Rake.each_dir_parent(dir) do |d| Rake.each_dir_parent(dir) do |d|
@ -78,9 +112,9 @@ module Rake
# about it) # about it)
# #
# Example: # Example:
# multitask :deploy => [:deploy_gem, :deploy_rdoc] # multitask deploy: %w[deploy_gem deploy_rdoc]
# #
def multitask(*args, &block) def multitask(*args, &block) # :doc:
Rake::MultiTask.define_task(*args, &block) Rake::MultiTask.define_task(*args, &block)
end end
@ -88,14 +122,22 @@ module Rake
# block. Returns a NameSpace object that can be used to lookup # block. Returns a NameSpace object that can be used to lookup
# tasks defined in the namespace. # tasks defined in the namespace.
# #
# E.g. # Example:
# #
# ns = namespace "nested" do # ns = namespace "nested" do
# # the "nested:run" task
# task :run # task :run
# end # end
# task_run = ns[:run] # find :run in the given namespace. # task_run = ns[:run] # find :run in the given namespace.
# #
def namespace(name=nil, &block) # Tasks can also be defined in a namespace by using a ":" in the task
# name:
#
# task "nested:test" do
# # ...
# end
#
def namespace(name=nil, &block) # :doc:
name = name.to_s if name.kind_of?(Symbol) name = name.to_s if name.kind_of?(Symbol)
name = name.to_str if name.respond_to?(:to_str) name = name.to_str if name.respond_to?(:to_str)
unless name.kind_of?(String) || name.nil? unless name.kind_of?(String) || name.nil?
@ -108,23 +150,22 @@ module Rake
# #
# Example: # Example:
# rule '.o' => '.c' do |t| # rule '.o' => '.c' do |t|
# sh %{cc -o #{t.name} #{t.source}} # sh 'cc', '-o', t.name, t.source
# end # end
# #
def rule(*args, &block) def rule(*args, &block) # :doc:
Rake::Task.create_rule(*args, &block) Rake::Task.create_rule(*args, &block)
end end
# Describe the next rake task. # Describes the next rake task. Duplicate descriptions are discarded.
# Duplicate descriptions are discarded.
# #
# Example: # Example:
# desc "Run the Unit Tests" # desc "Run the Unit Tests"
# task :test => [:build] # task test: [:build]
# runtests # # ... run tests
# end # end
# #
def desc(description) def desc(description) # :doc:
Rake.application.last_description = description Rake.application.last_description = description
end end
@ -142,7 +183,7 @@ module Rake
# Example: # Example:
# import ".depend", "my_rules" # import ".depend", "my_rules"
# #
def import(*fns) def import(*fns) # :doc:
fns.each do |fn| fns.each do |fn|
Rake.application.add_import(fn) Rake.application.add_import(fn)
end end

View File

@ -5,11 +5,14 @@ module Rake
include Comparable include Comparable
include Singleton include Singleton
##
# The EarlyTime always comes before +other+!
def <=>(other) def <=>(other)
-1 -1
end end
def to_s def to_s # :nodoc:
"<EARLY TIME>" "<EARLY TIME>"
end end
end end

View File

@ -1,8 +1,5 @@
######################################################################
# Core extension library
#
class Module class Module
# Check for an existing method in the current class before extending. IF # Check for an existing method in the current class before extending. If
# the method already exists, then a warning is printed and the extension is # the method already exists, then a warning is printed and the extension is
# not added. Otherwise the block is yielded and any definitions in the # not added. Otherwise the block is yielded and any definitions in the
# block will take effect. # block will take effect.
@ -17,7 +14,7 @@ class Module
# end # end
# end # end
# #
def rake_extension(method) def rake_extension(method) # :nodoc:
if method_defined?(method) if method_defined?(method)
$stderr.puts "WARNING: Possible conflict with Rake extension: " + $stderr.puts "WARNING: Possible conflict with Rake extension: " +
"#{self}##{method} already exists" "#{self}##{method} already exists"

View File

@ -1 +1,2 @@
# TODO: remove in Rake 11

View File

@ -1,8 +1,5 @@
require 'rake/ext/core' require 'rake/ext/core'
######################################################################
# Rake extension methods for String.
#
class String class String
rake_extension("ext") do rake_extension("ext") do
@ -11,6 +8,8 @@ class String
# is not given, or is the empty string, remove any existing extension. # is not given, or is the empty string, remove any existing extension.
# #
# +ext+ is a user added method for the String class. # +ext+ is a user added method for the String class.
#
# This String extension comes from Rake
def ext(newext='') def ext(newext='')
return self.dup if ['.', '..'].include? self return self.dup if ['.', '..'].include? self
newext = (newext =~ /^\./) ? newext : ("." + newext) if newext != '' newext = (newext =~ /^\./) ? newext : ("." + newext) if newext != ''
@ -20,6 +19,8 @@ class String
rake_extension("pathmap") do rake_extension("pathmap") do
# Explode a path into individual components. Used by +pathmap+. # Explode a path into individual components. Used by +pathmap+.
#
# This String extension comes from Rake
def pathmap_explode def pathmap_explode
head, tail = File.split(self) head, tail = File.split(self)
return [self] if head == self return [self] if head == self
@ -32,6 +33,8 @@ class String
# Extract a partial path from the path. Include +n+ directories from the # Extract a partial path from the path. Include +n+ directories from the
# front end (left hand side) if +n+ is positive. Include |+n+| # front end (left hand side) if +n+ is positive. Include |+n+|
# directories from the back end (right hand side) if +n+ is negative. # directories from the back end (right hand side) if +n+ is negative.
#
# This String extension comes from Rake
def pathmap_partial(n) def pathmap_partial(n)
dirs = File.dirname(self).pathmap_explode dirs = File.dirname(self).pathmap_explode
partial_dirs = partial_dirs =
@ -48,6 +51,8 @@ class String
# Preform the pathmap replacement operations on the given path. The # Preform the pathmap replacement operations on the given path. The
# patterns take the form 'pat1,rep1;pat2,rep2...'. # patterns take the form 'pat1,rep1;pat2,rep2...'.
#
# This String extension comes from Rake
def pathmap_replace(patterns, &block) def pathmap_replace(patterns, &block)
result = self result = self
patterns.split(';').each do |pair| patterns.split(';').each do |pair|
@ -69,35 +74,36 @@ class String
# controls the details of the mapping. The following special patterns are # controls the details of the mapping. The following special patterns are
# recognized: # recognized:
# #
# * <b>%p</b> -- The complete path. # <tt>%p</tt> :: The complete path.
# * <b>%f</b> -- The base file name of the path, with its file extension, # <tt>%f</tt> :: The base file name of the path, with its file extension,
# but without any directories. # but without any directories.
# * <b>%n</b> -- The file name of the path without its file extension. # <tt>%n</tt> :: The file name of the path without its file extension.
# * <b>%d</b> -- The directory list of the path. # <tt>%d</tt> :: The directory list of the path.
# * <b>%x</b> -- The file extension of the path. An empty string if there # <tt>%x</tt> :: The file extension of the path. An empty string if there
# is no extension. # is no extension.
# * <b>%X</b> -- Everything *but* the file extension. # <tt>%X</tt> :: Everything *but* the file extension.
# * <b>%s</b> -- The alternate file separator if defined, otherwise use # <tt>%s</tt> :: The alternate file separator if defined, otherwise use #
# the standard file separator. # the standard file separator.
# * <b>%%</b> -- A percent sign. # <tt>%%</tt> :: A percent sign.
# #
# The %d specifier can also have a numeric prefix (e.g. '%2d'). If the # The <tt>%d</tt> specifier can also have a numeric prefix (e.g. '%2d').
# number is positive, only return (up to) +n+ directories in the path, # If the number is positive, only return (up to) +n+ directories in the
# starting from the left hand side. If +n+ is negative, return (up to) # path, starting from the left hand side. If +n+ is negative, return (up
# |+n+| directories from the right hand side of the path. # to) +n+ directories from the right hand side of the path.
# #
# Examples: # Examples:
# #
# 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b' # 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b'
# 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d' # 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d'
# #
# Also the %d, %p, %f, %n, %x, and %X operators can take a # Also the <tt>%d</tt>, <tt>%p</tt>, <tt>%f</tt>, <tt>%n</tt>,
# pattern/replacement argument to perform simple string substitutions on a # <tt>%x</tt>, and <tt>%X</tt> operators can take a pattern/replacement
# particular part of the path. The pattern and replacement are separated # argument to perform simple string substitutions on a particular part of
# by a comma and are enclosed by curly braces. The replacement spec comes # the path. The pattern and replacement are separated by a comma and are
# after the % character but before the operator letter. (e.g. # enclosed by curly braces. The replacement spec comes after the %
# "%{old,new}d"). Multiple replacement specs should be separated by # character but before the operator letter. (e.g. "%{old,new}d").
# semi-colons (e.g. "%{old,new;src,bin}d"). # Multiple replacement specs should be separated by semi-colons (e.g.
# "%{old,new;src,bin}d").
# #
# Regular expressions may be used for the pattern, and back refs may be # Regular expressions may be used for the pattern, and back refs may be
# used in the replacement text. Curly braces, commas and semi-colons are # used in the replacement text. Curly braces, commas and semi-colons are
@ -106,11 +112,11 @@ class String
# #
# For example: # For example:
# #
# "src/org/onestepback/proj/A.java".pathmap("%{^src,bin}X.class") # "src/org/onestepback/proj/A.java".pathmap("%{^src,class}X.class")
# #
# returns: # returns:
# #
# "bin/org/onestepback/proj/A.class" # "class/org/onestepback/proj/A.class"
# #
# If the replacement text is '*', then a block may be provided to perform # If the replacement text is '*', then a block may be provided to perform
# some arbitrary calculation for the replacement. # some arbitrary calculation for the replacement.
@ -125,6 +131,7 @@ class String
# #
# "/path/to/file.txt" # "/path/to/file.txt"
# #
# This String extension comes from Rake
def pathmap(spec=nil, &block) def pathmap(spec=nil, &block)
return self if spec.nil? return self if spec.nil?
result = '' result = ''

View File

@ -3,7 +3,7 @@
require 'rake/early_time' require 'rake/early_time'
class Time class Time # :nodoc: all
alias rake_original_time_compare :<=> alias rake_original_time_compare :<=>
def <=>(other) def <=>(other)
if Rake::EarlyTime === other if Rake::EarlyTime === other

View File

@ -2,10 +2,10 @@ require 'rake/cloneable'
require 'rake/file_utils_ext' require 'rake/file_utils_ext'
require 'rake/pathmap' require 'rake/pathmap'
######################################################################
module Rake module Rake
# ######################################################################### ##
# A FileList is essentially an array with a few helper methods defined to # A FileList is essentially an array with a few helper methods defined to
# make file manipulation a bit easier. # make file manipulation a bit easier.
# #
@ -156,7 +156,6 @@ module Rake
self self
end end
# Clear all the exclude patterns so that we exclude nothing. # Clear all the exclude patterns so that we exclude nothing.
def clear_exclude def clear_exclude
@exclude_patterns = [] @exclude_patterns = []
@ -164,7 +163,7 @@ module Rake
self self
end end
# Define equality. # A FileList is equal through array equality.
def ==(array) def ==(array)
to_ary == array to_ary == array
end end
@ -208,7 +207,7 @@ module Rake
self self
end end
def resolve_add(fn) def resolve_add(fn) # :nodoc:
case fn case fn
when %r{[*?\[\{]} when %r{[*?\[\{]}
add_matching(fn) add_matching(fn)
@ -218,7 +217,7 @@ module Rake
end end
private :resolve_add private :resolve_add
def resolve_exclude def resolve_exclude # :nodoc:
reject! { |fn| excluded_from_list?(fn) } reject! { |fn| excluded_from_list?(fn) }
self self
end end
@ -276,7 +275,6 @@ module Rake
collect { |fn| fn.ext(newext) } collect { |fn| fn.ext(newext) }
end end
# Grep each of the files in the filelist using the given pattern. If a # Grep each of the files in the filelist using the given pattern. If a
# block is given, call the block on each matching line, passing the file # block is given, call the block on each matching line, passing the file
# name, line number, and the matching line of text. If no block is given, # name, line number, and the matching line of text. If no block is given,
@ -377,7 +375,7 @@ module Rake
proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) } proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
] ]
def import(array) def import(array) # :nodoc:
@items = array @items = array
self self
end end

View File

@ -2,7 +2,7 @@ require 'rake/task.rb'
require 'rake/early_time' require 'rake/early_time'
module Rake module Rake
# #########################################################################
# A FileTask is a task that includes time based dependencies. If any of a # A FileTask is a task that includes time based dependencies. If any of a
# FileTask's prerequisites have a timestamp that is later than the file # FileTask's prerequisites have a timestamp that is later than the file
# represented by this task, then the file must be rebuilt (using the # represented by this task, then the file must be rebuilt (using the
@ -13,7 +13,7 @@ module Rake
# Is this file task needed? Yes if it doesn't exist, or if its time stamp # Is this file task needed? Yes if it doesn't exist, or if its time stamp
# is out of date. # is out of date.
def needed? def needed?
! File.exist?(name) || out_of_date?(timestamp) ! File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all
end end
# Time stamp for file task. # Time stamp for file task.

View File

@ -14,12 +14,24 @@ module FileUtils
OPT_TABLE['sh'] = %w(noop verbose) OPT_TABLE['sh'] = %w(noop verbose)
OPT_TABLE['ruby'] = %w(noop verbose) OPT_TABLE['ruby'] = %w(noop verbose)
# Run the system command +cmd+. If multiple arguments are given the command # Run the system command +cmd+. If multiple arguments are given the command
# is not run with the shell (same semantics as Kernel::exec and # is run directly (without the shell, same semantics as Kernel::exec and
# Kernel::system). # Kernel::system).
# #
# Example: # It is recommended you use the multiple argument form over interpolating
# sh %{ls -ltr} # user input for both usability and security reasons. With the multiple
# argument form you can easily process files with spaces or other shell
# reserved characters in them. With the multiple argument form your rake
# tasks are not vulnerable to users providing an argument like
# <code>; rm # -rf /</code>.
#
# If a block is given, upon command completion the block is called with an
# OK flag (true on a zero exit status) and a Process::Status object.
# Without a block a RuntimeError is raised when the command exits non-zero.
#
# Examples:
#
# sh 'ls -ltr'
# #
# sh 'ls', 'file with spaces' # sh 'ls', 'file with spaces'
# #

View File

@ -1,2 +1,4 @@
# TODO: Remove in Rake 11
fail "ERROR: 'rake/gempackagetask' is obsolete and no longer supported. " + fail "ERROR: 'rake/gempackagetask' is obsolete and no longer supported. " +
"Use 'rubygems/packagetask' instead." "Use 'rubygems/package_task' instead."

View File

@ -1,6 +1,5 @@
module Rake module Rake
####################################################################
# InvocationChain tracks the chain of task invocations to detect # InvocationChain tracks the chain of task invocations to detect
# circular dependencies. # circular dependencies.
class InvocationChain < LinkedList class InvocationChain < LinkedList

View File

@ -1 +0,0 @@
# Ignore project.rake

View File

@ -1,21 +0,0 @@
task "create:project" => ["lib", "test", "Rakefile"]
directory "lib"
directory "test"
file "Rakefile" do
File.open("Rakefile", "w") do |out|
out.puts %{# -*- ruby -*-
require 'rake/clean'
require 'rake/testtask'
task :default => :test
Rake::TestTask.new do |t|
t.verbose = false
t.test_files = FileList['test/test_*.rb']
end
}
end
end

View File

@ -13,7 +13,7 @@ module Rake
end end
# Polymorphically add a new element to the head of a list. The # Polymorphically add a new element to the head of a list. The
# type of head node will be the same list type has the tail. # type of head node will be the same list type as the tail.
def conj(item) def conj(item)
self.class.cons(item, self) self.class.cons(item, self)
end end

View File

@ -1,25 +1,38 @@
module Rake ##
# The NameSpace class will lookup task names in the scope defined by a
# +namespace+ command.
# The NameSpace class will lookup task names in the the scope class Rake::NameSpace
# defined by a +namespace+ command.
#
class NameSpace
# Create a namespace lookup object using the given task manager ##
# and the list of scopes. # Create a namespace lookup object using the given task manager
def initialize(task_manager, scope_list) # and the list of scopes.
@task_manager = task_manager
@scope = scope_list.dup
end
# Lookup a task named +name+ in the namespace. def initialize(task_manager, scope_list)
def [](name) @task_manager = task_manager
@task_manager.lookup(name, @scope) @scope = scope_list.dup
end
# Return the list of tasks defined in this and nested namespaces.
def tasks
@task_manager.tasks_in_scope(@scope)
end
end end
##
# Lookup a task named +name+ in the namespace.
def [](name)
@task_manager.lookup(name, @scope)
end
##
# The scope of the namespace (a LinkedList)
def scope
@scope.dup
end
##
# Return the list of tasks defined in this and nested namespaces.
def tasks
@task_manager.tasks_in_scope(@scope)
end
end end

View File

@ -11,27 +11,27 @@ module Rake
# #
# The PackageTask will create the following targets: # The PackageTask will create the following targets:
# #
# [<b>:package</b>] # +:package+ ::
# Create all the requested package files. # Create all the requested package files.
# #
# [<b>:clobber_package</b>] # +:clobber_package+ ::
# Delete all the package files. This target is automatically # Delete all the package files. This target is automatically
# added to the main clobber target. # added to the main clobber target.
# #
# [<b>:repackage</b>] # +:repackage+ ::
# Rebuild the package files from scratch, even if they are not out # Rebuild the package files from scratch, even if they are not out
# of date. # of date.
# #
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>] # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</tt> ::
# Create a gzipped tar package (if <em>need_tar</em> is true). # Create a gzipped tar package (if <em>need_tar</em> is true).
# #
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</b>] # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</tt> ::
# Create a gzipped tar package (if <em>need_tar_gz</em> is true). # Create a gzipped tar package (if <em>need_tar_gz</em> is true).
# #
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</b>] # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</tt> ::
# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true). # Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
# #
# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>] # <tt>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</tt> ::
# Create a zip package archive (if <em>need_zip</em> is true). # Create a zip package archive (if <em>need_zip</em> is true).
# #
# Example: # Example:
@ -127,7 +127,7 @@ module Rake
file "#{package_dir}/#{file}" => file "#{package_dir}/#{file}" =>
[package_dir_path] + package_files do [package_dir_path] + package_files do
chdir(package_dir) do chdir(package_dir) do
sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}} sh @tar_command, "#{flag}cvf", file, package_name
end end
end end
end end
@ -138,7 +138,7 @@ module Rake
file "#{package_dir}/#{zip_file}" => file "#{package_dir}/#{zip_file}" =>
[package_dir_path] + package_files do [package_dir_path] + package_files do
chdir(package_dir) do chdir(package_dir) do
sh %{#{@zip_command} -r #{zip_file} #{package_name}} sh @zip_command, "-r", zip_file, package_name
end end
end end
end end
@ -162,26 +162,38 @@ module Rake
self self
end end
# The name of this package
def package_name def package_name
@version ? "#{@name}-#{@version}" : @name @version ? "#{@name}-#{@version}" : @name
end end
# The directory this package will be built in
def package_dir_path def package_dir_path
"#{package_dir}/#{package_name}" "#{package_dir}/#{package_name}"
end end
# The package name with .tgz added
def tgz_file def tgz_file
"#{package_name}.tgz" "#{package_name}.tgz"
end end
# The package name with .tar.gz added
def tar_gz_file def tar_gz_file
"#{package_name}.tar.gz" "#{package_name}.tar.gz"
end end
# The package name with .tar.bz2 added
def tar_bz2_file def tar_bz2_file
"#{package_name}.tar.bz2" "#{package_name}.tar.bz2"
end end
# The package name with .zip added
def zip_file def zip_file
"#{package_name}.zip" "#{package_name}.zip"
end end

View File

@ -1 +1,3 @@
# TODO: Remove in Rake 11
require 'rake/ext/string' require 'rake/ext/string'

View File

@ -1,8 +1,8 @@
module Rake module Rake
#################################################################### ##
# Exit status class for times the system just gives us a nil. # Exit status class for times the system just gives us a nil.
class PseudoStatus class PseudoStatus # :nodoc: all
attr_reader :exitstatus attr_reader :exitstatus
def initialize(code=0) def initialize(code=0)

View File

@ -2,8 +2,6 @@ require 'rake/application'
module Rake module Rake
# Rake module singleton methods.
#
class << self class << self
# Current Rake Application # Current Rake Application
def application def application
@ -15,6 +13,11 @@ module Rake
@application = app @application = app
end end
def suggested_thread_count # :nodoc:
@cpu_count ||= Rake::CpuCounter.count
@cpu_count + 4
end
# Return the original directory where the Rake application was started. # Return the original directory where the Rake application was started.
def original_dir def original_dir
application.original_dir application.original_dir
@ -28,9 +31,7 @@ module Rake
# Add files to the rakelib list # Add files to the rakelib list
def add_rakelib(*files) def add_rakelib(*files)
application.options.rakelib ||= [] application.options.rakelib ||= []
files.each do |file| application.options.rakelib.concat(files)
application.options.rakelib << file
end
end end
end end

View File

@ -1,2 +1,4 @@
# TODO: Remove in Rake 11
fail "ERROR: 'rake/rdoctask' is obsolete and no longer supported. " + fail "ERROR: 'rake/rdoctask' is obsolete and no longer supported. " +
"Use 'rdoc/task' (available in RDoc 2.4.2+) instead." "Use 'rdoc/task' (available in RDoc 2.4.2+) instead."

View File

@ -1,3 +1,5 @@
# TODO: Remove in rake 11
# Local Rake override to fix bug in Ruby 0.8.2 # Local Rake override to fix bug in Ruby 0.8.2
module Test # :nodoc: module Test # :nodoc:
# Local Rake override to fix bug in Ruby 0.8.2 # Local Rake override to fix bug in Ruby 0.8.2

View File

@ -5,7 +5,12 @@ require 'rake/file_list'
module Rake module Rake
include Test::Unit::Assertions include Test::Unit::Assertions
def run_tests(pattern='test/test*.rb', log_enabled=false) ##
# Deprecated way of running tests in process, but only for Test::Unit.
#--
# TODO: Remove in rake 11
def run_tests(pattern='test/test*.rb', log_enabled=false) # :nodoc:
FileList.glob(pattern).each do |fn| FileList.glob(pattern).each do |fn|
$stderr.puts fn if log_enabled $stderr.puts fn if log_enabled
begin begin

View File

@ -1,5 +1,5 @@
module Rake module Rake
class Scope < LinkedList class Scope < LinkedList # :nodoc: all
# Path for the scope. # Path for the scope.
def path def path

View File

@ -2,7 +2,7 @@ require 'rake/invocation_exception_mixin'
module Rake module Rake
# ######################################################################### ##
# A Task is the basic unit of work in a Rakefile. Tasks have associated # A Task is the basic unit of work in a Rakefile. Tasks have associated
# actions (possibly more than one) and a list of prerequisites. When # actions (possibly more than one) and a list of prerequisites. When
# invoked, a task will first ensure that all of its prerequisites have an # invoked, a task will first ensure that all of its prerequisites have an
@ -34,14 +34,18 @@ module Rake
name name
end end
def inspect def inspect # :nodoc:
"<#{self.class} #{name} => [#{prerequisites.join(', ')}]>" "<#{self.class} #{name} => [#{prerequisites.join(', ')}]>"
end end
# List of sources for task. # List of sources for task.
attr_writer :sources attr_writer :sources
def sources def sources
@sources ||= [] if defined?(@sources)
@sources
else
prerequisites
end
end end
# List of prerequisite tasks # List of prerequisite tasks
@ -49,7 +53,7 @@ module Rake
prerequisites.map { |pre| lookup_prerequisite(pre) } prerequisites.map { |pre| lookup_prerequisite(pre) }
end end
def lookup_prerequisite(prerequisite_name) def lookup_prerequisite(prerequisite_name) # :nodoc:
application[prerequisite_name, @scope] application[prerequisite_name, @scope]
end end
private :lookup_prerequisite private :lookup_prerequisite
@ -63,7 +67,7 @@ module Rake
seen.values seen.values
end end
def collect_prerequisites(seen) def collect_prerequisites(seen) # :nodoc:
prerequisite_tasks.each do |pre| prerequisite_tasks.each do |pre|
next if seen[pre.name] next if seen[pre.name]
seen[pre.name] = pre seen[pre.name] = pre
@ -74,7 +78,7 @@ module Rake
# First source from a rule (nil if no sources) # First source from a rule (nil if no sources)
def source def source
@sources.first if defined?(@sources) sources.first
end end
# Create a task named +task_name+ with no actions or prerequisites. Use # Create a task named +task_name+ with no actions or prerequisites. Use
@ -180,7 +184,7 @@ module Rake
end end
protected :invoke_with_call_chain protected :invoke_with_call_chain
def add_chain_to(exception, new_chain) def add_chain_to(exception, new_chain) # :nodoc:
exception.extend(InvocationExceptionMixin) unless exception.extend(InvocationExceptionMixin) unless
exception.respond_to?(:chain) exception.respond_to?(:chain)
exception.chain = new_chain if exception.chain.nil? exception.chain = new_chain if exception.chain.nil?
@ -257,11 +261,12 @@ module Rake
add_comment(comment) if comment && ! comment.empty? add_comment(comment) if comment && ! comment.empty?
end end
def comment=(comment) def comment=(comment) # :nodoc:
add_comment(comment) add_comment(comment)
end end
def add_comment(comment) def add_comment(comment) # :nodoc:
return if comment.nil?
@comments << comment unless @comments.include?(comment) @comments << comment unless @comments.include?(comment)
end end
private :add_comment private :add_comment

View File

@ -1,16 +1,16 @@
module Rake module Rake
#################################################################### ##
# TaskArguments manage the arguments passed to a task. # TaskArguments manage the arguments passed to a task.
# #
class TaskArguments class TaskArguments
include Enumerable include Enumerable
# Argument names
attr_reader :names attr_reader :names
# Create a TaskArgument object with a list of named arguments # Create a TaskArgument object with a list of argument +names+ and a set
# (given by :names) and a set of associated values (given by # of associated +values+. +parent+ is the parent argument object.
# :values). :parent is the parent argument object.
def initialize(names, values, parent=nil) def initialize(names, values, parent=nil)
@names = names @names = names
@parent = parent @parent = parent
@ -21,12 +21,12 @@ module Rake
} }
end end
# Retrive the complete array of sequential values # Retrieve the complete array of sequential values
def to_a def to_a
@values.dup @values.dup
end end
# Retrive the list of values not associated with named arguments # Retrieve the list of values not associated with named arguments
def extras def extras
@values[@names.length..-1] || [] @values[@names.length..-1] || []
end end
@ -50,33 +50,42 @@ module Rake
@hash = defaults.merge(@hash) @hash = defaults.merge(@hash)
end end
# Enumerates the arguments and their values
def each(&block) def each(&block)
@hash.each(&block) @hash.each(&block)
end end
# Extracts the argument values at +keys+
def values_at(*keys) def values_at(*keys)
keys.map { |k| lookup(k) } keys.map { |k| lookup(k) }
end end
# Returns the value of the given argument via method_missing
def method_missing(sym, *args) def method_missing(sym, *args)
lookup(sym.to_sym) lookup(sym.to_sym)
end end
# Returns a Hash of arguments and their values
def to_hash def to_hash
@hash @hash
end end
def to_s def to_s # :nodoc:
@hash.inspect @hash.inspect
end end
def inspect def inspect # :nodoc:
to_s to_s
end end
# Returns true if +key+ is one of the arguments
def has_key?(key)
@hash.has_key?(key)
end
protected protected
def lookup(name) def lookup(name) # :nodoc:
if @hash.has_key?(name) if @hash.has_key?(name)
@hash[name] @hash[name]
elsif @parent elsif @parent
@ -85,5 +94,5 @@ module Rake
end end
end end
EMPTY_TASK_ARGS = TaskArguments.new([], []) EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
end end

View File

@ -4,9 +4,12 @@ module Rake
module TaskManager module TaskManager
# Track the last comment made in the Rakefile. # Track the last comment made in the Rakefile.
attr_accessor :last_description attr_accessor :last_description
alias :last_comment :last_description # Backwards compatibility
def initialize # TODO: Remove in Rake 11
alias :last_comment :last_description # :nodoc: Backwards compatibility
def initialize # :nodoc:
super super
@tasks = Hash.new @tasks = Hash.new
@rules = Array.new @rules = Array.new
@ -14,14 +17,22 @@ module Rake
@last_description = nil @last_description = nil
end end
def create_rule(*args, &block) def create_rule(*args, &block) # :nodoc:
pattern, args, deps = resolve_args(args) pattern, args, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
@rules << [pattern, args, deps, block] @rules << [pattern, args, deps, block]
end end
def define_task(task_class, *args, &block) def define_task(task_class, *args, &block) # :nodoc:
task_name, arg_names, deps = resolve_args(args) task_name, arg_names, deps = resolve_args(args)
original_scope = @scope
if String === task_name and
not task_class.ancestors.include? Rake::FileTask then
task_name, *definition_scope = *(task_name.split(":").reverse)
@scope = Scope.make(*(definition_scope + @scope.to_a))
end
task_name = task_class.scope_name(@scope, task_name) task_name = task_class.scope_name(@scope, task_name)
deps = [deps] unless deps.respond_to?(:to_ary) deps = [deps] unless deps.respond_to?(:to_ary)
deps = deps.map { |d| d.to_s } deps = deps.map { |d| d.to_s }
@ -32,6 +43,8 @@ module Rake
task.add_description(get_description(task)) task.add_description(get_description(task))
end end
task.enhance(deps, &block) task.enhance(deps, &block)
ensure
@scope = original_scope
end end
# Lookup a task. Return an existing task if found, otherwise # Lookup a task. Return an existing task if found, otherwise
@ -49,7 +62,7 @@ module Rake
fail "Don't know how to build task '#{task_name}'" fail "Don't know how to build task '#{task_name}'"
end end
def synthesize_file_task(task_name) def synthesize_file_task(task_name) # :nodoc:
return nil unless File.exist?(task_name) return nil unless File.exist?(task_name)
define_task(Rake::FileTask, task_name) define_task(Rake::FileTask, task_name)
end end
@ -226,7 +239,7 @@ module Rake
"_anon_#{@seed}" "_anon_#{@seed}"
end end
def trace_rule(level, message) def trace_rule(level, message) # :nodoc:
options.trace_output.puts "#{" " * level}#{message}" if options.trace_output.puts "#{" " * level}#{message}" if
Rake.application.options.trace_rules Rake.application.options.trace_rules
end end
@ -265,7 +278,7 @@ module Rake
task_name.ext(ext) task_name.ext(ext)
when String when String
ext ext
when Proc when Proc, Method
if ext.arity == 1 if ext.arity == 1
ext.call(task_name) ext.call(task_name)
else else
@ -289,7 +302,7 @@ module Rake
end end
class << self class << self
attr_accessor :record_task_metadata attr_accessor :record_task_metadata # :nodoc:
TaskManager.record_task_metadata = false TaskManager.record_task_metadata = false
end end
end end

View File

@ -14,6 +14,8 @@ module Rake
# libraries depend on this so I can't remove it without breaking # libraries depend on this so I can't remove it without breaking
# other people's code. So for now it stays for backwards # other people's code. So for now it stays for backwards
# compatibility. BUT DON'T USE IT. # compatibility. BUT DON'T USE IT.
#--
# TODO: Remove in Rake 11
def paste(a, b) # :nodoc: def paste(a, b) # :nodoc:
(a.to_s + b.to_s).intern (a.to_s + b.to_s).intern
end end

View File

@ -1,5 +1,3 @@
# Define a task library for running unit tests.
require 'rake' require 'rake'
require 'rake/tasklib' require 'rake/tasklib'
@ -67,6 +65,9 @@ module Rake
# Array of commandline options to pass to ruby when running test loader. # Array of commandline options to pass to ruby when running test loader.
attr_accessor :ruby_opts attr_accessor :ruby_opts
# Description of the test task. (default is 'Run tests')
attr_accessor :description
# Explicitly define the list of test files to be included in a # Explicitly define the list of test files to be included in a
# test. +list+ is expected to be an array of file names (a # test. +list+ is expected to be an array of file names (a
# FileList is acceptable). If both +pattern+ and +test_files+ are # FileList is acceptable). If both +pattern+ and +test_files+ are
@ -86,6 +87,7 @@ module Rake
@warning = false @warning = false
@loader = :rake @loader = :rake
@ruby_opts = [] @ruby_opts = []
@description = "Run tests" + (@name == :test ? "" : " for #{@name}")
yield self if block_given? yield self if block_given?
@pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil? @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
define define
@ -93,7 +95,7 @@ module Rake
# Create the tasks defined by this task lib. # Create the tasks defined by this task lib.
def define def define
desc "Run tests" + (@name == :test ? "" : " for #{@name}") desc @description
task @name do task @name do
FileUtilsExt.verbose(@verbose) do FileUtilsExt.verbose(@verbose) do
args = args =
@ -121,18 +123,18 @@ module Rake
"") "")
end end
def ruby_opts_string def ruby_opts_string # :nodoc:
opts = @ruby_opts.dup opts = @ruby_opts.dup
opts.unshift("-I\"#{lib_path}\"") unless @libs.empty? opts.unshift("-I\"#{lib_path}\"") unless @libs.empty?
opts.unshift("-w") if @warning opts.unshift("-w") if @warning
opts.join(" ") opts.join(" ")
end end
def lib_path def lib_path # :nodoc:
@libs.join(File::PATH_SEPARATOR) @libs.join(File::PATH_SEPARATOR)
end end
def file_list_string def file_list_string # :nodoc:
file_list.map { |fn| "\"#{fn}\"" }.join(' ') file_list.map { |fn| "\"#{fn}\"" }.join(' ')
end end
@ -156,18 +158,18 @@ module Rake
end || '' end || ''
end end
def ruby_version def ruby_version # :nodoc:
RUBY_VERSION RUBY_VERSION
end end
def run_code def run_code # :nodoc:
case @loader case @loader
when :direct when :direct
"-e \"ARGV.each{|f| require f}\"" "-e \"ARGV.each{|f| require f}\""
when :testrb when :testrb
"-S testrb #{fix}" "-S testrb #{fix}"
when :rake when :rake
"-I\"#{rake_lib_dir}\" \"#{rake_loader}\"" "#{rake_include_arg} \"#{rake_loader}\""
end end
end end
@ -184,6 +186,15 @@ module Rake
nil nil
end end
def rake_include_arg # :nodoc:
spec = Gem.loaded_specs['rake']
if spec.respond_to?(:default_gem?) && spec.default_gem?
""
else
"-I\"#{rake_lib_dir}\""
end
end
def rake_lib_dir # :nodoc: def rake_lib_dir # :nodoc:
find_dir('rake') or find_dir('rake') or
fail "unable to find rake lib" fail "unable to find rake lib"

View File

@ -5,10 +5,10 @@ require 'rake/promise'
module Rake module Rake
class ThreadPool # :nodoc: all class ThreadPool # :nodoc: all
# Creates a ThreadPool object. # Creates a ThreadPool object. The +thread_count+ parameter is the size
# The parameter is the size of the pool. # of the pool.
def initialize(thread_count) def initialize(thread_count)
@max_active_threads = [thread_count, 0].max @max_active_threads = [thread_count, 0].max
@threads = Set.new @threads = Set.new
@ -25,9 +25,9 @@ module Rake
# Creates a future executed by the +ThreadPool+. # Creates a future executed by the +ThreadPool+.
# #
# The args are passed to the block when executing (similarly to # The args are passed to the block when executing (similarly to
# <tt>Thread#new</tt>) The return value is an object representing # Thread#new) The return value is an object representing
# a future which has been created and added to the queue in the # a future which has been created and added to the queue in the
# pool. Sending <tt>#value</tt> to the object will sleep the # pool. Sending #value to the object will sleep the
# current thread until the future is finished and will return the # current thread until the future is finished and will return the
# result (or raise an exception thrown from the future) # result (or raise an exception thrown from the future)
def future(*args, &block) def future(*args, &block)
@ -109,13 +109,19 @@ module Rake
false false
end end
def safe_thread_count
@threads_mon.synchronize do
@threads.count
end
end
def start_thread # :nodoc: def start_thread # :nodoc:
@threads_mon.synchronize do @threads_mon.synchronize do
next unless @threads.count < @max_active_threads next unless @threads.count < @max_active_threads
t = Thread.new do t = Thread.new do
begin begin
while @threads.count <= @max_active_threads while safe_thread_count <= @max_active_threads
break unless process_queue_item break unless process_queue_item
end end
ensure ensure
@ -126,6 +132,7 @@ module Rake
end end
end end
end end
@threads << t @threads << t
stat( stat(
:spawned, :spawned,
@ -152,10 +159,6 @@ module Rake
def __queue__ # :nodoc: def __queue__ # :nodoc:
@queue @queue
end end
def __threads__ # :nodoc:
@threads.dup
end
end end
end end

View File

@ -1,5 +1,5 @@
module Rake module Rake
module TraceOutput module TraceOutput # :nodoc: all
# Write trace output to output stream +out+. # Write trace output to output stream +out+.
# #

View File

@ -1,6 +1,4 @@
module Rake module Rake
VERSION = '10.1.0'
module Version # :nodoc: all module Version # :nodoc: all
MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split '.' MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split '.'

View File

@ -4,7 +4,7 @@ module Rake
# Win 32 interface methods for Rake. Windows specific functionality # Win 32 interface methods for Rake. Windows specific functionality
# will be placed here to collect that knowledge in one spot. # will be placed here to collect that knowledge in one spot.
module Win32 module Win32 # :nodoc: all
# Error indicating a problem in locating the home directory on a # Error indicating a problem in locating the home directory on a
# Win32 system. # Win32 system.

View File

@ -41,6 +41,16 @@ end
ACCESS ACCESS
end end
def rakefile_test_task
rakefile <<-RAKEFILE
require "rake/testtask"
Rake::TestTask.new(:unit) do |t|
t.description = "custom test task description"
end
RAKEFILE
end
def rakefile_chains def rakefile_chains
rakefile <<-DEFAULT rakefile <<-DEFAULT
task :default => "play.app" task :default => "play.app"
@ -217,6 +227,30 @@ default: other
end end
end end
def rakefile_regenerate_imports
rakefile <<-REGENERATE_IMPORTS
task :default
task :regenerate do
open("deps", "w") do |f|
f << <<-CONTENT
file "deps" => :regenerate
puts "REGENERATED"
CONTENT
end
end
import "deps"
REGENERATE_IMPORTS
open "deps", "w" do |f|
f << <<-CONTENT
file "deps" => :regenerate
puts "INITIAL"
CONTENT
end
end
def rakefile_multidesc def rakefile_multidesc
rakefile <<-MULTIDESC rakefile <<-MULTIDESC
task :b task :b

View File

@ -9,6 +9,79 @@ class TestRakeApplication < Rake::TestCase
@app.options.rakelib = [] @app.options.rakelib = []
end end
def setup_command_line(*options)
ARGV.clear
options.each do |option|
ARGV << option
end
end
def test_display_exception_details
begin
raise 'test'
rescue => ex
end
out, err = capture_io do
@app.display_error_message ex
end
assert_empty out
assert_match 'rake aborted!', err
assert_match __method__.to_s, err
end
def test_display_exception_details_cause
skip 'Exception#cause not implemented' unless
Exception.method_defined? :cause
begin
raise 'cause a'
rescue
begin
raise 'cause b'
rescue => ex
end
end
out, err = capture_io do
@app.display_error_message ex
end
assert_empty out
assert_match 'cause a', err
assert_match 'cause b', err
end
def test_display_exception_details_cause_loop
skip 'Exception#cause not implemented' unless
Exception.method_defined? :cause
begin
begin
raise 'cause a'
rescue => a
begin
raise 'cause b'
rescue
raise a
end
end
rescue => ex
end
out, err = capture_io do
@app.display_error_message ex
end
assert_empty out
assert_match 'cause a', err
assert_match 'cause b', err
end
def test_display_tasks def test_display_tasks
@app.options.show_tasks = :tasks @app.options.show_tasks = :tasks
@app.options.show_task_pattern = // @app.options.show_task_pattern = //
@ -193,6 +266,7 @@ class TestRakeApplication < Rake::TestCase
end end
def test_load_rakefile_not_found def test_load_rakefile_not_found
ARGV.clear
Dir.chdir @tempdir Dir.chdir @tempdir
ENV['RAKE_SYSTEM'] = 'not_exist' ENV['RAKE_SYSTEM'] = 'not_exist'
@ -201,8 +275,11 @@ class TestRakeApplication < Rake::TestCase
options.silent = true options.silent = true
end end
ex = assert_raises(RuntimeError) do ex = assert_raises(RuntimeError) do
@app.instance_eval do raw_load_rakefile end @app.instance_eval do
raw_load_rakefile
end
end end
assert_match(/no rakefile found/i, ex.message) assert_match(/no rakefile found/i, ex.message)
@ -295,8 +372,7 @@ class TestRakeApplication < Rake::TestCase
assert !@app.options.trace assert !@app.options.trace
valid_option = '--trace' valid_option = '--trace'
ARGV.clear setup_command_line(valid_option)
ARGV << valid_option
@app.handle_options @app.handle_options
@ -305,8 +381,7 @@ class TestRakeApplication < Rake::TestCase
end end
def test_handle_options_trace_default_is_stderr def test_handle_options_trace_default_is_stderr
ARGV.clear setup_command_line("--trace")
ARGV << "--trace"
@app.handle_options @app.handle_options
@ -315,8 +390,7 @@ class TestRakeApplication < Rake::TestCase
end end
def test_handle_options_trace_overrides_to_stdout def test_handle_options_trace_overrides_to_stdout
ARGV.clear setup_command_line("--trace=stdout")
ARGV << "--trace=stdout"
@app.handle_options @app.handle_options
@ -327,8 +401,7 @@ class TestRakeApplication < Rake::TestCase
def test_handle_options_trace_does_not_eat_following_task_names def test_handle_options_trace_does_not_eat_following_task_names
assert !@app.options.trace assert !@app.options.trace
ARGV.clear setup_command_line("--trace", "sometask")
ARGV << "--trace" << "sometask"
@app.handle_options @app.handle_options
assert ARGV.include?("sometask") assert ARGV.include?("sometask")
@ -359,8 +432,7 @@ class TestRakeApplication < Rake::TestCase
def test_display_task_run def test_display_task_run
ran = false ran = false
ARGV.clear setup_command_line('-f', '-s', '--tasks', '--rakelib=""')
ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
@app.last_description = "COMMENT" @app.last_description = "COMMENT"
@app.define_task(Rake::Task, "default") @app.define_task(Rake::Task, "default")
out, = capture_io { @app.run } out, = capture_io { @app.run }
@ -372,8 +444,7 @@ class TestRakeApplication < Rake::TestCase
def test_display_prereqs def test_display_prereqs
ran = false ran = false
ARGV.clear setup_command_line('-f', '-s', '--prereqs', '--rakelib=""')
ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
@app.last_description = "COMMENT" @app.last_description = "COMMENT"
t = @app.define_task(Rake::Task, "default") t = @app.define_task(Rake::Task, "default")
t.enhance([:a, :b]) t.enhance([:a, :b])
@ -389,44 +460,99 @@ class TestRakeApplication < Rake::TestCase
def test_bad_run def test_bad_run
@app.intern(Rake::Task, "default").enhance { fail } @app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear setup_command_line('-f', '-s', '--rakelib=""')
ARGV << '-f' << '-s' << '--rakelib=""' _, err = capture_io {
assert_raises(SystemExit) { assert_raises(SystemExit){ @app.run }
_, err = capture_io { @app.run }
assert_match(/see full trace/, err)
} }
assert_match(/see full trace/i, err)
ensure ensure
ARGV.clear ARGV.clear
end end
def test_bad_run_with_trace def test_bad_run_with_trace
@app.intern(Rake::Task, "default").enhance { fail } @app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear setup_command_line('-f', '-s', '-t')
ARGV << '-f' << '-s' << '-t' _, err = capture_io {
assert_raises(SystemExit) { assert_raises(SystemExit) { @app.run }
_, err = capture_io { @app.run }
refute_match(/see full trace/, err)
} }
refute_match(/see full trace/i, err)
ensure ensure
ARGV.clear ARGV.clear
end end
def test_bad_run_with_backtrace def test_bad_run_with_backtrace
@app.intern(Rake::Task, "default").enhance { fail } @app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear setup_command_line('-f', '-s', '--backtrace')
ARGV << '-f' << '-s' << '--backtrace' _, err = capture_io {
assert_raises(SystemExit) { assert_raises(SystemExit) {
_, err = capture_io { @app.run } @app.run
refute_match(/see full trace/, err) }
} }
refute_match(/see full trace/, err)
ensure
ARGV.clear
end
CustomError = Class.new(RuntimeError)
def test_bad_run_includes_exception_name
@app.intern(Rake::Task, "default").enhance {
raise CustomError, "intentional"
}
setup_command_line('-f', '-s')
_, err = capture_io {
assert_raises(SystemExit) {
@app.run
}
}
assert_match(/CustomError: intentional/, err)
end
def test_rake_error_excludes_exception_name
@app.intern(Rake::Task, "default").enhance {
fail "intentional"
}
setup_command_line('-f', '-s')
_, err = capture_io {
assert_raises(SystemExit) {
@app.run
}
}
refute_match(/RuntimeError/, err)
assert_match(/intentional/, err)
end
def cause_supported?
ex = StandardError.new
ex.respond_to?(:cause)
end
def test_printing_original_exception_cause
custom_error = Class.new(StandardError)
@app.intern(Rake::Task, "default").enhance {
begin
raise custom_error, "Original Error"
rescue custom_error
raise custom_error, "Secondary Error"
end
}
setup_command_line('-f', '-s')
_ ,err = capture_io {
assert_raises(SystemExit) {
@app.run
}
}
if cause_supported?
assert_match(/Original Error/, err)
end
assert_match(/Secondary Error/, err)
ensure ensure
ARGV.clear ARGV.clear
end end
def test_run_with_bad_options def test_run_with_bad_options
@app.intern(Rake::Task, "default").enhance { fail } @app.intern(Rake::Task, "default").enhance { fail }
ARGV.clear setup_command_line('-f', '-s', '--xyzzy')
ARGV << '-f' << '-s' << '--xyzzy'
assert_raises(SystemExit) { assert_raises(SystemExit) {
capture_io { @app.run } capture_io { @app.run }
} }
@ -500,14 +626,12 @@ class TestRakeApplication < Rake::TestCase
loader.instance_variable_set :@load_called, false loader.instance_variable_set :@load_called, false
def loader.load arg def loader.load arg
raise 'called more than once' if @load_called
raise ArgumentError, arg unless arg == 'x.dummy' raise ArgumentError, arg unless arg == 'x.dummy'
@load_called = true @load_called = true
end end
loader.instance_variable_set :@make_dummy_called, false loader.instance_variable_set :@make_dummy_called, false
def loader.make_dummy def loader.make_dummy
raise 'called more than once' if @make_dummy_called
@make_dummy_called = true @make_dummy_called = true
end end

View File

@ -111,14 +111,23 @@ class TestRakeApplicationOptions < Rake::TestCase
end end
def test_jobs def test_jobs
flags([]) do |opts|
assert_nil opts.thread_pool_size
end
flags(['--jobs', '0'], ['-j', '0']) do |opts|
assert_equal 0, opts.thread_pool_size
end
flags(['--jobs', '1'], ['-j', '1']) do |opts|
assert_equal 0, opts.thread_pool_size
end
flags(['--jobs', '4'], ['-j', '4']) do |opts| flags(['--jobs', '4'], ['-j', '4']) do |opts|
assert_equal 4, opts.thread_pool_size assert_equal 3, opts.thread_pool_size
end end
flags(['--jobs', 'asdas'], ['-j', 'asdas']) do |opts| flags(['--jobs', 'asdas'], ['-j', 'asdas']) do |opts|
assert_equal 2, opts.thread_pool_size assert_equal Rake.suggested_thread_count-1, opts.thread_pool_size
end end
flags('--jobs', '-j') do |opts| flags('--jobs', '-j') do |opts|
assert_equal 2, opts.thread_pool_size assert opts.thread_pool_size > 1_000_000, "thread pool size should be huge (was #{opts.thread_pool_size})"
end end
end end
@ -449,7 +458,7 @@ class TestRakeApplicationOptions < Rake::TestCase
end end
@app.instance_eval do @app.instance_eval do
handle_options handle_options
collect_tasks collect_command_line_tasks
end end
@tasks = @app.top_level_tasks @tasks = @app.top_level_tasks
@app.options @app.options

View File

@ -12,6 +12,9 @@ class TestBacktraceSuppression < Rake::TestCase
def test_system_dir_suppressed def test_system_dir_suppressed
path = RbConfig::CONFIG['rubylibprefix'] path = RbConfig::CONFIG['rubylibprefix']
skip if path.nil?
path = File.expand_path path
paths = [path + ":12"] paths = [path + ":12"]
actual = Rake::Backtrace.collapse(paths) actual = Rake::Backtrace.collapse(paths)
@ -21,6 +24,9 @@ class TestBacktraceSuppression < Rake::TestCase
def test_near_system_dir_isnt_suppressed def test_near_system_dir_isnt_suppressed
path = RbConfig::CONFIG['rubylibprefix'] path = RbConfig::CONFIG['rubylibprefix']
skip if path.nil?
path = File.expand_path path
paths = [" " + path + ":12"] paths = [" " + path + ":12"]
actual = Rake::Backtrace.collapse(paths) actual = Rake::Backtrace.collapse(paths)

View File

@ -15,7 +15,7 @@ class TestRakeClean < Rake::TestCase
file_name = create_undeletable_file file_name = create_undeletable_file
out, _ = capture_io do out, _ = capture_io do
Rake::Cleaner.cleanup(file_name, verbose: false) Rake::Cleaner.cleanup(file_name, :verbose => false)
end end
assert_match(/failed to remove/i, out) assert_match(/failed to remove/i, out)
@ -23,6 +23,15 @@ class TestRakeClean < Rake::TestCase
remove_undeletable_file remove_undeletable_file
end end
def test_cleanup_ignores_missing_files
file_name = File.join(@tempdir, "missing_directory", "no_such_file")
out, _ = capture_io do
Rake::Cleaner.cleanup(file_name, :verbose => false)
end
refute_match(/failed to remove/i, out)
end
private private
def create_undeletable_file def create_undeletable_file
@ -46,7 +55,7 @@ class TestRakeClean < Rake::TestCase
file_name = File.join(dir_name, "deleteme") file_name = File.join(dir_name, "deleteme")
FileUtils.chmod(0777, dir_name) FileUtils.chmod(0777, dir_name)
FileUtils.chmod(0777, file_name) FileUtils.chmod(0777, file_name)
Rake::Cleaner.cleanup(file_name, verbose: false) Rake::Cleaner.cleanup(file_name, :verbose => false)
Rake::Cleaner.cleanup(dir_name, verbose: false) Rake::Cleaner.cleanup(dir_name, :verbose => false)
end end
end end

View File

@ -0,0 +1,50 @@
require File.expand_path('../helper', __FILE__)
class TestRakeCpuCounter < Rake::TestCase
def setup
super
@cpu_counter = Rake::CpuCounter.new
end
def test_count_via_win32
if Rake::Win32.windows? then
assert_kind_of Numeric, @cpu_counter.count_via_win32
else
assert_nil @cpu_counter.count_via_win32
end
end
def test_in_path_command
with_ruby_in_path do |ruby|
assert_equal ruby, @cpu_counter.in_path_command(ruby)
end
rescue Errno::ENOENT => e
raise unless e.message =~ /\bwhich\b/
skip 'cannot find which for this test'
end
def test_run
with_ruby_in_path do |ruby|
assert_equal 7, @cpu_counter.run(ruby, '-e', 'puts 3 + 4')
end
end
def with_ruby_in_path
ruby = File.basename Gem.ruby
ruby_dir = File.dirname Gem.ruby
begin
orig_path, ENV['PATH'] =
ENV['PATH'], [ruby_dir, *ENV['PATH']].join(File::PATH_SEPARATOR)
yield ruby
ensure
ENV['PATH'] = orig_path
end
end
end

View File

@ -25,6 +25,12 @@ class TestRakeDirectoryTask < Rake::TestCase
refute File.exist?("a/b/c") refute File.exist?("a/b/c")
end end
def test_directory_colon
directory "a:b"
assert_equal FileCreationTask, Task['a:b'].class
end unless Rake::Win32.windows?
if Rake::Win32.windows? if Rake::Win32.windows?
def test_directory_win32 def test_directory_win32
desc "WIN32 DESC" desc "WIN32 DESC"

View File

@ -98,6 +98,70 @@ class TestRakeFileTask < Rake::TestCase
assert @ran assert @ran
end end
def test_needed_eh_build_all
create_file 'a'
file 'a'
a_task = Task['a']
refute a_task.needed?
Rake.application.options.build_all = true
assert a_task.needed?
ensure
delete_file 'a'
end
def test_needed_eh_dependency
create_file 'a', Time.now
create_file 'b', Time.now - 60
create_file 'c', Time.now
create_file 'd', Time.now - 60
file 'b' => 'a'
b_task = Task['b']
assert b_task.needed?
file 'c' => 'd'
c_task = Task['c']
refute c_task.needed?
ensure
delete_file 'old'
delete_file 'new'
end
def test_needed_eh_exists
name = "dummy"
file name
ftask = Task[name]
assert ftask.needed?
create_file name
refute ftask.needed?
ensure
delete_file name
end
def test_source_is_first_prerequisite
t = file :f => ["preqA", "preqB"]
assert_equal "preqA", t.source
end
def test_sources_is_all_prerequisites
t = file :f => ["preqA", "preqB"]
assert_equal ["preqA", "preqB"], t.sources
end
# I have currently disabled this test. I'm not convinced that # I have currently disabled this test. I'm not convinced that
# deleting the file target on failure is always the proper thing to # deleting the file target on failure is always the proper thing to
# do. I'm willing to hear input on this topic. # do. I'm willing to hear input on this topic.

View File

@ -268,6 +268,14 @@ class TestRakeFunctional < Rake::TestCase
assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out) assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
end end
def test_regenerate_imports
rakefile_regenerate_imports
rake
assert_match(/^INITIAL\s+^REGENERATED$/, @out)
end
def test_rules_chaining_to_file_task def test_rules_chaining_to_file_task
rakefile_chains rakefile_chains
@ -368,6 +376,14 @@ class TestRakeFunctional < Rake::TestCase
assert_match(/^PREPARE\nSCOPEDEP$/m, @out) assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
end end
def test_test_task_descriptions
rakefile_test_task
rake "-T"
assert_match(/custom test task description/, @out)
end
def test_comment_before_task_acts_like_desc def test_comment_before_task_acts_like_desc
rakefile_comments rakefile_comments
@ -414,7 +430,7 @@ class TestRakeFunctional < Rake::TestCase
end end
def can_detect_signals? def can_detect_signals?
system "ruby -e 'Process.kill \"TERM\", $$'" system RUBY, '-e', 'Process.kill "TERM", $$'
status = $? status = $?
if @verbose if @verbose
puts " SIG status = #{$?.inspect}" puts " SIG status = #{$?.inspect}"

View File

@ -40,4 +40,18 @@ class TestRakeNameSpace < Rake::TestCase
ns.tasks.map { |tsk| tsk.name } 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
def test_scope
mgr = TM.new
scope = Rake::LinkedList.new 'b'
scope = scope.conj 'a'
ns = Rake::NameSpace.new mgr, scope
assert_equal scope, ns.scope
refute_same scope, ns.scope
end
end end

View File

@ -156,8 +156,8 @@ class TestRakePathMap < Rake::TestCase
"src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class")) "src/org/onstepback/proj/A.java".pathmap("%{src,bin}d/%n.class"))
assert_equal( assert_equal(
"src_work/bin/org/onstepback/proj/A.class", "src_work/bin/org/onstepback/proj/A.class",
"src_work/src/org/onstepback/proj/A.java" "src_work/src/org/onstepback/proj/A.java".
.pathmap('%{\bsrc\b,bin}X.class')) pathmap('%{\bsrc\b,bin}X.class'))
assert_equal( assert_equal(
".depends.bak", ".depends.bak",
".depends".pathmap("%X.bak")) ".depends".pathmap("%X.bak"))

View File

@ -359,4 +359,30 @@ class TestRakeRules < Rake::TestCase
Task[OBJFILE].invoke('arg') Task[OBJFILE].invoke('arg')
end end
def test_rule_with_method_prereq
create_file(".foo")
obj = Object.new
def obj.find_prereq
".foo"
end
rule '.o' => obj.method(:find_prereq) do |t|
@runs << "#{t.name} - #{t.source}"
end
Task[OBJFILE].invoke
assert_equal ["#{OBJFILE} - .foo"], @runs
end
def test_rule_with_one_arg_method_prereq
create_file(SRCFILE)
obj = Object.new
def obj.find_prereq(task_name)
task_name.ext(".c")
end
rule '.o' => obj.method(:find_prereq) do |t|
@runs << "#{t.name} - #{t.source}"
end
Task[OBJFILE].invoke
assert_equal ["#{OBJFILE} - abc.c"], @runs
end
end end

View File

@ -333,6 +333,17 @@ class TestRakeTask < Rake::TestCase
assert_equal "Revision 1.2.3", t.comment assert_equal "Revision 1.2.3", t.comment
end end
def test_comments_do_not_set
t = task(:t, :name, :rev)
assert_equal nil, t.comment
end
def test_comments_is_nil
t = task(:t, :name, :rev)
t.comment = nil
assert_equal nil, t.comment
end
def test_extended_comments def test_extended_comments
desc %{ desc %{
This is a comment. This is a comment.
@ -374,4 +385,9 @@ class TestRakeTask < Rake::TestCase
task(:t) task(:t)
assert_equal "line one / line two", t.comment assert_equal "line one / line two", t.comment
end end
def test_source_is_first_prerequisite
t = task :t => ["preqA", "preqB"]
assert_equal "preqA", t.source
end
end end

View File

@ -43,6 +43,12 @@ class TestRakeTaskArgumentParsing < Rake::TestCase
assert_equal ["a one ana", "two"], args assert_equal ["a one ana", "two"], args
end end
def test_can_handle_commas_in_args
name, args = @app.parse_task_string("name[one, two, three_a\\, three_b, four]")
assert_equal "name", name
assert_equal ["one", "two", "three_a, three_b", "four"], args
end
def test_terminal_width_using_env def test_terminal_width_using_env
app = Rake::Application.new app = Rake::Application.new
app.terminal_columns = 1234 app.terminal_columns = 1234

View File

@ -19,6 +19,12 @@ class TestRakeTaskArguments < Rake::TestCase
assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash) assert_equal({:a => :one, :b => :two, :c => :three}, ta.to_hash)
end end
def test_has_key
ta = Rake::TaskArguments.new([:a], [:one])
assert(ta.has_key?(:a))
refute(ta.has_key?(:b))
end
def test_to_s def test_to_s
ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3]) ta = Rake::TaskArguments.new([:a, :b, :c], [1, 2, 3])
assert_equal ta.to_hash.inspect, ta.to_s assert_equal ta.to_hash.inspect, ta.to_s

View File

@ -40,6 +40,23 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal ["x:t"], @tm.tasks.map { |t| t.name } assert_equal ["x:t"], @tm.tasks.map { |t| t.name }
end end
def test_define_namespaced_task
t = @tm.define_task(Rake::Task, 'n:a:m:e:t')
assert_equal Rake::Scope.make("e", "m", "a", "n"), t.scope
assert_equal "n:a:m:e:t", t.name
assert_equal @tm, t.application
end
def test_define_namespace_in_namespace
t = nil
@tm.in_namespace("n") do
t = @tm.define_task(Rake::Task, 'a:m:e:t')
end
assert_equal Rake::Scope.make("e", "m", "a", "n"), t.scope
assert_equal "n:a:m:e:t", t.name
assert_equal @tm, t.application
end
def test_anonymous_namespace def test_anonymous_namespace
anon_ns = @tm.in_namespace(nil) do anon_ns = @tm.in_namespace(nil) do
t = @tm.define_task(Rake::Task, :t) t = @tm.define_task(Rake::Task, :t)
@ -89,6 +106,7 @@ class TestRakeTaskManager < Rake::TestCase
@tm.in_namespace("a") do @tm.in_namespace("a") do
aa = @tm.define_task(Rake::Task, :aa) aa = @tm.define_task(Rake::Task, :aa)
mid_z = @tm.define_task(Rake::Task, :z) mid_z = @tm.define_task(Rake::Task, :z)
ns_d = @tm.define_task(Rake::Task, "n:t")
@tm.in_namespace("b") do @tm.in_namespace("b") do
bb = @tm.define_task(Rake::Task, :bb) bb = @tm.define_task(Rake::Task, :bb)
bot_z = @tm.define_task(Rake::Task, :z) bot_z = @tm.define_task(Rake::Task, :z)
@ -116,6 +134,8 @@ class TestRakeTaskManager < Rake::TestCase
assert_equal top_z, @tm["^z"] assert_equal top_z, @tm["^z"]
assert_equal top_z, @tm["^^z"] # Over the top assert_equal top_z, @tm["^^z"] # Over the top
assert_equal top_z, @tm["rake:z"] assert_equal top_z, @tm["rake:z"]
assert_equal ns_d, @tm["n:t"]
assert_equal ns_d, @tm["a:n:t"]
end end
assert_equal Rake::Scope.make, @tm.current_scope assert_equal Rake::Scope.make, @tm.current_scope

View File

@ -16,11 +16,13 @@ class TestRakeTestTask < Rake::TestCase
def test_initialize_override def test_initialize_override
tt = Rake::TestTask.new(:example) do |t| tt = Rake::TestTask.new(:example) do |t|
t.description = "Run example tests"
t.libs = ['src', 'ext'] t.libs = ['src', 'ext']
t.pattern = 'test/tc_*.rb' t.pattern = 'test/tc_*.rb'
t.verbose = true t.verbose = true
end end
refute_nil tt refute_nil tt
assert_equal "Run example tests", tt.description
assert_equal :example, tt.name assert_equal :example, tt.name
assert_equal ['src', 'ext'], tt.libs assert_equal ['src', 'ext'], tt.libs
assert_equal 'test/tc_*.rb', tt.pattern assert_equal 'test/tc_*.rb', tt.pattern
@ -81,11 +83,31 @@ class TestRakeTestTask < Rake::TestCase
end end
def test_run_code_rake def test_run_code_rake
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| test_task = Rake::TestTask.new do |t|
t.loader = :rake t.loader = :rake
end end
assert_match(/-I".*?" ".*?"/, test_task.run_code) 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
test_task = Rake::TestTask.new do |t|
t.loader = :rake
end
assert_match(/\A ".*?"\Z/, test_task.run_code)
ensure
Gem.loaded_specs['rake'] = rake
end end
def test_run_code_testrb_ruby_1_8_2 def test_run_code_testrb_ruby_1_8_2