diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2023-10-18 15:58:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2023-10-18 17:16:11 -0700 |
commit | 10272b27900dd30981f59fe5e2aed8e14b4f729f (patch) | |
tree | 2ee0811293b6b2e700203ac63fe91870b62341b7 | |
parent | 10c5063704c5bb086825c5e2e26ab7cacb7dbd7a (diff) | |
download | ruby-10272b27900dd30981f59fe5e2aed8e14b4f729f.tar.gz |
Use assert_separately to avoid defining `foo`
When we eval the iseqs generated by prism, they can have side effects
like defining methods. In this case, we were defining the method "foo",
but other tests were expecting that the foo method would _not_ be
defined.
-rw-r--r-- | test/ruby/test_compile_prism.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 7e39e9d266..ef14cbaf91 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -488,8 +488,30 @@ module Prism ############################################################################ def test_ScopeNode - test_prism_eval("a = 1; tap do; { a: }; end") - test_prism_eval("a = 1; def foo(a); a; end") + assert_separately(%w[], "#{<<-'begin;'}\n#{<<-'end;'}") + begin; + def compare_eval(source) + ruby_eval = RubyVM::InstructionSequence.compile(source).eval + prism_eval = RubyVM::InstructionSequence.compile_prism(source).eval + + assert_equal ruby_eval, prism_eval + end + + def test_prism_eval(source) + $VERBOSE, verbose_bak = nil, $VERBOSE + + begin + compare_eval(source) + + # Test "popped" functionality + compare_eval("#{source}; 1") + ensure + $VERBOSE = verbose_bak + end + end + test_prism_eval("a = 1; tap do; { a: }; end") + test_prism_eval("a = 1; def foo(a); a; end") + end; end private |