From ce3ca270a5433dc1f252c49ba2905e87f2ab2a92 Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 15 Aug 2013 12:38:02 +0000 Subject: [PATCH] * test/ruby/test_file.rb (TestFile#test_truncate_size): test for above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 3 +++ test/ruby/test_file.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9310cc975d..08f2a63ee5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,9 @@ Thu Aug 15 20:51:29 2013 NAKAMURA Usaku * file.c (rb_file_truncate): use above function. + * test/ruby/test_file.rb (TestFile#test_truncate_size): test for + above changes. + Thu Aug 15 18:39:31 2013 NAKAMURA Usaku * win32/win32.c (clock_gettime): improve precision when freq is less diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 528193dabb..50f101867a 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'tempfile' +require "thread" require_relative 'envutil' require_relative 'ut_eof' @@ -118,6 +119,31 @@ class TestFile < Test::Unit::TestCase } end + def test_truncate_size + Tempfile.create("test-truncate") do |f| + q1 = Queue.new + q2 = Queue.new + + Thread.new do + data = '' + 64.times do |i| + data << i.to_s + f.rewind + f.print data + f.truncate(data.bytesize) + q1.push data.bytesize + q2.pop + end + q1.push nil + end + + while size = q1.pop + assert_equal size, File.size(f.path) + q2.push true + end + end + end + def test_read_all_extended_file [nil, {:textmode=>true}, {:binmode=>true}].each do |mode| Tempfile.create("test-extended-file", mode) {|f|