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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
require 'bundler/errors'
begin
gem 'test-unit'
rescue NoMethodError, Gem::LoadError, Bundler::GemfileNotFound
# for ruby tests
end
require 'test/unit'
require 'fileutils'
require 'pp'
require 'tempfile'
require 'tmpdir'
require 'stringio'
begin
require_relative '../../lib/helper'
rescue LoadError
end
if ENV['AUTOPKGTEST_TMP']
require 'rdoc'
else
require_relative '../../../lib/rdoc'
end
##
# RDoc::TestCase is an abstract TestCase to provide common setup and teardown
# across all RDoc tests. The test case uses test-unit, so all the assertions
# of test-unit may be used.
#
# The testcase provides the following:
#
# * A reset code-object tree
# * A reset markup preprocessor (RDoc::Markup::PreProcess)
# * The <code>@RM</code> alias of RDoc::Markup (for less typing)
# * <code>@pwd</code> containing the current working directory
# * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO
class RDoc::TestCase < Test::Unit::TestCase
##
# Abstract test-case setup
def setup
super
@orig_home = ENV["HOME"]
FileUtils.mkdir_p(@test_home = Dir.mktmpdir("test_rdoc_"))
ENV["HOME"] = @test_home
@top_level = nil
@RM = RDoc::Markup
@pwd = Dir.pwd
@options = RDoc::Options.new
@store = RDoc::Store.new(@options)
@rdoc = RDoc::RDoc.new
@rdoc.store = @store
@rdoc.options = @options
@rdoc.generator = Object.new
RDoc::Markup::PreProcess.reset
end
##
# Abstract test-case teardown
def teardown
ENV["HOME"] = @orig_home if defined?(@orig_home)
defined?(@test_home) and FileUtils.rm_rf @test_home
super
end
##
# Asserts +path+ is a file
def assert_file(path)
assert File.file?(path), "#{path} is not a file"
end
##
# Asserts +path+ is a directory
def assert_directory(path)
assert File.directory?(path), "#{path} is not a directory"
end
##
# Refutes +path+ exists
def refute_file(path)
refute File.exist?(path), "#{path} exists"
end
##
# Shortcut for RDoc::Markup::BlankLine.new
def blank_line
@RM::BlankLine.new
end
##
# Shortcut for RDoc::Markup::BlockQuote.new with +contents+
def block *contents
@RM::BlockQuote.new(*contents)
end
##
# Creates an RDoc::Comment with +text+ which was defined on +top_level+.
# By default the comment has the 'rdoc' format.
def comment(text, top_level = @top_level, language = nil)
comment = RDoc::Comment.new text, top_level, language
comment
end
##
# Shortcut for RDoc::Markup::Document.new with +contents+
def doc *contents
@RM::Document.new(*contents)
end
##
# Shortcut for RDoc::Markup::HardBreak.new
def hard_break
@RM::HardBreak.new
end
##
# Shortcut for RDoc::Markup::Heading.new with +level+ and +text+
def head(level, text)
@RM::Heading.new level, text
end
##
# Shortcut for RDoc::Markup::ListItem.new with +label+ and +parts+
def item label = nil, *parts
@RM::ListItem.new label, *parts
end
##
# Shortcut for RDoc::Markup::List.new with +type+ and +items+
def list type = nil, *items
@RM::List.new type, *items
end
##
# Enables pretty-print output
def mu_pp(obj) # :nodoc:
s = obj.pretty_inspect
s = RDoc::Encoding.change_encoding s, Encoding.default_external
s.chomp
end
##
# Shortcut for RDoc::Markup::Paragraph.new with +contents+
def para *a
@RM::Paragraph.new(*a)
end
##
# Shortcut for RDoc::Markup::Rule.new with +weight+
def rule(weight)
@RM::Rule.new weight
end
##
# Shortcut for RDoc::Markup::Raw.new with +contents+
def raw *contents
@RM::Raw.new(*contents)
end
##
# Creates a temporary directory changes the current directory to it for the
# duration of the block.
#
# Depends upon Dir.mktmpdir
def temp_dir
Dir.mktmpdir do |temp_dir|
Dir.chdir temp_dir do
yield temp_dir
end
end
end
##
# Shortcut for RDoc::Markup::Verbatim.new with +parts+
def verb *parts
@RM::Verbatim.new(*parts)
end
##
# run capture_io with setting $VERBOSE = true
def verbose_capture_output
capture_output do
begin
orig_verbose = $VERBOSE
$VERBOSE = true
yield
ensure
$VERBOSE = orig_verbose
end
end
end
end
|