ruby/test/stringio/test_ractor.rb
Hiroshi SHIBATA 7d1190059f [ruby/stringio] Support Ractor#value
(https://github.com/ruby/stringio/pull/134)

from https://bugs.ruby-lang.org/issues/21262

We need to alias `Ractor#value` to `Ractor#take` for old versions of
Ruby.

---------

https://github.com/ruby/stringio/commit/9954dabd80

Co-authored-by: Koichi Sasada <ko1@atdot.net>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
2025-06-03 07:44:36 +00:00

28 lines
593 B
Ruby

# frozen_string_literal: true
require 'test/unit'
class TestStringIOInRactor < Test::Unit::TestCase
def setup
omit unless defined? Ractor
end
def test_ractor
assert_in_out_err([], <<-"end;", ["true"], [])
class Ractor
alias value take unless method_defined? :value # compat with Ruby 3.4 and olders
end
require "stringio"
$VERBOSE = nil
r = Ractor.new do
io = StringIO.new(+"")
io.puts "abc"
io.truncate(0)
io.puts "def"
"\0\0\0\0def\n" == io.string
end
puts r.value
end;
end
end