diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-26 15:14:49 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-07-29 09:01:23 -0700 |
commit | aa97410b0a85cb4ceb956ab943b5eee92a128411 (patch) | |
tree | c3463f6004d4fe33887e34e9362cc067529700cb /spec/ruby/language | |
parent | c2428b8bf6f3646f575c21d0c89192d79130f7cc (diff) | |
download | ruby-aa97410b0a85cb4ceb956ab943b5eee92a128411.tar.gz |
Warn if using return at top-level with an argument
Fixes [Bug #14062]
Diffstat (limited to 'spec/ruby/language')
-rw-r--r-- | spec/ruby/language/return_spec.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb index 1af88c55cd..27729750f1 100644 --- a/spec/ruby/language/return_spec.rb +++ b/spec/ruby/language/return_spec.rb @@ -484,13 +484,26 @@ describe "The return keyword" do end describe "return with argument" do - # https://bugs.ruby-lang.org/issues/14062 - it "does not affect exit status" do - ruby_exe(<<-END_OF_CODE).should == "" - return 10 - END_OF_CODE + ruby_version_is ""..."2.7" do + it "does not affect exit status" do + ruby_exe(<<-END_OF_CODE).should == "" + return 10 + END_OF_CODE + + $?.exitstatus.should == 0 + end + end + + ruby_version_is "2.7" do + it "warns but does not affect exit status" do + ruby_exe(<<-END_OF_CODE).should == "-e: warning: argument of top-level return is ignored\n" + $stderr.reopen($stdout) + system(ENV['RUBY_EXE'], '-e', 'return 10') + exit($?.exitstatus) + END_OF_CODE - $?.exitstatus.should == 0 + $?.exitstatus.should == 0 + end end end end |