summaryrefslogtreecommitdiff
path: root/test/fileutils
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-09 09:03:29 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-09 09:03:29 +0000
commit3ac1eeb34dd618592cfc86065e5a875f716645dc (patch)
treed6cd911b3aa4587e0c1b124604ccb90a470c0135 /test/fileutils
parent2afa9b88ca58f01da79efee709ec0b30d485b18a (diff)
* 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
Diffstat (limited to 'test/fileutils')
-rw-r--r--test/fileutils/test_fileutils.rb56
1 files changed, 27 insertions, 29 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 1c24a92..6e5ba24 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -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?