From 1e145e11e4f5f03c301d1c001558f1d4572823c3 Mon Sep 17 00:00:00 2001 From: Josh Cheek Date: Mon, 1 Aug 2016 16:31:13 -0500 Subject: [PATCH] Child event stream uses file descriptor 4 Plus some other changes while exploring issues blocking #31 Current issue looks like the file isn't there when it goes to delete it. There's about a hundred, many are different, but all could feasible be caused by this --- .../evaluate_by_moving_files.rb | 18 ++++++++++-------- lib/seeing_is_believing/hard_core_ensure.rb | 2 +- spec/binary/marker_spec.rb | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/seeing_is_believing/evaluate_by_moving_files.rb b/lib/seeing_is_believing/evaluate_by_moving_files.rb index da5df8a..0e13634 100644 --- a/lib/seeing_is_believing/evaluate_by_moving_files.rb +++ b/lib/seeing_is_believing/evaluate_by_moving_files.rb @@ -75,9 +75,11 @@ def backup_existing_file end def set_back_to_initial_conditions - @was_backed_up ? - File.rename(backup_filename, filename) : + if @was_backed_up + File.rename(backup_filename, filename) + else File.delete(filename) + end end def write_program_to_file @@ -98,7 +100,7 @@ def evaluate_file # setup environment variables env = ENV.to_hash.merge 'SIB_VARIABLES.MARSHAL.B64' => [Marshal.dump( - event_stream_fd: child_eventstream.to_i, + event_stream_fd: 4, max_line_captures: max_line_captures, num_lines: program.lines.count, filename: filename @@ -106,11 +108,11 @@ def evaluate_file # evaluate the code in a child process opts = { - child_eventstream => child_eventstream, - in: child_stdin, - out: child_stdout, - err: child_stderr, - pgroup: true, # run it in its own process group so we can SIGINT the whole group + 4 => child_eventstream, + in: child_stdin, + out: child_stdout, + err: child_stderr, + pgroup: true, # run it in its own process group so we can SIGINT the whole group } child_pid = Kernel.spawn(env, *popen_args, opts) child_pgid = Process.getpgid(child_pid) diff --git a/lib/seeing_is_believing/hard_core_ensure.rb b/lib/seeing_is_believing/hard_core_ensure.rb index cfe8360..a4080f9 100644 --- a/lib/seeing_is_believing/hard_core_ensure.rb +++ b/lib/seeing_is_believing/hard_core_ensure.rb @@ -33,8 +33,8 @@ def invoke_code def invoke_ensure return if ensure_invoked - trap 'INT', old_handler self.ensure_invoked = true + trap 'INT', old_handler options[:ensure].call end diff --git a/spec/binary/marker_spec.rb b/spec/binary/marker_spec.rb index 801bfb3..014ed3e 100644 --- a/spec/binary/marker_spec.rb +++ b/spec/binary/marker_spec.rb @@ -47,9 +47,9 @@ def assert_parses(input, regex) it 'requires prefix and a regex' do described_class.new prefix: '', regex: // - expect { described_class.new }.to raise_error - expect { described_class.new prefix: '' }.to raise_error - expect { described_class.new regex: // }.to raise_error + expect { described_class.new }.to raise_error ArgumentError + expect { described_class.new prefix: '' }.to raise_error ArgumentError + expect { described_class.new regex: // }.to raise_error ArgumentError end it 'stores the prefix and a regex' do