Skip to content

Commit

Permalink
+ Optionally allow autorun exit hook to remain active in forked child…
Browse files Browse the repository at this point in the history
…. (casperisfine)

[git-p4: depot-paths = "//src/minitest/dev/": change = 13908]
  • Loading branch information
zenspider committed Sep 6, 2023
1 parent ed88d19 commit 780dc15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def self.cattr_accessor name # :nodoc:
cattr_accessor :info_signal
self.info_signal = "INFO"

cattr_accessor :allow_fork
self.allow_fork = false

##
# Registers Minitest to run at process exit

Expand All @@ -75,7 +78,7 @@ def self.autorun

pid = Process.pid
at_exit {
next if Process.pid != pid
next if !Minitest.allow_fork && Process.pid != pid
@@after_run.reverse_each(&:call)
exit exit_code || false
}
Expand Down
10 changes: 10 additions & 0 deletions test/minitest/test_minitest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,16 @@ def test_autorun_does_not_affect_fork_exit_status
Process.waitpid(fork { exit 42 })
assert_equal 42, $?.exitstatus
end

def test_autorun_optionally_can_affect_fork_exit_status
@assertion_count = 0
skip "windows doesn't have fork" unless Process.respond_to?(:fork)
Minitest.allow_fork = true
Process.waitpid(fork { exit 42 })
refute_equal 42, $?.exitstatus
ensure
Minitest.allow_fork = false
end
end

class TestMinitestGuard < Minitest::Test
Expand Down

0 comments on commit 780dc15

Please sign in to comment.