* 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:
parent
2afa9b88ca
commit
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>
|
Tue Jul 9 17:43:57 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* test/test_tracer.rb: catch up recent rubygems changes.
|
* test/test_tracer.rb: catch up recent rubygems changes.
|
||||||
|
@ -9,6 +9,21 @@ require 'test/unit'
|
|||||||
class TestFileUtils < Test::Unit::TestCase
|
class TestFileUtils < Test::Unit::TestCase
|
||||||
TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
|
TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
|
||||||
include Test::Unit::FileAssertions
|
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
|
end
|
||||||
|
|
||||||
prevdir = Dir.pwd
|
prevdir = Dir.pwd
|
||||||
@ -1024,38 +1039,21 @@ class TestFileUtils
|
|||||||
def test_chmod_verbose
|
def test_chmod_verbose
|
||||||
check_singleton :chmod
|
check_singleton :chmod
|
||||||
|
|
||||||
stderr_back = $stderr
|
assert_output_lines(["chmod 700 tmp/a", "chmod 500 tmp/a"]) {
|
||||||
read, $stderr = IO.pipe
|
|
||||||
th = Thread.new { read.read }
|
|
||||||
|
|
||||||
touch 'tmp/a'
|
touch 'tmp/a'
|
||||||
chmod 0700, 'tmp/a', verbose: true
|
chmod 0700, 'tmp/a', verbose: true
|
||||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
||||||
chmod 0500, 'tmp/a', verbose: true
|
chmod 0500, 'tmp/a', verbose: true
|
||||||
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
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
|
|
||||||
end if have_file_perm?
|
end if have_file_perm?
|
||||||
|
|
||||||
def test_s_chmod_verbose
|
def test_s_chmod_verbose
|
||||||
output_back = FileUtils.instance_variable_get(:@fileutils_output)
|
assert_output_lines(["chmod 700 tmp/a"], FileUtils) {
|
||||||
read, write = IO.pipe
|
|
||||||
FileUtils.instance_variable_set(:@fileutils_output, write)
|
|
||||||
th = Thread.new { read.read }
|
|
||||||
|
|
||||||
touch 'tmp/a'
|
touch 'tmp/a'
|
||||||
FileUtils.chmod 0700, 'tmp/a', verbose: true
|
FileUtils.chmod 0700, 'tmp/a', verbose: true
|
||||||
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
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
|
|
||||||
end if have_file_perm?
|
end if have_file_perm?
|
||||||
|
|
||||||
# FIXME: How can I test this method?
|
# FIXME: How can I test this method?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user