Skip to content

Commit 41e38e5

Browse files
committed
Remove aborts, make tests work on ruby trunk
1 parent 294fa04 commit 41e38e5

File tree

4 files changed

+82
-34
lines changed

4 files changed

+82
-34
lines changed

lib/rdoc/options.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class RDoc::Options
154154

155155
attr_reader :webcvs
156156

157-
def initialize(generators) # :nodoc:
157+
def initialize(generators = {}) # :nodoc:
158158
@op_dir = "doc"
159159
@op_name = nil
160160
@show_all = false
@@ -613,8 +613,8 @@ def check_diagram
613613

614614
def check_files
615615
@files.each do |f|
616-
stat = File.stat f rescue abort("File not found: #{f}")
617-
abort("File '#{f}' not readable") unless stat.readable?
616+
stat = File.stat f
617+
raise RDoc::Error, "file '#{f}' not readable" unless stat.readable?
618618
end
619619
end
620620

lib/rdoc/parser.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ class << self
5353
# "new_ext" will be parsed using the same parser as "old_ext"
5454

5555
def self.alias_extension(old_ext, new_ext)
56+
old_ext = old_ext.sub(/^\.(.*)/, '\1')
57+
new_ext = new_ext.sub(/^\.(.*)/, '\1')
58+
5659
parser = can_parse "xxx.#{old_ext}"
5760
return false unless parser
5861

59-
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser.last]
62+
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
6063

6164
true
6265
end

lib/rdoc/parser/ruby.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ def token
540540
begin
541541
tk = @OP.match(self)
542542
@space_seen = TkSPACE === tk
543-
rescue SyntaxError
544-
abort if @exception_on_syntax_error
543+
rescue SyntaxError => e
544+
raise RDoc::Error, "syntax error: #{e.message}" if
545+
@exception_on_syntax_error
546+
545547
tk = TkError.new(line_no, char_no)
546548
end
547549
end while @skip_space and TkSPACE === tk

test/test_rdoc_info_sections.rb

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,76 @@
1-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/'
21
require 'fileutils'
2+
require 'tempfile'
33
require 'test/unit'
4+
require 'tmpdir'
5+
46
require 'rdoc/generator/texinfo'
5-
require 'yaml'
67

78
# give us access to check this stuff before it's rendered
89
class RDoc::Generator::Texinfo; attr_reader :files, :classes; end
910
class RDoc::RDoc; attr_reader :options; attr_reader :gen; end
1011

1112
class TestRdocInfoSections < Test::Unit::TestCase
12-
OUTPUT_DIR = "/tmp/rdoc-#{$$}"
1313

1414
def setup
15-
# supress stdout
16-
$stdout = File.new('/dev/null','w')
17-
$stderr = File.new('/dev/null','w')
15+
@output_dir = File.join Dir.tmpdir, "test_rdoc_info_sections_#{$$}"
16+
@output_file = File.join @output_dir, 'rdoc.texinfo'
17+
18+
@input_file = Tempfile.new 'my_file.rb'
19+
20+
open @input_file.path, 'w' do |io|
21+
io.write TEST_DOC
22+
end
23+
24+
RDoc::Parser.alias_extension '.rb', File.extname(@input_file.path)
1825

1926
@rdoc = RDoc::RDoc.new
20-
@rdoc.document(['--fmt=texinfo',
21-
File.expand_path(File.dirname(__FILE__) + '/../lib/rdoc/generator/texinfo.rb'),
22-
File.expand_path(File.dirname(__FILE__) + '/../README.txt'),
23-
"--op=#{OUTPUT_DIR}"])
24-
@text = File.read(OUTPUT_DIR + '/rdoc.texinfo')
27+
@rdoc.document(['--fmt=texinfo', '--quiet', @input_file.path,
28+
"--op=#{@output_dir}"])
29+
30+
@text = File.read @output_file
2531
end
2632

2733
def teardown
28-
$stdout = STDOUT
29-
$stderr = STDERR
30-
FileUtils.rm_rf OUTPUT_DIR
34+
@input_file.close
35+
FileUtils.rm_rf @output_dir
3136
end
3237

3338
def test_output_exists
3439
assert ! @text.empty?
3540
end
3641

3742
def test_each_class_has_a_chapter
38-
assert_section "Class RDoc::Generator::Texinfo", '@chapter'
39-
assert_section "Class RDoc::Generator::TexinfoTemplate", '@chapter'
43+
assert_section "Class MyClass", '@chapter'
4044
end
4145

4246
def test_class_descriptions_are_given
43-
assert_match(/This generates .*Texinfo.* files for viewing with GNU Info or Emacs from .*RDoc.* extracted from Ruby source files/, @text.gsub("\n", ' '))
47+
assert_match(/Documentation for my class/, @text.gsub("\n", ' '))
4448
end
4549

4650
def test_included_modules_are_given
47-
assert_match(/Includes.* Generator::MarkUp/m, @text)
51+
assert_match(/Includes.* MyModule/m, @text)
4852
end
4953

5054
def test_class_methods_are_given
51-
assert_match(/new\(options\)/, @text)
55+
assert_match(/my_class_method\(my_first_argument\)/, @text)
5256
end
5357

5458
def test_classes_instance_methods_are_given
55-
assert_section 'Class RDoc::Generator::Texinfo#generate'
56-
assert_match(/generate\(toplevels\)/, @text)
59+
assert_section 'Class MyClass#my_method'
60+
assert_match(/my_method\(my_first_argument\)/, @text)
5761
end
5862

5963
def test_each_module_has_a_chapter
60-
assert_section "RDoc", '@chapter'
61-
assert_section "Generator", '@chapter'
64+
assert_section 'MyModule', '@chapter'
6265
end
6366

6467
def test_methods_are_shown_only_once
65-
methods = @rdoc.gen.classes.map { |c| c.methods.map{ |m| c.name + '#' + m.name } }.flatten
68+
methods = @rdoc.gen.classes.map do |c|
69+
c.methods.map do |m|
70+
c.name + '#' + m.name
71+
end
72+
end.flatten
73+
6674
assert_equal methods, methods.uniq
6775
end
6876

@@ -82,12 +90,47 @@ def test_methods_are_shown_only_once
8290
# def test_oh_yeah_dont_forget_files
8391
# end
8492

85-
private
8693
def assert_section(name, command = '@section')
8794
assert_match Regexp.new("^#{command}.*#{Regexp.escape name}"), @text, "Could not find a #{command} #{name}"
8895
end
8996

90-
# def puts(*args)
91-
# @real_stdout.puts(*args)
92-
# end
97+
TEST_DOC = <<-DOC
98+
##
99+
# Documentation for my module
100+
101+
module MyModule
102+
103+
##
104+
# Documentation for my included method
105+
106+
def my_included_method() end
107+
108+
end
109+
110+
##
111+
# Documentation for my class
112+
113+
class MyClass
114+
115+
include MyModule
116+
117+
##
118+
# Documentation for my constant
119+
120+
MY_CONSTANT = 'my value'
121+
122+
##
123+
# Documentation for my class method
124+
125+
def self.my_class_method(my_first_argument) end
126+
127+
##
128+
# Documentation for my method
129+
130+
def my_method(my_first_argument) end
131+
132+
end
133+
134+
DOC
135+
93136
end

0 commit comments

Comments
 (0)