Skip to content

Commit

Permalink
Apply r27290 from ruby trunk, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Apr 11, 2010
1 parent 1c59086 commit 1a0826b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -25,6 +25,7 @@ If you don't want to rebuild the rdoc for `gem server`, add --no-rdoc.
* 1 Bug Fixe
* Fixed loading of created.rid when regenerating documentation. Ruby bug
#3121 by Yusuke Endoh.
* Compare times as Integers as created.rid doesn't store fractional times.

=== 2.5.2 / 2010-04-09

Expand Down
29 changes: 17 additions & 12 deletions lib/rdoc/rdoc.rb
Expand Up @@ -37,6 +37,11 @@ class RDoc::RDoc

attr_accessor :generator

##
# Hash of files and their last modified times.

attr_reader :last_modified

##
# RDoc options

Expand Down Expand Up @@ -75,13 +80,13 @@ def self.current=(rdoc)
end

def initialize
@current = nil
@exclude = nil
@generator = nil
@last_created = {}
@old_siginfo = nil
@options = nil
@stats = nil
@current = nil
@exclude = nil
@generator = nil
@last_modified = {}
@old_siginfo = nil
@options = nil
@stats = nil
end

##
Expand Down Expand Up @@ -230,12 +235,12 @@ def normalized_file_list(relative_files, force_doc = false,

case type = stat.ftype
when "file" then
next if last_created = @last_created[rel_file_name] and
stat.mtime <= last_created
next if last_modified = @last_modified[rel_file_name] and
stat.mtime.to_i <= last_modified.to_i

if force_doc or RDoc::Parser.can_parse(rel_file_name) then
file_list << rel_file_name.sub(/^\.\//, '')
@last_created[rel_file_name] = stat.mtime
@last_modified[rel_file_name] = stat.mtime
end
when "directory" then
next if rel_file_name == "CVS" || rel_file_name == ".svn"
Expand Down Expand Up @@ -360,7 +365,7 @@ def document(argv)

@exclude = @options.exclude

@last_created = setup_output_dir @options.op_dir, @options.force_update
@last_modified = setup_output_dir @options.op_dir, @options.force_update

start_time = Time.now

Expand All @@ -386,7 +391,7 @@ def document(argv)
self.class.current = self

@generator.generate file_info
update_output_dir ".", start_time, @last_created
update_output_dir ".", start_time, @last_modified
ensure
self.class.current = nil
end
Expand Down
20 changes: 19 additions & 1 deletion test/test_rdoc_rdoc.rb
Expand Up @@ -12,14 +12,32 @@ def setup
end

def teardown
@tempfile.close
@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
Expand Down

0 comments on commit 1a0826b

Please sign in to comment.