Skip to content

Commit

Permalink
Added dedicated helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 23, 2020
1 parent 7a09414 commit e70206f
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions test/ruby/test_parse.rb
Expand Up @@ -1174,14 +1174,32 @@ def test_void_value_in_command_rhs
assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
end

def eval_separately(code)
Class.new.class_eval(code)
end

def assert_ractor_error(message, code)
assert_raise_with_message(Ractor::Error, message) do
eval_separately(code)
end
end

def assert_ractor_shareable(obj)
assert Ractor.shareable?(obj), ->{"Expected #{mu_pp(obj)} to be ractor shareable"}
end

def assert_not_ractor_shareable(obj)
assert !Ractor.shareable?(obj), ->{"Expected #{mu_pp(obj)} not to be ractor shareable"}
end

def test_shareable_constant_value
assert_warning(/invalid value/) do
assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true)
end
assert_warning(/ignored/) do
assert_valid_syntax("nil # shareable_constant_value: true", verbose: true)
end
a, b, c = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
a, b, c = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: experimental_everything
A = [[1]]
Expand All @@ -1193,12 +1211,13 @@ def test_shareable_constant_value
[A, B, C]
end;
assert_send([Ractor, :shareable?, a])
assert_not_send([Ractor, :shareable?, b])
assert_send([Ractor, :shareable?, c])
assert_ractor_shareable(a)
assert_not_ractor_shareable(b)
assert_ractor_shareable(c)
assert_equal([1], a[0])
assert_send([Ractor, :shareable?, a[0]])
a, b = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
assert_ractor_shareable(a[0])

a, b = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: none
class X
Expand All @@ -1208,18 +1227,16 @@ class X
B = []
[X::A, B]
end;
assert_send([Ractor, :shareable?, a])
assert_not_send([Ractor, :shareable?, b])
assert_ractor_shareable(a)
assert_not_ractor_shareable(b)
assert_equal([1], a[0])
assert_send([Ractor, :shareable?, a[0]])
assert_ractor_shareable(a[0])

assert_raise_with_message(Ractor::Error, /unshareable/) do
Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: literal
C = ["Not " + "shareable"]
end;
end
assert_ractor_error(/unshareable/, "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: literal
C = ["Not " + "shareable"]
end;
end

=begin
Expand Down

0 comments on commit e70206f

Please sign in to comment.