Skip to content

Commit

Permalink
Merge pull request #971 from zzak/rdoc-coverage-task
Browse files Browse the repository at this point in the history
Add rdoc:coverage default task
  • Loading branch information
zzak authored Feb 3, 2023
2 parents 71dd5c7 + 6d609cb commit 68f7b13
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 27 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,17 @@ 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

self
end

Expand Down Expand Up @@ -288,6 +302,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 +336,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

0 comments on commit 68f7b13

Please sign in to comment.