2
2
require 'minitest/autorun'
3
3
require 'rdoc/options'
5
8
class TestRDocOptions < MiniTest::Unit::TestCase
8
11
@options = RDoc::Options.new
12
@generators = RDoc::RDoc::GENERATORS.dup
16
RDoc::RDoc::GENERATORS.replace @generators
20
skip "assumes UNIX permission model" if /mswin|mingw/ =~ RUBY_PLATFORM
21
out, err = capture_io do
24
FileUtils.touch 'unreadable'
25
FileUtils.chmod 0, 'unreadable'
27
@options.files = %w[nonexistent unreadable]
34
assert_empty @options.files
38
expected = <<-EXPECTED
39
file 'nonexistent' not found
40
file 'unreadable' not readable
43
assert_equal expected, err
46
def test_dry_run_default
47
refute @options.dry_run
50
def test_encoding_default
51
skip "Encoding not implemented" unless Object.const_defined? :Encoding
53
assert_equal Encoding.default_external, @options.encoding
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
62
expected = <<-EXPECTED.chomp
63
darkfish - HTML generator, written by Michael Granger
64
ri - creates ri data files
67
assert_equal expected, @options.generator_descriptions
70
def test_parse_coverage
71
@options.parse %w[--dcov]
73
assert @options.coverage_report
74
assert @options.force_update
77
def test_parse_coverage_no
78
@options.parse %w[--no-dcov]
80
refute @options.coverage_report
83
def test_parse_coverage_level_1
84
@options.parse %w[--dcov=1]
86
assert_equal 1, @options.coverage_report
90
out, err = capture_io do
95
refute_match %r%^Usage: %, err
96
refute_match %r%^invalid options%, err
101
def test_parse_dash_p_files
102
out, err = capture_io do
103
@options.parse ['-p', File.expand_path(__FILE__)]
107
refute_match %r%^Usage: %, err
108
assert_match %r%^invalid options: -p .with files.%, err
113
def test_parse_default
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
121
def test_parse_deprecated
122
dep_hash = RDoc::Options::DEPRECATED
123
options = dep_hash.keys.sort
125
out, err = capture_io do
126
@options.parse options
129
dep_hash.each_pair do |opt, message|
130
assert_match %r%.*#{opt}.+#{message}%, err
136
def test_parse_dry_run
137
@options.parse %w[--dry-run]
139
assert @options.dry_run
142
def test_parse_encoding
143
skip "Encoding not implemented" unless Object.const_defined? :Encoding
145
@options.parse %w[--encoding Big5]
147
assert_equal Encoding::Big5, @options.encoding
148
assert_equal 'Big5', @options.charset
151
def test_parse_encoding_invalid
152
skip "Encoding not implemented" unless Object.const_defined? :Encoding
154
out, err = capture_io do
155
@options.parse %w[--encoding invalid]
158
assert_match %r%^invalid options: --encoding invalid%, err
163
def test_parse_formatter
164
e = assert_raises OptionParser::InvalidOption do
165
@options.parse %w[--format darkfish --format ri]
168
assert_equal 'invalid option: --format generator already set to darkfish',
172
def test_parse_formatter_ri
173
e = assert_raises OptionParser::InvalidOption do
174
@options.parse %w[--format darkfish --ri]
177
assert_equal 'invalid option: --ri generator already set to darkfish',
180
@options = RDoc::Options.new
182
e = assert_raises OptionParser::InvalidOption do
183
@options.parse %w[--format darkfish -r]
186
assert_equal 'invalid option: -r generator already set to darkfish',
190
def test_parse_formatter_ri_site
191
e = assert_raises OptionParser::InvalidOption do
192
@options.parse %w[--format darkfish --ri-site]
195
assert_equal 'invalid option: --ri-site generator already set to darkfish',
198
@options = RDoc::Options.new
200
e = assert_raises OptionParser::InvalidOption do
201
@options.parse %w[--format darkfish -R]
204
assert_equal 'invalid option: -R generator already set to darkfish',
211
@options.parse %w[--help]
216
assert_equal 1, out.scan(/HTML generator options:/).length
217
assert_equal 1, out.scan(/ri generator options:/). length
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
225
op.separator 'test generator options:'
231
@options.parse %w[--help]
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
11
241
def test_parse_ignore_invalid
50
286
assert_equal 'MAIN', @options.main_page
54
out, err = capture_io do
59
refute_match %r%^Usage: %, err
60
refute_match %r%^invalid options%, err
63
def test_parse_dash_p_files
64
out, err = capture_io do
65
@options.parse %w[-p README]
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]
297
assert_equal 'darkfish', @options.template
299
assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir
302
def test_parse_template_nonexistent
303
out, err = capture_io do
304
@options.parse %w[--template NONEXISTENT]
308
assert_equal "could not find template NONEXISTENT\n", err
310
assert_equal 'darkfish', @options.template
311
assert_match %r%rdoc/generator/template/darkfish$%, @options.template_dir
314
def test_parse_template_load_path
315
orig_LOAD_PATH = $LOAD_PATH.dup
319
Dir.mktmpdir do |dir|
322
template_dir = File.join dir, 'rdoc', 'generator', 'template', 'load_path'
324
FileUtils.mkdir_p template_dir
326
out, err = capture_io do
327
@options.parse %w[--template load_path]
334
assert_equal 'load_path', @options.template
335
assert_equal template_dir, @options.template_dir
337
$LOAD_PATH.replace orig_LOAD_PATH
340
def test_setup_generator
341
test_generator = Class.new do
342
def self.setup_options op
346
def self.op() @op end
349
RDoc::RDoc::GENERATORS['test'] = test_generator
351
@options.setup_generator 'test'
353
assert_equal test_generator, @options.generator
354
assert_equal [test_generator], @options.generator_options
356
assert_equal @options, test_generator.op
358
RDoc::RDoc::GENERATORS.delete 'test'
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
368
def self.op() @op end
371
RDoc::RDoc::GENERATORS['test'] = test_generator
373
@options.setup_generator 'test'
375
assert_equal test_generator, @options.generator
376
assert_equal [test_generator], @options.generator_options
378
assert_equal @options, test_generator.op
380
RDoc::RDoc::GENERATORS.delete 'test'
383
def test_update_output_dir
384
assert @options.update_output_dir
386
@options.update_output_dir = false
388
refute @options.update_output_dir