Skip to content

Commit e69121b

Browse files
committed
Avoid terminating the process inside lib/ code
1 parent 8adb9a9 commit e69121b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

bin/rerun

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ end
1515

1616
exit if options.nil? or options[:cmd].nil? or options[:cmd].empty?
1717

18-
Rerun::Runner.keep_running(options[:cmd], options)
18+
begin
19+
Rerun::Runner.keep_running(options[:cmd], options)
20+
rescue Rerun::ExitException
21+
exit 0
22+
end

lib/rerun.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
require "rerun/glob"
1111

1212
module Rerun
13-
13+
# Raised when the runner wants to exit cleanly.
14+
# This allows tests to catch the exit instead of terminating the process.
15+
class ExitException < StandardError; end
1416
end
1517

lib/rerun/runner.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def start
160160
say "Rerun (#{$PID}) running #{app_name} (#{@pid})"
161161
rescue => e
162162
puts "#{e.class}: #{e.message}"
163-
exit
163+
raise ExitException
164164
end
165165

166166
status_thread = Process.detach(@pid) # so if the child exits, it dies
@@ -235,7 +235,7 @@ def change_message(changes)
235235
def die
236236
#stop_keypress_thread # don't do this since we're probably *in* the keypress thread
237237
stop # stop the child process if it exists
238-
exit 0 # todo: status code param
238+
raise ExitException # todo: status code param
239239
end
240240

241241
def join

0 commit comments

Comments
 (0)