~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rdoc/test_rdoc_options.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
require 'minitest/autorun'
3
3
require 'rdoc/options'
4
4
 
 
5
require 'fileutils'
 
6
require 'tmpdir'
 
7
 
5
8
class TestRDocOptions < MiniTest::Unit::TestCase
6
9
 
7
10
  def setup
8
11
    @options = RDoc::Options.new
 
12
    @generators = RDoc::RDoc::GENERATORS.dup
 
13
  end
 
14
 
 
15
  def teardown
 
16
    RDoc::RDoc::GENERATORS.replace @generators
 
17
  end
 
18
 
 
19
  def test_check_files
 
20
    skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM
 
21
    out, err = capture_io do
 
22
      Dir.mktmpdir do |dir|
 
23
        Dir.chdir dir do
 
24
          FileUtils.touch 'unreadable'
 
25
          FileUtils.chmod 0, 'unreadable'
 
26
 
 
27
          @options.files = %w[nonexistent unreadable]
 
28
 
 
29
          @options.check_files
 
30
        end
 
31
      end
 
32
    end
 
33
 
 
34
    assert_empty @options.files
 
35
 
 
36
    assert_equal '', out
 
37
 
 
38
    expected = <<-EXPECTED
 
39
file 'nonexistent' not found
 
40
file 'unreadable' not readable
 
41
    EXPECTED
 
42
 
 
43
    assert_equal expected, err
 
44
  end
 
45
 
 
46
  def test_dry_run_default
 
47
    refute @options.dry_run
 
48
  end
 
49
 
 
50
  def test_encoding_default
 
51
    skip "Encoding not implemented" unless Object.const_defined? :Encoding
 
52
 
 
53
    assert_equal Encoding.default_external, @options.encoding
 
54
  end
 
55
 
 
56
  def test_generator_descriptions
 
57
    # HACK autotest/isolate should take care of this
 
58
    RDoc::RDoc::GENERATORS.clear
 
59
    RDoc::RDoc::GENERATORS['darkfish'] = RDoc::Generator::Darkfish
 
60
    RDoc::RDoc::GENERATORS['ri']       = RDoc::Generator::RI
 
61
 
 
62
    expected = <<-EXPECTED.chomp
 
63
  darkfish - HTML generator, written by Michael Granger
 
64
  ri       - creates ri data files
 
65
    EXPECTED
 
66
 
 
67
    assert_equal expected, @options.generator_descriptions
 
68
  end
 
69
 
 
70
  def test_parse_coverage
 
71
    @options.parse %w[--dcov]
 
72
 
 
73
    assert @options.coverage_report
 
74
    assert @options.force_update
 
75
  end
 
76
 
 
77
  def test_parse_coverage_no
 
78
    @options.parse %w[--no-dcov]
 
79
 
 
80
    refute @options.coverage_report
 
81
  end
 
82
 
 
83
  def test_parse_coverage_level_1
 
84
    @options.parse %w[--dcov=1]
 
85
 
 
86
    assert_equal 1, @options.coverage_report
 
87
  end
 
88
 
 
89
  def test_parse_dash_p
 
90
    out, err = capture_io do
 
91
      @options.parse %w[-p]
 
92
    end
 
93
 
 
94
    assert @options.pipe
 
95
    refute_match %r%^Usage: %, err
 
96
    refute_match %r%^invalid options%, err
 
97
 
 
98
    assert_empty out
 
99
  end
 
100
 
 
101
  def test_parse_dash_p_files
 
102
    out, err = capture_io do
 
103
      @options.parse ['-p', File.expand_path(__FILE__)]
 
104
    end
 
105
 
 
106
    refute @options.pipe
 
107
    refute_match %r%^Usage: %, err
 
108
    assert_match %r%^invalid options: -p .with files.%, err
 
109
 
 
110
    assert_empty out
 
111
  end
 
112
 
 
113
  def test_parse_default
 
114
    @options.parse []
 
115
 
 
116
    assert_equal RDoc::Generator::Darkfish,             @options.generator
 
117
    assert_equal 'darkfish',                            @options.template
 
118
    assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir
 
119
  end
 
120
 
 
121
  def test_parse_deprecated
 
122
    dep_hash = RDoc::Options::DEPRECATED
 
123
    options = dep_hash.keys.sort
 
124
 
 
125
    out, err = capture_io do
 
126
      @options.parse options
 
127
    end
 
128
 
 
129
    dep_hash.each_pair do |opt, message|
 
130
      assert_match %r%.*#{opt}.+#{message}%, err
 
131
    end
 
132
 
 
133
    assert_empty out
 
134
  end
 
135
 
 
136
  def test_parse_dry_run
 
137
    @options.parse %w[--dry-run]
 
138
 
 
139
    assert @options.dry_run
 
140
  end
 
141
 
 
142
  def test_parse_encoding
 
143
    skip "Encoding not implemented" unless Object.const_defined? :Encoding
 
144
 
 
145
    @options.parse %w[--encoding Big5]
 
146
 
 
147
    assert_equal Encoding::Big5, @options.encoding
 
148
    assert_equal 'Big5',         @options.charset
 
149
  end
 
150
 
 
151
  def test_parse_encoding_invalid
 
152
    skip "Encoding not implemented" unless Object.const_defined? :Encoding
 
153
 
 
154
    out, err = capture_io do
 
155
      @options.parse %w[--encoding invalid]
 
156
    end
 
157
 
 
158
    assert_match %r%^invalid options: --encoding invalid%, err
 
159
 
 
160
    assert_empty out
 
161
  end
 
162
 
 
163
  def test_parse_formatter
 
164
    e = assert_raises OptionParser::InvalidOption do
 
165
      @options.parse %w[--format darkfish --format ri]
 
166
    end
 
167
 
 
168
    assert_equal 'invalid option: --format generator already set to darkfish',
 
169
                 e.message
 
170
  end
 
171
 
 
172
  def test_parse_formatter_ri
 
173
    e = assert_raises OptionParser::InvalidOption do
 
174
      @options.parse %w[--format darkfish --ri]
 
175
    end
 
176
 
 
177
    assert_equal 'invalid option: --ri generator already set to darkfish',
 
178
                 e.message
 
179
 
 
180
    @options = RDoc::Options.new
 
181
 
 
182
    e = assert_raises OptionParser::InvalidOption do
 
183
      @options.parse %w[--format darkfish -r]
 
184
    end
 
185
 
 
186
    assert_equal 'invalid option: -r generator already set to darkfish',
 
187
                 e.message
 
188
  end
 
189
 
 
190
  def test_parse_formatter_ri_site
 
191
    e = assert_raises OptionParser::InvalidOption do
 
192
      @options.parse %w[--format darkfish --ri-site]
 
193
    end
 
194
 
 
195
    assert_equal 'invalid option: --ri-site generator already set to darkfish',
 
196
                 e.message
 
197
 
 
198
    @options = RDoc::Options.new
 
199
 
 
200
    e = assert_raises OptionParser::InvalidOption do
 
201
      @options.parse %w[--format darkfish -R]
 
202
    end
 
203
 
 
204
    assert_equal 'invalid option: -R generator already set to darkfish',
 
205
                 e.message
 
206
  end
 
207
 
 
208
  def test_parse_help
 
209
    out, = capture_io do
 
210
      begin
 
211
        @options.parse %w[--help]
 
212
      rescue SystemExit
 
213
      end
 
214
    end
 
215
 
 
216
    assert_equal 1, out.scan(/HTML generator options:/).length
 
217
    assert_equal 1, out.scan(/ri generator options:/).  length
 
218
  end
 
219
 
 
220
  def test_parse_help_extra_generator
 
221
    RDoc::RDoc::GENERATORS['test'] = Class.new do
 
222
      def self.setup_options options
 
223
        op = options.option_parser
 
224
 
 
225
        op.separator 'test generator options:'
 
226
      end
 
227
    end
 
228
 
 
229
    out, = capture_io do
 
230
      begin
 
231
        @options.parse %w[--help]
 
232
      rescue SystemExit
 
233
      end
 
234
    end
 
235
 
 
236
    assert_equal 1, out.scan(/HTML generator options:/).length
 
237
    assert_equal 1, out.scan(/ri generator options:/).  length
 
238
    assert_equal 1, out.scan(/test generator options:/).length
9
239
  end
10
240
 
11
241
  def test_parse_ignore_invalid
15
245
 
16
246
    refute_match %r%^Usage: %, err
17
247
    assert_match %r%^invalid options: --bogus%, err
 
248
 
 
249
    assert_empty out
18
250
  end
19
251
 
20
252
  def test_parse_ignore_invalid_default
26
258
    assert_match %r%^invalid options: --bogus%, err
27
259
 
28
260
    assert_equal 'BLAH', @options.main_page
 
261
 
 
262
    assert_empty out
29
263
  end
30
264
 
31
265
  def test_parse_ignore_invalid_no
32
266
    out, err = capture_io do
33
267
      assert_raises SystemExit do
34
 
        @options.parse %w[--no-ignore-invalid --bogus]
 
268
        @options.parse %w[--no-ignore-invalid --bogus=arg --bobogus --visibility=extended]
35
269
      end
36
270
    end
37
271
 
38
272
    assert_match %r%^Usage: %, err
39
 
    assert_match %r%^invalid option: --bogus%, err
 
273
    assert_match %r%^invalid options: --bogus=arg, --bobogus, --visibility=extended%, err
 
274
 
 
275
    assert_empty out
40
276
  end
41
277
 
42
278
  def test_parse_main
50
286
    assert_equal 'MAIN', @options.main_page
51
287
  end
52
288
 
53
 
  def test_parse_dash_p
54
 
    out, err = capture_io do
55
 
      @options.parse %w[-p]
56
 
    end
57
 
 
58
 
    assert @options.pipe
59
 
    refute_match %r%^Usage: %, err
60
 
    refute_match %r%^invalid options%, err
61
 
  end
62
 
 
63
 
  def test_parse_dash_p_files
64
 
    out, err = capture_io do
65
 
      @options.parse %w[-p README]
66
 
    end
67
 
 
68
 
    refute @options.pipe
69
 
    refute_match %r%^Usage: %, err
70
 
    assert_match %r%^invalid options: -p .with files.%, err
 
289
  def test_parse_template
 
290
    out, err = capture_io do
 
291
      @options.parse %w[--template darkfish]
 
292
    end
 
293
 
 
294
    assert_empty out
 
295
    assert_empty err
 
296
 
 
297
    assert_equal 'darkfish', @options.template
 
298
 
 
299
    assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir
 
300
  end
 
301
 
 
302
  def test_parse_template_nonexistent
 
303
    out, err = capture_io do
 
304
      @options.parse %w[--template NONEXISTENT]
 
305
    end
 
306
 
 
307
    assert_empty out
 
308
    assert_equal "could not find template NONEXISTENT\n", err
 
309
 
 
310
    assert_equal 'darkfish', @options.template
 
311
    assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir
 
312
  end
 
313
 
 
314
  def test_parse_template_load_path
 
315
    orig_LOAD_PATH = $LOAD_PATH.dup
 
316
 
 
317
    template_dir = nil
 
318
 
 
319
    Dir.mktmpdir do |dir|
 
320
      $LOAD_PATH << dir
 
321
 
 
322
      template_dir = File.join dir, 'rdoc', 'generator', 'template', 'load_path'
 
323
 
 
324
      FileUtils.mkdir_p template_dir
 
325
 
 
326
      out, err = capture_io do
 
327
        @options.parse %w[--template load_path]
 
328
      end
 
329
 
 
330
      assert_empty out
 
331
      assert_empty err
 
332
    end
 
333
 
 
334
    assert_equal 'load_path',  @options.template
 
335
    assert_equal template_dir, @options.template_dir
 
336
  ensure
 
337
    $LOAD_PATH.replace orig_LOAD_PATH
 
338
  end
 
339
 
 
340
  def test_setup_generator
 
341
    test_generator = Class.new do
 
342
      def self.setup_options op
 
343
        @op = op
 
344
      end
 
345
 
 
346
      def self.op() @op end
 
347
    end
 
348
 
 
349
    RDoc::RDoc::GENERATORS['test'] = test_generator
 
350
 
 
351
    @options.setup_generator 'test'
 
352
 
 
353
    assert_equal test_generator, @options.generator
 
354
    assert_equal [test_generator], @options.generator_options
 
355
 
 
356
    assert_equal @options, test_generator.op
 
357
  ensure
 
358
    RDoc::RDoc::GENERATORS.delete 'test'
 
359
  end
 
360
 
 
361
  def test_setup_generator_no_option_parser
 
362
    test_generator = Class.new do
 
363
      def self.setup_options op
 
364
        op.option_parser.separator nil
 
365
        @op = op
 
366
      end
 
367
 
 
368
      def self.op() @op end
 
369
    end
 
370
 
 
371
    RDoc::RDoc::GENERATORS['test'] = test_generator
 
372
 
 
373
    @options.setup_generator 'test'
 
374
 
 
375
    assert_equal test_generator, @options.generator
 
376
    assert_equal [test_generator], @options.generator_options
 
377
 
 
378
    assert_equal @options, test_generator.op
 
379
  ensure
 
380
    RDoc::RDoc::GENERATORS.delete 'test'
 
381
  end
 
382
 
 
383
  def test_update_output_dir
 
384
    assert @options.update_output_dir
 
385
 
 
386
    @options.update_output_dir = false
 
387
 
 
388
    refute @options.update_output_dir
71
389
  end
72
390
 
73
391
end