Repository navigation
mruby-exit: run the hooks left to mrb_close() before exiting from at_exit #7840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| require 'open3' | ||
|
|
||
| # The finalizers left to the exit run when the program ends, so these run | ||
| # the mruby command. | ||
| def finalizer_run(code) | ||
| out, err, stat = Open3.capture3(*cmd_list("mruby"), "-e", code) | ||
| [out, err, stat.exitstatus] | ||
| end | ||
|
|
||
| def finalizer_mruby? | ||
| File.exist?(cmd_bin("mruby")) | ||
| end | ||
|
|
||
| FINALIZER_LIVE = '$o = Object.new; ObjectSpace.define_finalizer($o, Proc.new { puts "fin" }); ' | ||
|
|
||
| assert('the finalizers of the objects still alive run at exit, after the at_exit blocks') do | ||
| skip "no mruby command" unless finalizer_mruby? | ||
| out, _, status = finalizer_run(FINALIZER_LIVE + 'at_exit { puts "at_exit" }') | ||
| assert_equal "at_exit\nfin\n", out | ||
| assert_equal 0, status | ||
| end | ||
|
|
||
| assert('the finalizers run at exit after an at_exit block that calls exit') do | ||
| skip "no mruby command" unless finalizer_mruby? | ||
| out, _, status = finalizer_run(FINALIZER_LIVE + 'at_exit { exit 3 }') | ||
| assert_equal "fin\n", out | ||
| assert_equal 3, status | ||
| end | ||
|
|
||
| assert('the finalizers run at exit after an at_exit block that raises') do | ||
| skip "no mruby command" unless finalizer_mruby? | ||
| out, err, status = finalizer_run(FINALIZER_LIVE + 'at_exit { raise "in handler" }') | ||
| assert_equal "fin\n", out | ||
| assert_true err.include?("in handler (RuntimeError)"), err | ||
| assert_equal 1, status | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip the finalizer bintest when the target binary lacks
at_exit.finalizer_mruby?checks only that themrubyexecutable exists. It does not check forat_exit. Neithermruby-objectspace-finalizernormruby-bin-mrubyrequiresmruby-exit, andat_exitis defined only bymruby-exit. A custom build that enables bintests and omitsmruby-exitruns this suite against a binary withoutat_exit. Each child script then fails before itsat_exitblock registers, so each case fails at least one assertion.Make the guard check the capability, or make the suite's binary include
mruby-exit. Keep all three cases enabled whenat_exitis available.