summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rdoc/test_rdoc_task.rb
blob: 43d458981d794b915020dfe53fa4527bf40225ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
require 'rdoc/test_case'
require 'rake'

class TestRDocTask < RDoc::TestCase

  def setup
    super

    Rake::Task.clear

    @t = RDoc::Task.new
  end

  def test_clobber_task_description
    assert_equal 'Remove RDoc HTML files', @t.clobber_task_description
  end

  def test_inline_source
    _, err = verbose_capture_io do
      assert @t.inline_source
    end

    assert_equal "RDoc::Task#inline_source is deprecated\n", err

    _, err = verbose_capture_io do
      @t.inline_source = false
    end

    assert_equal "RDoc::Task#inline_source is deprecated\n", err

    capture_io do
      assert @t.inline_source
    end
  end

  def test_markup_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.markup = "tomdoc"
    end

    assert_equal %w[-o html --markup tomdoc], rdoc_task.option_list
  end

  def test_tasks_creation
    RDoc::Task.new
    assert Rake::Task[:rdoc]
    assert Rake::Task[:clobber_rdoc]
    assert Rake::Task[:rerdoc]
    assert_equal ["html/created.rid"], Rake::Task[:rdoc].prerequisites
  end

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

  def test_tasks_option_parser
    rdoc_task = RDoc::Task.new do |rd|
      rd.title = "Test Tasks Option Parser"
      rd.main = "README.md"
      rd.rdoc_files.include("README.md")
      rd.options << "--all"
    end

    assert rdoc_task.title, "Test Tasks Option Parser"
    assert rdoc_task.main, "README.md"
    assert rdoc_task.rdoc_files.include?("README.md")
    assert rdoc_task.options.include?("--all")

    args = %w[--all -o html --main README.md] << "--title" << "Test Tasks Option Parser" << "README.md"
    assert_equal args, rdoc_task.option_list + rdoc_task.rdoc_files
  end

  def test_generator_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.generator = "ri"
    end

    assert_equal %w[-o html -f ri], rdoc_task.option_list
  end

  def test_main_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.main = "README.md"
    end

    assert_equal %w[-o html --main README.md], rdoc_task.option_list
  end

  def test_output_dir_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.rdoc_dir = "zomg"
    end

    assert_equal %w[-o zomg], rdoc_task.option_list
  end

  def test_rdoc_task_description
    assert_equal 'Build RDoc HTML files', @t.rdoc_task_description
  end

  def test_rerdoc_task_description
    assert_equal 'Rebuild RDoc HTML files', @t.rerdoc_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_equal "rdoc_dev", rd.name
  end

  def test_tasks_creation_with_custom_name_hash
    options = {
      :rdoc => "rdoc",
      :clobber_rdoc => "rdoc:clean",
      :rerdoc => "rdoc:force"
    }

    Rake::Task.clear

    rd = RDoc::Task.new(options)
    assert Rake::Task[:"rdoc"]
    assert Rake::Task[:"rdoc:clean"]
    assert Rake::Task[:"rdoc:force"]
    assert_raises(RuntimeError) { Rake::Task[:clobber_rdoc] }
    assert_equal options, rd.name
  end

  def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
    RDoc::Task.new(:clobber_rdoc => "rdoc:clean")
    assert Rake::Task[:rdoc]
    assert Rake::Task[:"rdoc:clean"]
    assert Rake::Task[:rerdoc]
  end

  def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
    assert_raises(ArgumentError) do
      RDoc::Task.new(:foo => "bar")
    end

    begin
      RDoc::Task.new(:foo => "bar")
    rescue ArgumentError => e
      assert_match(/foo/, e.message)
    end
  end

  def test_template_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.template = "foo"
    end

    assert_equal %w[-o html -T foo], rdoc_task.option_list
  end

  def test_title_option
    rdoc_task = RDoc::Task.new do |rd|
      rd.title = "Test Title Option"
    end

    assert_equal %w[-o html] << "--title" << "Test Title Option", rdoc_task.option_list
  end

end