Skip to content
Browse files

Changes to get 100% code coverage in main rake.rb file.

git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@604 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information...
1 parent d800e9b commit e462afc4bfa67bf1a5e7889123e1e002d9d2ef1f jimweirich committed
View
37 Rakefile
@@ -23,7 +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')
+CLOBBER.include('coverage', 'rcov_aggregate')
def announce(msg='')
STDERR.puts msg
@@ -92,11 +92,14 @@ begin
Rcov::RcovTask.new do |t|
t.libs << "test"
- t.rcov_opts = ['-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report']
+ t.rcov_opts = [
+ '-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report',
+ ]
t.test_files = FileList[
- 'test/test*.rb',
- 'test/contrib/test*.rb'
+ 'test/test*.rb', 'test/functional.rb'
+# 'test/contrib/test*.rb'
]
+ t.output_dir = 'coverage'
t.verbose = true
end
rescue LoadError
@@ -245,12 +248,6 @@ task :lines do
show_line("TOTAL", total_lines, total_code)
end
-ARCHIVEDIR = '/mnt/usb'
-
-task :archive => [:package] do
- cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR
-end
-
# Define an optional publish target in an external file. If the
# publish.rf file is not found, the publish targets won't be defined.
@@ -258,23 +255,35 @@ load "publish.rf" if File.exist? "publish.rf"
# Support Tasks ------------------------------------------------------
+RUBY_FILES = FileList['**/*.rb'].exclude('pkg')
+
desc "Look for TODO and FIXME tags in the code"
task :todo do
- FileList['**/*.rb'].exclude('pkg').egrep(/#.*(FIXME|TODO|TBD)/)
+ RUBY_FILES.egrep(/#.*(FIXME|TODO|TBD)/)
end
desc "Look for Debugging print lines"
task :dbg do
- FileList['**/*.rb'].egrep(/\bDBG|\bbreakpoint\b/)
+ RUBY_FILES.egrep(/\bDBG|\bbreakpoint\b/)
end
desc "List all ruby files"
task :rubyfiles do
- puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
- puts Dir['bin/*'].reject { |fn| fn =~ /CVS|(~$)|(\.rb$)/ }
+ puts RUBY_FILES
+ puts FileList['bin/*'].exclude('bin/*.rb')
end
task :rf => :rubyfiles
+desc "Create a TAGS file"
+task :tags => "TAGS"
+
+TAGS = 'xctags -e'
+
+file "TAGS" => RUBY_FILES do
+ puts "Makings TAGS"
+ sh "#{TAGS} #{RUBY_FILES}", :verbose => false
+end
+
# --------------------------------------------------------------------
# Creating a release
View
72 lib/rake.rb
@@ -304,10 +304,6 @@ def append(value)
self.class.new(value, self)
end
- def prefix
- "#{@tail.to_s} => "
- end
-
def to_s
"#{prefix}#{@value}"
end
@@ -316,6 +312,12 @@ def self.append(value, chain)
chain.append(value)
end
+ private
+
+ def prefix
+ "#{@tail.to_s} => "
+ end
+
class EmptyInvocationChain
def member?(obj)
false
@@ -323,9 +325,6 @@ def member?(obj)
def append(value)
InvocationChain.new(value, self)
end
- def prefix
- "#{to_s} => "
- end
def to_s
"TOP"
end
@@ -500,16 +499,9 @@ def execute
puts "** Execute #{name}"
end
application.enhance_with_matching_rule(name) if @actions.empty?
- @actions.each { |act|
- case act.arity
- when 0
- act.call
- when 1
- act.call(self)
- else
- act.call(self, *args)
- end
- }
+ @actions.each do |act|
+ (act.arity == 1) ? act.call(self) : act.call(self, *args)
+ end
end
# Is this task needed?
@@ -556,9 +548,9 @@ def add_comment(comment)
else
@comment = @full_comment
end
- if @comment.length > 50
- @comment = @comment[0, 47] + "..."
- end
+# if @comment.length > 50
+# @comment = @comment[0, 47] + "..."
+# end
end
private :add_comment
@@ -1143,7 +1135,7 @@ class FileList
ln = __LINE__+1
class_eval %{
def #{sym}(*args, &block)
- resolve if @pending
+ resolve
result = @items.send(:#{sym}, *args, &block)
FileList.new.import(result)
end
@@ -1152,7 +1144,7 @@ def #{sym}(*args, &block)
ln = __LINE__+1
class_eval %{
def #{sym}(*args, &block)
- resolve if @pending
+ resolve
result = @items.send(:#{sym}, *args, &block)
result.object_id == @items.object_id ? self : result
end
@@ -1427,7 +1419,7 @@ def partition(&block) # :nodoc:
# Convert a FileList to a string by joining all elements with a space.
def to_s
- resolve if @pending
+ resolve
self.join(' ')
end
@@ -1454,7 +1446,7 @@ def exclude?(fn)
DEFAULT_IGNORE_PROCS = [
proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
]
- @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
+# @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
def import(array)
@items = array
@@ -1468,26 +1460,6 @@ class << self
def [](*args)
new(*args)
end
-
- # Set the ignore patterns back to the default value. The default
- # patterns will ignore files
- # * containing "CVS" in the file path
- # * containing ".svn" in the file path
- # * ending with ".bak"
- # * ending with "~"
- # * named "core"
- #
- # Note that file names beginning with "." are automatically ignored by
- # Ruby's glob patterns and are not specifically listed in the ignore
- # patterns.
- def select_default_ignore_patterns
- @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
- end
-
- # Clear the ignore patterns.
- def clear_ignore_patterns
- @exclude_patterns = [ /^$/ ]
- end
end
end # FileList
end
@@ -1759,7 +1731,7 @@ def attempt_rule(task_name, extensions, block, level)
def make_sources(task_name, extensions)
extensions.collect { |ext|
case ext
- when /^%/
+ when /%/
task_name.pathmap(ext)
when %r{/}
ext
@@ -1920,13 +1892,9 @@ def invoke_task(task_string)
end
def parse_task_string(string)
- if string =~ /^([^\[]+)(\[(.*)\])?$/
+ if string =~ /^([^\[]+)(\[(.*)\])$/
name = $1
- if $3
- args = $3.split(/\s*,\s*/)
- else
- args = []
- end
+ args = $3.split(/\s*,\s*/)
else
name = string
args = []
@@ -1999,7 +1967,7 @@ def display_tasks_and_comments
}
if options.full_description
displayable_tasks.each do |t|
- puts "task #{t.name_with_args}"
+ puts "rake #{t.name_with_args}"
t.full_comment.each do |line|
puts " #{line}"
end
View
3 test/data/multidesc/Rakefile
@@ -12,3 +12,6 @@ desc "A2"
task :a
task :c
+
+desc "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+task :d
View
32 test/session_functional.rb
@@ -18,8 +18,13 @@ def initialize(*args)
end
class FunctionalTest < Test::Unit::TestCase
+
+ RUBY_COMMAND = 'ruby'
+
def setup
@rake_path = File.expand_path("bin/rake")
+ @coverage_aggregate_file = File.expand_path("rcov_aggregate")
+ @rcov_dir = File.expand_path("coverage")
lib_path = File.expand_path("lib")
@ruby_options = "-I#{lib_path} -I."
@verbose = ! ENV['VERBOSE'].nil?
@@ -61,6 +66,15 @@ def test_multi_desc
assert_match %r{^rake a *# A / A2 *$}, @out
assert_match %r{^rake b *# B *$}, @out
assert_no_match %r{^rake c}, @out
+ assert_match %r{^rake d *# x{47}\.\.\.$}, @out
+ end
+
+ def test_long_description
+ Dir.chdir("test/data/multidesc") do rake "--describe" end
+ assert_match %r{^task a\n *A / A2 *$}m, @out
+ assert_match %r{^task b\n *B *$}m, @out
+ assert_match %r{^task d\n *x{80}}m, @out
+ assert_no_match %r{^task c\n}m, @out
end
def test_rbext
@@ -212,10 +226,26 @@ def remove_chaining_files
end
end
+ class << self
+ def format_command
+ @format_command ||= lambda { |ruby_options, rake_path, options|
+ "ruby #{ruby_options} #{rake_path} #{options}"
+ }
+ end
+
+ def format_command=(fmt_command)
+ @format_command = fmt_command
+ end
+ end
+
def rake(*option_list)
+ self.class.format_command = lambda { |ruby_options, rake_path, options|
+ "rcov --output=#{@rcov_dir} --aggregate=#{@coverage_aggregate_file} #{ruby_options} #{rake_path} -- #{options}"
+ }
+
options = option_list.join(' ')
shell = Session::Shell.new
- command = "ruby #{@ruby_options} #{@rake_path} #{options}"
+ command = self.class.format_command[@ruby_options, @rake_path, options]
puts "COMMAND: [#{command}]" if @verbose
@out, @err = shell.execute command
@status = shell.exit_status
View
31 test/test_application.rb
@@ -38,6 +38,25 @@ def test_display_tasks
assert_match(/# COMMENT/, out)
end
+ def test_display_tasks_with_long_comments
+ @app.options.show_task_pattern = //
+ @app.last_description = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ @app.define_task(Rake::Task, "t")
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ assert_match(/^rake t/, out)
+ assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
+ end
+
+ def test_display_tasks_with_full_descriptions
+ @app.options.show_task_pattern = //
+ @app.options.full_description = true
+ @app.last_description = "COMMENT"
+ @app.define_task(Rake::Task, "t")
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ assert_match(/^rake t$/, out)
+ assert_match(/^ {4}COMMENT$/, out)
+ end
+
def test_finding_rakefile
assert @app.instance_eval { have_rakefile }
assert_equal "rakefile", @app.rakefile.downcase
@@ -253,15 +272,23 @@ def test_dry_run
end
def test_help
- flags('--help', '-H') do |opts, output|
+ flags('--help', '-H') do |opts|
assert_match(/\Arake/, @out)
assert_match(/--help/, @out)
assert_equal :exit, @exit
end
end
+ def test_describe
+ flags('--describe') do |opts|
+ assert opts.full_description
+ assert opts.show_tasks
+ assert_equal(//.to_s, opts.show_task_pattern.to_s)
+ end
+ end
+
def test_usage
- flags('--usage', '-h') do |opts, output|
+ flags('--usage', '-h') do |opts|
assert_match(/\Arake/, @out)
assert_match(/\boptions\b/, @out)
assert_match(/\btargets\b/, @out)
View
63 test/test_extension.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+
+require 'test/unit'
+require 'rake'
+
+######################################################################
+class TestExtension < Test::Unit::TestCase
+
+ module Redirect
+ def error_redirect
+ old_err = $stderr
+ result = StringIO.new
+ $stderr = result
+ yield
+ result
+ ensure
+ $stderr = old_err
+ end
+ end
+
+ class Sample
+ extend Redirect
+
+ def duplicate_method
+ :original
+ end
+
+ OK_ERRS = error_redirect do
+ rake_extension("a") do
+ def ok_method
+ end
+ end
+ end
+
+
+ DUP_ERRS = error_redirect do
+ rake_extension("duplicate_method") do
+ def duplicate_method
+ :override
+ end
+ end
+ end
+
+ end
+
+ def test_methods_actually_exist
+ sample = Sample.new
+ sample.ok_method
+ sample.duplicate_method
+ end
+
+ def test_no_warning_when_defining_ok_method
+ assert_equal "", Sample::OK_ERRS.string
+ end
+
+ def test_extension_complains_when_a_method_that_is_present
+ assert_match(/warning:/i, Sample::DUP_ERRS.string)
+ assert_match(/already exists/i, Sample::DUP_ERRS.string)
+ assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
+ assert_equal :original, Sample.new.duplicate_method
+ end
+
+end
View
4 test/test_filelist.rb
@@ -13,7 +13,7 @@ def setup
end
def teardown
- FileList.select_default_ignore_patterns
+# FileList.select_default_ignore_patterns
FileUtils.rm_rf("testdata")
end
@@ -543,7 +543,7 @@ def test_other_array_returning_methods
def test_file_utils_can_use_filelists
cfiles = FileList['testdata/*.c']
- cp cfiles, @cdir
+ cp cfiles, @cdir, :verbose => false
assert File.exist?(File.join(@cdir, 'abc.c'))
assert File.exist?(File.join(@cdir, 'xyz.c'))
View
1 test/test_invocation_chain.rb
@@ -42,7 +42,6 @@ def test_should_fail_when_adding_original_member
end
def test_to_s
- assert_equal "TOP => ", @chain.prefix
assert_equal "TOP => A", @chain.to_s
end
View
36 test/test_rules.rb
@@ -113,10 +113,23 @@ def test_file_names_beginning_with_dot_can_be_wrapped_in_lambda
chdir("testdata") do
create_file(".foo")
rule '.o' => lambda{".foo"} do |t|
- @runs << t.name
+ @runs << "#{t.name} - #{t.source}"
end
Task[OBJFILE].invoke
- assert_equal [OBJFILE], @runs
+ assert_equal ["#{OBJFILE} - .foo"], @runs
+ end
+ end
+ end
+
+ def test_file_names_containing_percent_can_be_wrapped_in_lambda
+ verbose(false) do
+ chdir("testdata") do
+ create_file("foo%x")
+ rule '.o' => lambda{"foo%x"} do |t|
+ @runs << "#{t.name} - #{t.source}"
+ end
+ Task[OBJFILE].invoke
+ assert_equal ["#{OBJFILE} - foo%x"], @runs
end
end
end
@@ -137,12 +150,25 @@ def test_non_extension_rule_name_refers_to_file
def test_pathmap_automatically_applies_to_name
verbose(false) do
chdir("testdata") do
- create_file("abc.c")
- rule ".o" => '%{x,a}n.c' do |t|
+ create_file("zzabc.c")
+ rule ".o" => 'zz%{x,a}n.c' do |t|
+ @runs << "#{t.name} - #{t.source}"
+ end
+ Task["xbc.o"].invoke
+ assert_equal ["xbc.o - zzabc.c"], @runs
+ end
+ end
+ end
+
+ def test_plain_strings_are_just_filenames
+ verbose(false) do
+ chdir("testdata") do
+ create_file("plainname")
+ rule ".o" => 'plainname' do |t|
@runs << "#{t.name} - #{t.source}"
end
Task["xbc.o"].invoke
- assert_equal ["xbc.o - abc.c"], @runs
+ assert_equal ["xbc.o - plainname"], @runs
end
end
end
View
38 test/test_tasks.rb
@@ -151,16 +151,38 @@ def test_investigation_output
end
def test_tasks_can_access_arguments
- t = intern(:t1).enhance { |t|
+ t = intern(:t).enhance do |t|
a, b, c = t.args
assert_equal 1, a
assert_equal 2, b
assert_equal 3, c
- }
+ end
t.args = [1, 2, 3]
t.invoke
end
+ def test_actions_of_various_arity_are_ok_with_args
+ notes = []
+ t = intern(:t).enhance do
+ notes << :a
+ end
+ t.enhance do ||
+ notes << :b
+ end
+ t.enhance do |t|
+ notes << :c
+ assert_kind_of Task, t
+ end
+ t.enhance do |t2, a|
+ notes << :d
+ assert_equal t, t2
+ assert_equal 1, a
+ end
+ t.args = [1, 2, 3]
+ assert_nothing_raised do t.invoke end
+ assert_equal [:a, :b, :c, :d], notes
+ end
+
def test_arguments_are_passed_to_block
t = intern(:t).enhance { |t, a|
assert_equal 1, a
@@ -299,12 +321,6 @@ def test_comments_below_limit_are_unchanged
assert_equal "12345678901234567890123456789012345678901234567890", t.comment
end
- def test_comments_above_limit_are_truncated
- desc %{123456789012345678901234567890123456789012345678901}
- t = intern(:t)
- assert_equal "12345678901234567890123456789012345678901234567...", t.comment
- end
-
def test_multiple_comments
desc "line one"
t = intern(:t)
@@ -313,6 +329,12 @@ def test_multiple_comments
assert_equal "line one / line two", t.comment
end
+ def test_settable_comments
+ t = intern(:t)
+ t.comment = "HI"
+ assert_equal "HI", t.comment
+ end
+
private
def intern(name)

0 comments on commit e462afc

Please sign in to comment.
Something went wrong with that request. Please try again.