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
|
require 'tempfile'
require 'tmpdir'
require 'rubygems'
require 'minitest/autorun'
require 'rdoc/rdoc'
class TestRDocRDoc < MiniTest::Unit::TestCase
def setup
@rdoc = RDoc::RDoc.new
@tempfile = Tempfile.new 'test_rdoc_rdoc'
end
def teardown
@tempfile.close rescue nil # HACK for 1.8.6
end
def test_gather_files
file = File.expand_path __FILE__
assert_equal [file], @rdoc.gather_files([file, file])
end
def test_normalized_file_list
files = @rdoc.normalized_file_list [__FILE__]
files = files.map { |file| File.expand_path file }
assert_equal [File.expand_path(__FILE__)], files
end
def test_normalized_file_list_not_modified
files = [__FILE__]
@rdoc.last_modified[__FILE__] = File.stat(__FILE__).mtime
files = @rdoc.normalized_file_list [__FILE__]
assert_empty files
end
def test_read_file_contents
@tempfile.write "hi everybody"
@tempfile.flush
assert_equal "hi everybody", @rdoc.read_file_contents(@tempfile.path)
end
def test_read_file_contents_encoding
skip "Encoding not implemented" unless defined? ::Encoding
@tempfile.write "# coding: utf-8\nhi everybody"
@tempfile.flush
contents = @rdoc.read_file_contents @tempfile.path
assert_equal "# coding: utf-8\nhi everybody", contents
assert_equal Encoding::UTF_8, contents.encoding
end
def test_read_file_contents_encoding_fancy
skip "Encoding not implemented" unless defined? ::Encoding
@tempfile.write "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody"
@tempfile.flush
contents = @rdoc.read_file_contents @tempfile.path
assert_equal("# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody",
contents)
assert_equal Encoding::UTF_8, contents.encoding
end
def test_remove_unparsable
file_list = %w[
blah.class
blah.eps
blah.erb
blah.scpt.txt
blah.ttf
blah.yml
]
assert_empty @rdoc.remove_unparseable file_list
end
def test_setup_output_dir
path = @tempfile.path
@tempfile.unlink
last = @rdoc.setup_output_dir path, false
assert_empty last
assert File.directory? path
ensure
FileUtils.rm_f path
end
def test_setup_output_dir_exists
path = @tempfile.path
@tempfile.unlink
FileUtils.mkdir_p path
open @rdoc.output_flag_file(path), 'w' do |io|
io.puts Time.at 0
io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
end
last = @rdoc.setup_output_dir path, false
assert_equal 1, last.size
assert_equal Time.at(86400), last['./lib/rdoc.rb']
ensure
FileUtils.rm_f path
end
def test_setup_output_dir_exists_empty_created_rid
path = @tempfile.path
@tempfile.unlink
FileUtils.mkdir_p path
open @rdoc.output_flag_file(path), 'w' do end
e = assert_raises RDoc::Error do
@rdoc.setup_output_dir path, false
end
assert_match %r%Directory #{Regexp.escape path} already exists%, e.message
ensure
FileUtils.rm_f path
end
def test_setup_output_dir_exists_file
path = @tempfile.path
e = assert_raises RDoc::Error do
@rdoc.setup_output_dir path, false
end
assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
e.message)
end
def test_setup_output_dir_exists_not_rdoc
skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
Dir.mktmpdir do |dir|
e = assert_raises RDoc::Error do
@rdoc.setup_output_dir dir, false
end
assert_match %r%Directory #{Regexp.escape dir} already exists%, e.message
end
end
end
|