diff --git a/lib/run_loop/core_simulator.rb b/lib/run_loop/core_simulator.rb index 10d6dc3d..739fdf17 100644 --- a/lib/run_loop/core_simulator.rb +++ b/lib/run_loop/core_simulator.rb @@ -1,6 +1,9 @@ # A class to manage interactions with CoreSimulators. class RunLoop::CoreSimulator + require "run_loop/shell" + include RunLoop::Shell + # These options control various aspects of an app's life cycle on the iOS # Simulator. # @@ -568,7 +571,7 @@ def running_simulator_pid process_name = "MacOS/#{sim_name}" args = ["ps", "x", "-o", "pid,command"] - hash = xcrun.run_command_in_context(args) + hash = run_shell_command(args) exit_status = hash[:exit_status] if exit_status != 0 diff --git a/lib/run_loop/process_terminator.rb b/lib/run_loop/process_terminator.rb index 072bc6f0..35f57e3e 100644 --- a/lib/run_loop/process_terminator.rb +++ b/lib/run_loop/process_terminator.rb @@ -101,7 +101,7 @@ def process_alive? # @!visibility private # The details of the process reported by `ps`. def ps_details - `xcrun ps -p #{pid} -o pid,comm | grep #{pid}`.strip + `ps -p #{pid} -o pid,comm | grep #{pid}`.strip end # @!visibility private diff --git a/lib/run_loop/sim_control.rb b/lib/run_loop/sim_control.rb index 69244c15..bcfac7e6 100644 --- a/lib/run_loop/sim_control.rb +++ b/lib/run_loop/sim_control.rb @@ -153,10 +153,10 @@ def self.terminate_all_sims # @todo Maybe should try to send -TERM first and -KILL if TERM fails. # @todo Needs benchmarking. processes.each do |process_name| - descripts = `xcrun ps x -o pid,command | grep "#{process_name}" | grep -v grep`.strip.split("\n") + descripts = `ps x -o pid,command | grep "#{process_name}" | grep -v grep`.strip.split("\n") descripts.each do |process_desc| pid = process_desc.split(' ').first - Open3.popen3("xcrun kill -9 #{pid} && xcrun wait #{pid}") do |_, stdout, stderr, _| + Open3.popen3("kill -9 #{pid} && xcrun wait #{pid}") do |_, stdout, stderr, _| if ENV['DEBUG_UNIX_CALLS'] == '1' out = stdout.read.strip err = stderr.read.strip @@ -601,7 +601,7 @@ def enable_software_keyboard(device) # @return [String, nil] The pid as a String or nil if no process is found. def sim_pid process_name = "MacOS/#{sim_name}" - `xcrun ps x -o pid,command | grep "#{process_name}" | grep -v grep`.strip.split(' ').first + `ps x -o pid,command | grep "#{process_name}" | grep -v grep`.strip.split(' ').first end # @!visibility private diff --git a/spec/lib/core_simulator_spec.rb b/spec/lib/core_simulator_spec.rb index b2bda211..c3a2162f 100644 --- a/spec/lib/core_simulator_spec.rb +++ b/spec/lib/core_simulator_spec.rb @@ -322,7 +322,6 @@ end describe "#running_simulator_pid" do - let(:xcrun) { RunLoop::Xcrun.new } let(:hash) do { :exit_status => 0, @@ -330,13 +329,9 @@ } end - before do - allow(core_sim).to receive(:xcrun).and_return xcrun - end - it "xcrun exit status is non-zero" do hash[:exit_status] = 1 - expect(xcrun).to receive(:run_command_in_context).and_return(hash) + expect(core_sim).to receive(:run_shell_command).and_return hash expect do core_sim.send(:running_simulator_pid) @@ -346,7 +341,7 @@ describe "xcrun returns no :out" do it "out is nil" do hash[:out] = nil - expect(xcrun).to receive(:run_command_in_context).and_return(hash) + expect(core_sim).to receive(:run_shell_command).and_return hash expect do core_sim.send(:running_simulator_pid) @@ -355,7 +350,7 @@ it "out is empty string" do hash[:out] = "" - expect(xcrun).to receive(:run_command_in_context).and_return(hash) + expect(core_sim).to receive(:run_shell_command).and_return hash expect do core_sim.send(:running_simulator_pid) @@ -364,15 +359,15 @@ end it "no matching process is found" do - hash[:out] = -%Q{ + hash[:out] = + %Q{ 27247 login -pf moody 46238 tmate 31098 less run_loop.out 32976 vim lib/run_loop/xcrun.rb 7656 /bin/ps x -o pid,command } - expect(xcrun).to receive(:run_command_in_context).and_return(hash) + expect(core_sim).to receive(:run_shell_command).and_return hash expect(core_sim.send(:running_simulator_pid)).to be == nil end @@ -387,7 +382,7 @@ 7656 /MacOS/SillySim } expect(core_sim).to receive(:sim_name).and_return("SillySim") - expect(xcrun).to receive(:run_command_in_context).and_return(hash) + expect(core_sim).to receive(:run_shell_command).and_return hash expect(core_sim.send(:running_simulator_pid)).to be == 7656 end