Skip to content

Commit

Permalink
added rcov and unit tests
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@564 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information
jimweirich committed Jun 1, 2006
1 parent 0cb938c commit c8197eb
Show file tree
Hide file tree
Showing 18 changed files with 711 additions and 53 deletions.
1 change: 1 addition & 0 deletions rake/.cvsignore
@@ -1,3 +1,4 @@
coverage
testdata
html
pkg
Expand Down
3 changes: 3 additions & 0 deletions rake/CHANGES
Expand Up @@ -6,6 +6,9 @@
Payton Quackenbush).
* Better error handling on invalid command line arguments (from Payton
Quackenbush).
* Added rcov task and updated unit testing for better code coverage.
* Fixed some bugs where the application object was going to the global
appliation instead of using its own data.

== Version 0.7.1

Expand Down
17 changes: 15 additions & 2 deletions rake/Rakefile
Expand Up @@ -23,6 +23,7 @@ CLOBBER.include('test/data/chains/play.*')
CLOBBER.include('test/data/file_creation_task/build')
CLOBBER.include('test/data/file_creation_task/src')
CLOBBER.include('TAGS')
CLOBBER.include('coverage')

def announce(msg='')
STDERR.puts msg
Expand Down Expand Up @@ -87,6 +88,18 @@ Rake::TestTask.new(:test_contribs) do |t|
t.warning = true
end

require 'rcov/rcovtask'

Rcov::RcovTask.new do |t|
t.libs << "test"
t.rcov_opts = ['-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report']
t.test_files = FileList[
'test/test*.rb',
'test/contrib/test*.rb'
]
t.verbose = true
end

directory 'testdata'
[:test_all, :test_units, :test_contribs, :test_functional].each do |t|
task t => ['testdata']
Expand Down Expand Up @@ -244,12 +257,12 @@ load "publish.rf" if File.exist? "publish.rf"

desc "Look for TODO and FIXME tags in the code"
task :todo do
FileList['**/*.rb'].exclude('pkg').egrep /#.*(FIXME|TODO|TBD)/
FileList['**/*.rb'].exclude('pkg').egrep(/#.*(FIXME|TODO|TBD)/)
end

desc "Look for Debugging print lines"
task :dbg do
FileList['**/*.rb'].egrep /\bDBG|\bbreakpoint\b/
FileList['**/*.rb'].egrep(/\bDBG|\bbreakpoint\b/)
end

desc "List all ruby files"
Expand Down
62 changes: 25 additions & 37 deletions rake/lib/rake.rb
Expand Up @@ -395,7 +395,7 @@ def needed?
# Timestamp for this task. Basic tasks return the current time for
# their time stamp. Other tasks can be more sophisticated.
def timestamp
@prerequisites.collect { |p| Rake::Task[p].timestamp }.max || Time.now
@prerequisites.collect { |p| application[p].timestamp }.max || Time.now
end

# Add a comment to the task. If a comment alread exists, separate
Expand All @@ -419,12 +419,12 @@ def investigation
result << "task needed: #{needed?}\n"
result << "timestamp: #{timestamp}\n"
result << "pre-requisites: \n"
prereqs = @prerequisites.collect {|name| Rake::Task[name]}
prereqs = @prerequisites.collect {|name| application[name]}
prereqs.sort! {|a,b| a.timestamp <=> b.timestamp}
prereqs.each do |p|
result << "--#{p.name} (#{p.timestamp})\n"
end
latest_prereq = @prerequisites.collect{|n| Rake::Task[n].timestamp}.max
latest_prereq = @prerequisites.collect{|n| application[n].timestamp}.max
result << "latest-prerequisite time: #{latest_prereq}\n"
result << "................................\n\n"
return result
Expand Down Expand Up @@ -513,7 +513,7 @@ def timestamp
# Are there any prerequisites with a later time than the given
# time stamp?
def out_of_date?(stamp)
@prerequisites.any? { |n| Rake::Task[n].timestamp > stamp}
@prerequisites.any? { |n| application[n].timestamp > stamp}
end

# ----------------------------------------------------------------
Expand Down Expand Up @@ -555,7 +555,7 @@ def timestamp
class MultiTask < Task
def invoke_prerequisites
threads = @prerequisites.collect { |p|
Thread.new(p) { |r| Task[r].invoke }
Thread.new(p) { |r| application[r].invoke }
}
threads.each { |t| t.join }
end
Expand Down Expand Up @@ -710,11 +710,7 @@ module FileUtils
# end
#
def sh(*cmd, &block)
if Hash === cmd.last then
options = cmd.pop
else
options = {}
end
options = (Hash === cmd.last) ? cmd.pop : {}
unless block_given?
show_command = cmd.join(" ")
show_command = show_command[0,42] + "..." if show_command.length > 45
Expand All @@ -736,11 +732,7 @@ def sh(*cmd, &block)
# ruby %{-pe '$_.upcase!' <README}
#
def ruby(*args,&block)
if Hash === args.last
options = args.pop
else
options = {}
end
options = (Hash === args.last) ? args.pop : {}
if args.length > 1 then
sh(*([RUBY] + args + [options]), &block)
else
Expand All @@ -758,7 +750,7 @@ def safe_ln(*args)
else
begin
ln(*args)
rescue StandardError, NotImplementedError
rescue StandardError, NotImplementedError => ex
LN_SUPPORTED[0] = false
cp(*args)
end
Expand Down Expand Up @@ -1125,7 +1117,7 @@ def calculate_exclude_regexp
case pat
when Regexp
ignores << pat
when /[*.]/
when /[*?]/
Dir[pat].each do |p| ignores << p end
else
ignores << Regexp.quote(pat)
Expand All @@ -1141,8 +1133,6 @@ def calculate_exclude_regexp

def resolve_add(fn)
case fn
when Array
fn.each { |f| self.resolve_add(f) }
when %r{[*?]}
add_matching(fn)
else
Expand All @@ -1156,7 +1146,7 @@ def resolve_exclude
case pat
when Regexp
reject! { |fn| fn =~ pat }
when /[*.]/
when /[*?]/
reject_list = Dir[pat]
reject! { |fn| reject_list.include?(fn) }
else
Expand Down Expand Up @@ -1427,7 +1417,6 @@ def define_task(task_class, args, &block)
deps = [deps] unless deps.respond_to?(:to_ary)
deps = deps.collect {|d| d.to_s }
task = intern(task_class, task_name)
task.application = self
task.add_comment(@last_comment)
@last_comment = nil
task.enhance(deps, &block)
Expand Down Expand Up @@ -1602,9 +1591,9 @@ class Application
include TaskManager

# The original directory where rake was invoked.
attr_reader :original_dir
attr_reader :original_dir, :rakefile

RAKEFILES = ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb']
DEFAULT_RAKEFILES = ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].freeze

OPTIONS = [
['--dry-run', '-n', GetoptLong::NO_ARGUMENT,
Expand Down Expand Up @@ -1644,6 +1633,7 @@ class Application
# Create a Rake::Application object.
def initialize
super
@rakefiles = DEFAULT_RAKEFILES.dup
@rakefile = nil
@pending_imports = []
@imported = []
Expand All @@ -1662,7 +1652,7 @@ def options
# True if one of the files in RAKEFILES is in the current directory.
# If a match is found, it is copied into @rakefile.
def have_rakefile
RAKEFILES.each do |fn|
@rakefiles.each do |fn|
if File.exist?(fn) || fn == ''
@rakefile = fn
return true
Expand Down Expand Up @@ -1695,20 +1685,18 @@ def help

# Display the tasks and dependencies.
def display_tasks_and_comments
displayable_tasks = Rake::Task.tasks.select { |t|
displayable_tasks = tasks.select { |t|
t.comment && t.name =~ options.show_task_pattern
}
width = displayable_tasks.collect { |t|
t.name.length
}.max
width = displayable_tasks.collect { |t| t.name.length }.max
displayable_tasks.each do |t|
printf "rake %-#{width}s # %s\n", t.name, t.comment
end
end

# Display the tasks and prerequisites
def display_prerequisites
Rake::Task.tasks.each do |t|
tasks.each do |t|
puts "rake #{t.name}"
t.prerequisites.each { |pre| puts " #{pre}" }
end
Expand Down Expand Up @@ -1740,8 +1728,8 @@ def do_option(opt, value)
when '--quiet'
verbose(false)
when '--rakefile'
RAKEFILES.clear
RAKEFILES << value
@rakefiles.clear
@rakefiles << value
when '--rakelibdir'
options.rakelib = value.split(':')
when '--require'
Expand Down Expand Up @@ -1774,8 +1762,6 @@ def do_option(opt, value)
when '--classic-namespace'
require 'rake/classic_namespace'
options.classic_namespace = true
else
fail "Unknown option: #{opt}"
end
end

Expand Down Expand Up @@ -1819,7 +1805,7 @@ def load_rakefile
while ! have_rakefile
Dir.chdir("..")
if Dir.pwd == here || options.nosearch
fail "No Rakefile found (looking for: #{RAKEFILES.join(', ')})"
fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})"
end
here = Dir.pwd
end
Expand All @@ -1833,7 +1819,7 @@ def load_rakefile
end

# Collect the list of tasks on the command line. If no tasks are
# give, 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.
def collect_tasks
tasks = []
Expand All @@ -1857,7 +1843,9 @@ def add_import(fn)
def load_imports
while fn = @pending_imports.shift
next if @imported.member?(fn)
Rake::Task[fn].invoke if Rake::Task.task_defined?(fn)
if fn_task = lookup(fn)
fn_task.invoke
end
ext = File.extname(fn)
loader = @loaders[ext] || @default_loader
loader.load(fn)
Expand Down Expand Up @@ -1903,7 +1891,7 @@ def run
elsif options.show_prereqs
display_prerequisites
else
tasks.each { |task_name| Rake::Task[task_name].invoke }
tasks.each { |task_name| self[task_name].invoke }
end
rescue SystemExit, GetoptLong::InvalidOption => ex
# Exit silently
Expand Down
26 changes: 26 additions & 0 deletions rake/test/capture_stdout.rb
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby

require 'stringio'

# Mix-in for capturing standard output.
module CaptureStdout
def capture_stdout
s = StringIO.new
oldstdout = $stdout
$stdout = s
yield
s.string
ensure
$stdout = oldstdout
end

def capture_stderr
s = StringIO.new
oldstderr = $stderr
$stderr = s
yield
s.string
ensure
$stderr = oldstderr
end
end
3 changes: 3 additions & 0 deletions rake/test/reqfile.rb
@@ -0,0 +1,3 @@
# For --require testing

TESTING_REQUIRE << 1
3 changes: 3 additions & 0 deletions rake/test/reqfile2.rb
@@ -0,0 +1,3 @@
# For --require testing

TESTING_REQUIRE << 2
3 changes: 3 additions & 0 deletions rake/test/reqfile3.rake
@@ -0,0 +1,3 @@
# For --require testing

TESTING_REQUIRE << 3

0 comments on commit c8197eb

Please sign in to comment.