From 260bf60e52ffdfa625be1153624b0d123fc305f8 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 25 Dec 2023 14:20:53 +1300 Subject: Correctly release the underlying file mapping. (#9340) * Avoiding using `Tempfile` which was retaining the file preventing it from unlinking. --- test/ruby/test_io_buffer.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index f7a6557a24..c4239101cf 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -519,23 +519,22 @@ class TestIOBuffer < Test::Unit::TestCase end def test_private - omit if RUBY_PLATFORM =~ /mswin|mingw/ + tmpdir = Dir.tmpdir + buffer_path = File.join(tmpdir, "buffer.txt") + File.write(buffer_path, "Hello World") - Tempfile.create("buffer.txt") do |io| - io.write("Hello World") - - buffer = IO::Buffer.map(io, nil, 0, IO::Buffer::PRIVATE) + File.open(buffer_path) do |file| + buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE) assert buffer.private? refute buffer.readonly? buffer.set_string("J") # It was not changed because the mapping was private: - io.seek(0) - assert_equal "Hello World", io.read + file.seek(0) + assert_equal "Hello World", file.read ensure buffer&.free - io&.close end end end -- cgit v1.2.3