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

« back to all changes in this revision

Viewing changes to test/rdoc/test_rdoc_rdoc.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'tempfile'
 
2
require 'tmpdir'
 
3
require 'rubygems'
 
4
require 'minitest/autorun'
 
5
require 'rdoc/rdoc'
 
6
 
 
7
class TestRDocRDoc < MiniTest::Unit::TestCase
 
8
 
 
9
  def setup
 
10
    @rdoc = RDoc::RDoc.new
 
11
    @tempfile = Tempfile.new 'test_rdoc_rdoc'
 
12
    @tempfile.binmode
 
13
  end
 
14
 
 
15
  def teardown
 
16
    @tempfile.close rescue nil # HACK for 1.8.6
 
17
  end
 
18
 
 
19
  def test_gather_files
 
20
    file = File.expand_path __FILE__
 
21
    assert_equal [file], @rdoc.gather_files([file, file])
 
22
  end
 
23
 
 
24
  def test_normalized_file_list
 
25
    files = @rdoc.normalized_file_list [__FILE__]
 
26
 
 
27
    files = files.map { |file| File.expand_path file }
 
28
 
 
29
    assert_equal [File.expand_path(__FILE__)], files
 
30
  end
 
31
 
 
32
  def test_normalized_file_list_not_modified
 
33
    files = [__FILE__]
 
34
 
 
35
    @rdoc.last_modified[__FILE__] = File.stat(__FILE__).mtime
 
36
 
 
37
    files = @rdoc.normalized_file_list [__FILE__]
 
38
 
 
39
    assert_empty files
 
40
  end
 
41
 
 
42
  def test_read_file_contents
 
43
    @tempfile.write "hi everybody"
 
44
    @tempfile.flush
 
45
 
 
46
    assert_equal "hi everybody", @rdoc.read_file_contents(@tempfile.path)
 
47
  end
 
48
 
 
49
  def test_read_file_contents_encoding
 
50
    skip "Encoding not implemented" unless defined? ::Encoding
 
51
 
 
52
    @tempfile.write "# coding: utf-8\nhi everybody"
 
53
    @tempfile.flush
 
54
 
 
55
    contents = @rdoc.read_file_contents @tempfile.path
 
56
    assert_equal "# coding: utf-8\nhi everybody", contents
 
57
    assert_equal Encoding::UTF_8, contents.encoding
 
58
  end
 
59
 
 
60
  def test_read_file_contents_encoding_fancy
 
61
    skip "Encoding not implemented" unless defined? ::Encoding
 
62
 
 
63
    @tempfile.write "# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody"
 
64
    @tempfile.flush
 
65
 
 
66
    contents = @rdoc.read_file_contents @tempfile.path
 
67
    assert_equal("# -*- coding: utf-8; fill-column: 74 -*-\nhi everybody",
 
68
                 contents)
 
69
    assert_equal Encoding::UTF_8, contents.encoding
 
70
  end
 
71
 
 
72
  def test_read_file_contents_encoding_with_signature
 
73
    skip "Encoding not implemented" unless defined? ::Encoding
 
74
 
 
75
    @tempfile.write "\xEF\xBB\xBF""hi everybody"
 
76
    @tempfile.flush
 
77
 
 
78
    bug3360 = '[ruby-dev:41452]'
 
79
    contents = @rdoc.read_file_contents @tempfile.path
 
80
    assert_equal "hi everybody", contents, bug3360
 
81
    assert_equal Encoding::UTF_8, contents.encoding, bug3360
 
82
  end
 
83
 
 
84
  def test_remove_unparsable
 
85
    file_list = %w[
 
86
      blah.class
 
87
      blah.eps
 
88
      blah.erb
 
89
      blah.scpt.txt
 
90
      blah.ttf
 
91
      blah.yml
 
92
    ]
 
93
 
 
94
    assert_empty @rdoc.remove_unparseable file_list
 
95
  end
 
96
 
 
97
  def test_setup_output_dir
 
98
    skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
 
99
 
 
100
    Dir.mktmpdir {|d|
 
101
      path = File.join(d, 'testdir')
 
102
 
 
103
      last = @rdoc.setup_output_dir path, false
 
104
 
 
105
      assert_empty last
 
106
 
 
107
      assert File.directory? path
 
108
    }
 
109
  end
 
110
 
 
111
  def test_setup_output_dir_exists
 
112
    skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
 
113
 
 
114
    Dir.mktmpdir {|path|
 
115
      open @rdoc.output_flag_file(path), 'w' do |io|
 
116
        io.puts Time.at 0
 
117
        io.puts "./lib/rdoc.rb\t#{Time.at 86400}"
 
118
      end
 
119
 
 
120
      last = @rdoc.setup_output_dir path, false
 
121
 
 
122
      assert_equal 1, last.size
 
123
      assert_equal Time.at(86400), last['./lib/rdoc.rb']
 
124
    }
 
125
  end
 
126
 
 
127
  def test_setup_output_dir_exists_empty_created_rid
 
128
    skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
 
129
 
 
130
    Dir.mktmpdir {|path|
 
131
      open @rdoc.output_flag_file(path), 'w' do end
 
132
 
 
133
      e = assert_raises RDoc::Error do
 
134
        @rdoc.setup_output_dir path, false
 
135
      end
 
136
 
 
137
      assert_match %r%Directory #{Regexp.escape path} already exists%, e.message
 
138
    }
 
139
  end
 
140
 
 
141
  def test_setup_output_dir_exists_file
 
142
    path = @tempfile.path
 
143
 
 
144
    e = assert_raises RDoc::Error do
 
145
      @rdoc.setup_output_dir path, false
 
146
    end
 
147
 
 
148
    assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
 
149
                 e.message)
 
150
  end
 
151
 
 
152
  def test_setup_output_dir_exists_not_rdoc
 
153
    skip "No Dir::mktmpdir, upgrade your ruby" unless Dir.respond_to? :mktmpdir
 
154
 
 
155
    Dir.mktmpdir do |dir|
 
156
      e = assert_raises RDoc::Error do
 
157
        @rdoc.setup_output_dir dir, false
 
158
      end
 
159
 
 
160
      assert_match %r%Directory #{Regexp.escape dir} already exists%, e.message
 
161
    end
 
162
  end
 
163
 
 
164
end
 
165