aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_argf.rb
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-18 07:28:24 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-18 07:28:24 +0000
commit6874320d20763fdc77d915aac71cfe7ecdd1a000 (patch)
tree198dfc6e89e2d4425febe7b4418d168f3dedf39e /test/ruby/test_argf.rb
parent58d694fcdb247ca3ba66e12eb0cae97a3dda4cea (diff)
downloadruby-6874320d20763fdc77d915aac71cfe7ecdd1a000.tar.gz
* test/ruby/test_argf.rb: support NO_SAFE_RENAME platforms.
* test/ruby/test_argf.rb: now tempfiles are binmode'ed to test tell/pos/etc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_argf.rb')
-rw-r--r--test/ruby/test_argf.rb36
1 files changed, 25 insertions, 11 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 7ab9b250df..82aaa41dca 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -7,14 +7,17 @@ require_relative 'envutil'
class TestArgf < Test::Unit::TestCase
def setup
@t1 = Tempfile.new("foo")
+ @t1.binmode
@t1.puts "1"
@t1.puts "2"
@t1.close
@t2 = Tempfile.new("bar")
+ @t2.binmode
@t2.puts "3"
@t2.puts "4"
@t2.close
@t3 = Tempfile.new("baz")
+ @t3.binmode
@t3.puts "5"
@t3.puts "6"
@t3.close
@@ -47,6 +50,10 @@ class TestArgf < Test::Unit::TestCase
f.close unless !f || f.closed?
end
+ def no_safe_rename
+ /cygwin|mswin|mingw|bccwin/ =~ RUBY_PLATFORM
+ end
+
def test_argf
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
a = ARGF
@@ -203,9 +210,15 @@ class TestArgf < Test::Unit::TestCase
w.puts " puts line.chomp + '.new'"
w.puts "end"
w.close
- assert_match(/Can't rename .* to .*: .*. skipping file/, e.read) #'
- assert_equal("", r.read)
- assert_equal("foo\nbar\nbaz\n", File.read(t.path))
+ if no_safe_rename
+ assert_equal("", e.read)
+ assert_equal("", r.read)
+ assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
+ else
+ assert_match(/Can't rename .* to .*: .*. skipping file/, e.read) #'
+ assert_equal("", r.read)
+ assert_equal("foo\nbar\nbaz\n", File.read(t.path))
+ end
end
end
@@ -218,9 +231,13 @@ class TestArgf < Test::Unit::TestCase
w.puts " puts line.chomp + '.new'"
w.puts "end"
w.close
- assert_equal("", e.read)
- assert_equal("", r.read)
- assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
+ if no_safe_rename
+ assert_match(/Can't do inplace edit without backup/, e.read) #'
+ else
+ assert_equal("", e.read)
+ assert_equal("", r.read)
+ assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
+ end
end
end
@@ -284,6 +301,7 @@ class TestArgf < Test::Unit::TestCase
def test_tell
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
begin
+ ARGF.binmode
loop do
p ARGF.tell
p ARGF.gets
@@ -642,13 +660,9 @@ class TestArgf < Test::Unit::TestCase
end
def test_binmode
- r = ""
- @tmps.each do |f|
- r << IO.read(f.path, mode:"rb")
- end
ruby('-e', "ARGF.binmode; STDOUT.binmode; puts ARGF.read", @t1.path, @t2.path, @t3.path) do |f|
f.binmode
- assert_equal(r, f.read)
+ assert_equal("1\n2\n3\n4\n5\n6\n", f.read)
end
end