зеркало из https://github.com/github/ruby.git
* test/fileutils/test_fileutils.rb
(TestFileUtils#assert_output_lines): New utility assertion method for testing verbose output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2afa9b88ca
Коммит
3ac1eeb34d
|
@ -1,3 +1,9 @@
|
|||
Tue Jul 9 17:58:26 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* test/fileutils/test_fileutils.rb
|
||||
(TestFileUtils#assert_output_lines): New utility assertion
|
||||
method for testing verbose output.
|
||||
|
||||
Tue Jul 9 17:43:57 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* test/test_tracer.rb: catch up recent rubygems changes.
|
||||
|
|
|
@ -9,6 +9,21 @@ require 'test/unit'
|
|||
class TestFileUtils < Test::Unit::TestCase
|
||||
TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
|
||||
include Test::Unit::FileAssertions
|
||||
|
||||
def assert_output_lines(expected, fu = self, message=nil)
|
||||
old = fu.instance_variable_get(:@fileutils_output)
|
||||
read, write = IO.pipe
|
||||
fu.instance_variable_set(:@fileutils_output, write)
|
||||
th = Thread.new { read.read }
|
||||
|
||||
yield
|
||||
|
||||
write.close
|
||||
lines = th.value.lines.map {|l| l.chomp }
|
||||
assert_equal(expected, lines)
|
||||
ensure
|
||||
fu.instance_variable_set(:@fileutils_output, old) if old
|
||||
end
|
||||
end
|
||||
|
||||
prevdir = Dir.pwd
|
||||
|
@ -1024,38 +1039,21 @@ class TestFileUtils
|
|||
def test_chmod_verbose
|
||||
check_singleton :chmod
|
||||
|
||||
stderr_back = $stderr
|
||||
read, $stderr = IO.pipe
|
||||
th = Thread.new { read.read }
|
||||
|
||||
touch 'tmp/a'
|
||||
chmod 0700, 'tmp/a', verbose: true
|
||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
||||
chmod 0500, 'tmp/a', verbose: true
|
||||
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
||||
|
||||
$stderr.close
|
||||
lines = th.value.lines.map {|l| l.chomp }
|
||||
assert_equal(["chmod 700 tmp/a", "chmod 500 tmp/a"], lines)
|
||||
ensure
|
||||
$stderr = stderr_back if stderr_back
|
||||
assert_output_lines(["chmod 700 tmp/a", "chmod 500 tmp/a"]) {
|
||||
touch 'tmp/a'
|
||||
chmod 0700, 'tmp/a', verbose: true
|
||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
||||
chmod 0500, 'tmp/a', verbose: true
|
||||
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
||||
}
|
||||
end if have_file_perm?
|
||||
|
||||
def test_s_chmod_verbose
|
||||
output_back = FileUtils.instance_variable_get(:@fileutils_output)
|
||||
read, write = IO.pipe
|
||||
FileUtils.instance_variable_set(:@fileutils_output, write)
|
||||
th = Thread.new { read.read }
|
||||
|
||||
touch 'tmp/a'
|
||||
FileUtils.chmod 0700, 'tmp/a', verbose: true
|
||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
||||
|
||||
write.close
|
||||
lines = th.value.lines.map {|l| l.chomp }
|
||||
assert_equal(["chmod 700 tmp/a"], lines)
|
||||
ensure
|
||||
FileUtils.instance_variable_set(:@fileutils_output, output_back) if output_back
|
||||
assert_output_lines(["chmod 700 tmp/a"], FileUtils) {
|
||||
touch 'tmp/a'
|
||||
FileUtils.chmod 0700, 'tmp/a', verbose: true
|
||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
||||
}
|
||||
end if have_file_perm?
|
||||
|
||||
# FIXME: How can I test this method?
|
||||
|
|
Загрузка…
Ссылка в новой задаче