|
1 |
| -require_relative '../spec_helper' |
| 1 | +require_relative "../spec_helper" |
2 | 2 |
|
3 |
| -describe "Magic comments" do |
| 3 | +describe "magic comments in ractors" do |
4 | 4 | ruby_version_is "3.0" do
|
5 |
| - it 'makes constants shareable between ractors' do |
6 |
| - -> { ruby_exe(fixture(__FILE__, 'shareable_constant_value_magic_comment.rb'), options: '-W0')}.should_not raise_error |
| 5 | + it "makes constants shareable between ractors" do |
| 6 | + out = ruby_exe(fixture(__FILE__, "shareable_constant_value_magic_comment.rb"), options: "-W0") |
| 7 | + out.should == "ractor" |
7 | 8 | end
|
8 | 9 |
|
9 |
| - it 'makes constants shareable between ractors' do |
10 |
| - a, b, c = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}") |
11 |
| - begin; |
| 10 | + it "makes constants shareable between ractors" do |
| 11 | + a, b, c = Class.new.class_eval(<<~RUBY, __FILE__, __LINE__ + 1) |
12 | 12 | # shareable_constant_value: experimental_everything
|
13 | 13 | A = [[1]]
|
14 | 14 | # shareable_constant_value: none
|
15 | 15 | B = [[2]]
|
16 | 16 | # shareable_constant_value: literal
|
17 |
| - C = [["shareable", "constant#{nil}"]] |
| 17 | + C = [["shareable", "constant#{self.class.name}"]] |
18 | 18 | [A, B, C]
|
19 |
| - end; |
| 19 | + RUBY |
20 | 20 | Ractor.shareable?(a).should == true
|
21 | 21 | Ractor.shareable?(b).should == false
|
22 | 22 | Ractor.shareable?(c).should == true
|
23 | 23 | end
|
24 | 24 |
|
25 |
| - it 'raises an error whenn shared constant is not a literal' do |
26 |
| - -> { Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}", /unshareable expression/) }.should raise_error |
27 |
| - begin; |
| 25 | + it "raises an error when shared constant is not a literal" do |
| 26 | + -> { Class.new.class_eval(<<~RUBY, __FILE__, __LINE__ + 1) }.should raise_error(Ractor::IsolationError, "cannot assign unshareable object to C") |
28 | 27 | # shareable_constant_value: literal
|
29 | 28 | C = ["Not " + "shareable"]
|
30 |
| - end; |
| 29 | + RUBY |
31 | 30 | end
|
32 | 31 | end
|
33 | 32 | end
|
0 commit comments