Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rdoc:coverage default task #971

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/rdoc/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
# [rerdoc]
# Rebuild the rdoc files from scratch, even if they are not out of date.
#
# [rdoc:coverage]
# Print RDoc coverage report for all rdoc files.
#
# Simple Example:
#
# require 'rdoc/task'
Expand Down Expand Up @@ -90,8 +93,8 @@
# RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
# :rerdoc => "rdoc:force")
#
# This will create the tasks <tt>:rdoc</tt>, <tt>:rdoc:clean</tt> and
# <tt>:rdoc:force</tt>.
# This will create the tasks <tt>:rdoc</tt>, <tt>:rdoc:clean</tt>,
# <tt>:rdoc:force</tt>, and <tt>:rdoc:coverage</tt>.

class RDoc::Task < Rake::TaskLib

Expand Down Expand Up @@ -248,6 +251,16 @@ def define
RDoc::RDoc.new.document args
end

namespace rdoc_task_name do
desc coverage_task_description
task coverage_task_name do
@before_running_rdoc.call if @before_running_rdoc
opts = option_list << "-C"
args = opts + @rdoc_files

$stderr.puts "rdoc #{args.join ' '}" if Rake.application.options.trace
end
end
zzak marked this conversation as resolved.
Show resolved Hide resolved
self
end

Expand Down Expand Up @@ -288,6 +301,13 @@ def rerdoc_task_description
"Rebuild RDoc HTML files"
end

##
# Task description for the coverage task or its renamed description

def coverage_task_description
"Print RDoc coverage report"
end

private

def rdoc_target
Expand Down Expand Up @@ -315,6 +335,10 @@ def rerdoc_task_name
end
end

def coverage_task_name
"coverage"
end

end

# :stopdoc:
Expand Down
9 changes: 9 additions & 0 deletions test/rdoc/test_rdoc_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_tasks_creation
assert Rake::Task[:rdoc]
assert Rake::Task[:clobber_rdoc]
assert Rake::Task[:rerdoc]
assert Rake::Task[:"rdoc:coverage"]
assert_equal ["html/created.rid"], Rake::Task[:rdoc].prerequisites
end

Expand All @@ -58,6 +59,7 @@ def test_tasks_creation_with_custom_name_symbol
assert Rake::Task[:rdoc_dev]
assert Rake::Task[:clobber_rdoc_dev]
assert Rake::Task[:rerdoc_dev]
assert Rake::Task[:"rdoc_dev:coverage"]
assert_equal :rdoc_dev, rd.name
end

Expand Down Expand Up @@ -110,11 +112,16 @@ def test_rerdoc_task_description
assert_equal 'Rebuild RDoc HTML files', @t.rerdoc_task_description
end

def test_coverage_task_description
assert_equal 'Print RDoc coverage report', @t.coverage_task_description
end

def test_tasks_creation_with_custom_name_string
rd = RDoc::Task.new("rdoc_dev")
assert Rake::Task[:rdoc_dev]
assert Rake::Task[:clobber_rdoc_dev]
assert Rake::Task[:rerdoc_dev]
assert Rake::Task[:"rdoc_dev:coverage"]
assert_equal "rdoc_dev", rd.name
end

Expand All @@ -131,6 +138,7 @@ def test_tasks_creation_with_custom_name_hash
assert Rake::Task[:"rdoc"]
assert Rake::Task[:"rdoc:clean"]
assert Rake::Task[:"rdoc:force"]
assert Rake::Task[:"rdoc:coverage"]
assert_raise(RuntimeError) { Rake::Task[:clobber_rdoc] }
assert_equal options, rd.name
end
Expand All @@ -140,6 +148,7 @@ def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt
assert Rake::Task[:rdoc]
assert Rake::Task[:"rdoc:clean"]
assert Rake::Task[:rerdoc]
assert Rake::Task[:"rdoc:coverage"]
end

def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
Expand Down