Skip to content

Commit

Permalink
Merge pull request #444 from calabash/release/2.1.1
Browse files Browse the repository at this point in the history
Release/2.1.1
  • Loading branch information
jmoody committed Apr 16, 2016
2 parents 814e61b + 2a08cc9 commit 5d5fa4e
Show file tree
Hide file tree
Showing 47 changed files with 1,924 additions and 554 deletions.
16 changes: 8 additions & 8 deletions .irbrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ puts ''
puts '# => Useful Methods <= #'
puts '> xcode => Xcode instance'
puts '> instruments => Instruments instance'
puts '> simcontrol => SimControl instance'
puts '> simctl => Simctl instance'
puts '> default_sim => Default simulator'
puts '> verbose => turn on DEBUG logging'
puts '> quiet => turn off DEBUG logging'
Expand All @@ -58,14 +58,14 @@ def instruments
@instruments ||= RunLoop::Instruments.new
end

def simcontrol
@simcontrol ||= RunLoop::SimControl.new
def simctl
@simctl ||= RunLoop::Simctl.new
end

def default_sim
@default_sim ||= lambda do
name = RunLoop::Core.default_simulator(xcode)
simcontrol.simulators.find do |sim|
simctl.simulators.find do |sim|
sim.instruments_identifier(xcode) == name
end
end.call
Expand Down Expand Up @@ -98,7 +98,7 @@ def create_simulator(n, options={})
end

def delete_simulator(name)
simcontrol.simulators.each do |simulator|
simctl.simulators.each do |simulator|
if simulator.name == name
puts "Deleting #{simulator}"
system('xcrun', 'simctl', 'delete', simulator.udid)
Expand All @@ -121,17 +121,17 @@ end
puts "XCUITest workspace = #{ENV["CBXWS"]}"

def xcuitest(bundle_id="com.apple.Preferences")
device = RunLoop::Device.detect_device({}, xcode, simcontrol, instruments)
device = RunLoop::Device.detect_device({}, xcode, simctl, instruments)
RunLoop::XCUITest.new(bundle_id, device)
end

def holmes(bundle_id="com.apple.Preferences")
device = RunLoop::Device.detect_device({}, xcode, simcontrol, instruments)
device = RunLoop::Device.detect_device({}, xcode, simctl, instruments)
options = {
:device => device.udid,
:xcuitest => true,
:xcode => xcode,
:simctl => simcontrol,
:simctl => simctl,
:instruments => instruments,
:app => bundle_id
}
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ script:
- scripts/ci/travis/install-gem-ci.rb
- scripts/ci/travis/rspec-ci.rb
- bundle exec rspec spec/integration/detect_simulators_spec.rb
- bundle exec rspec spec/integration/simctl_spec.rb

rvm:
- 2.0.0
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
## Change Log

### 2.1.1

* Expose color methods as public API #443
* Replace SimControl with Simctl #441
* Fixing syntax error in host script #438 @garyjohnson
* Improve retry strategy for app launch on simulators #436
* Fix instruments CLI rspec tests. #416
* CoreSim#launch: improve retrying #434
* Filter new Xcode 7.3 simctl stderr output from `simctl list devices`
#433
* Simctl is responsible for collecting devices on Xcode > 6
* CoreSim: patch retry on failed app launch 5300542
* Restore UIALogger flushing and ensure variables are substituted
properly. #430
* DotDir: symlink to current result #429
* Relax deprecation warnings @TeresaP, @jane-openreply, and others
* RESET\_BETWEEN\_SCENARIOS has stopped working #426 @ankurgamit

### 2.1.0

This release fixes a bug that might put the iOS Simulator into a bad state.
Expand Down
4 changes: 4 additions & 0 deletions lib/run_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def self.run(options={})
cloned_options[:sim_control] = options[:sim_control]
end

if options[:simctl]
cloned_options[:simctl] = options[:simctl]
end

Core.run_with_options(cloned_options)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/run_loop/cli/instruments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def launch
launch_options = {
:args => parse_app_launch_args(options),
:udid => detect_device_udid_from_options(options),
:bundle_dir_or_bundle_id => detect_bundle_id_or_bundle_path(options)
:app => detect_bundle_id_or_bundle_path(options)
}
run_loop = RunLoop.run(launch_options)
puts JSON.generate(run_loop)
Expand Down
18 changes: 9 additions & 9 deletions lib/run_loop/cli/simctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RunLoop
module CLI
class Simctl < Thor

attr_reader :sim_control
attr_reader :simctl

desc 'tail', 'Tail the log file of the booted simulator'
def tail
Expand All @@ -17,7 +17,7 @@ def tail
def tail_booted
device = booted_device
if device.nil?
version = Xcode.new.version
version = xcode.version
puts "No simulator for active Xcode (version #{version}) is booted."
else
log_file = device.simulator_log_file_path
Expand All @@ -30,7 +30,7 @@ def tail_booted
def booted
device = booted_device
if device.nil?
version = Xcode.new.version
version = xcode.version
puts "No simulator for active Xcode (version #{version}) is booted."
else
puts device
Expand Down Expand Up @@ -73,15 +73,15 @@ def doctor

no_commands do
def erase_and_launch_each_simulator
sim_control.simulators.each do |simulator|
simctl.simulators.each do |simulator|
RunLoop::CoreSimulator.erase(simulator)
launch_simulator(simulator, xcode)
end
end

def launch_simulator(simulator, xcode)
core_sim = RunLoop::CoreSimulator.new(simulator, nil,
{:xcode => xcode})
{:xcode => xcode})
core_sim.launch_simulator
end
end
Expand Down Expand Up @@ -114,8 +114,8 @@ def manage_processes
end

no_commands do
def sim_control
@sim_control ||= RunLoop::SimControl.new
def simctl
@simctl ||= RunLoop::Simctl.new
end

def xcode
Expand All @@ -127,7 +127,7 @@ def xcrun
end

def booted_device
sim_control.simulators.detect(nil) do |device|
simctl.simulators.detect(nil) do |device|
device.state == 'Booted'
end
end
Expand Down Expand Up @@ -192,7 +192,7 @@ def install
no_commands do
def expect_device(options)
device_from_options = options[:device]
simulators = sim_control.simulators
simulators = simctl.simulators
if device_from_options.nil?
default_name = RunLoop::Core.default_simulator
device = simulators.find do |sim|
Expand Down
62 changes: 48 additions & 14 deletions lib/run_loop/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def self.run_with_options(options)
self.prepare(options)

logger = options[:logger]
sim_control = options[:sim_control] || options[:simctl] || RunLoop::SimControl.new
simctl = options[:sim_control] || options[:simctl] || RunLoop::Simctl.new
xcode = options[:xcode] || RunLoop::Xcode.new
instruments = options[:instruments] || RunLoop::Instruments.new

# Find the Device under test, the App under test, UIA strategy, and reset options
device = RunLoop::Device.detect_device(options, xcode, sim_control, instruments)
device = RunLoop::Device.detect_device(options, xcode, simctl, instruments)
app_details = RunLoop::DetectAUT.detect_app_under_test(options)
uia_strategy = self.detect_uia_strategy(options, device, xcode)
reset_options = self.detect_reset_options(options)
Expand All @@ -89,11 +89,20 @@ def self.run_with_options(options)

script = File.join(results_dir, '_run_loop.js')

code = UIAScriptTemplate.new(SCRIPTS_PATH, options[:script]).result
code = code.gsub(/\$PATH/, results_dir)
code = code.gsub(/\$READ_SCRIPT_PATH/, READ_SCRIPT_PATH)
code = code.gsub(/\$TIMEOUT_SCRIPT_PATH/, TIMEOUT_SCRIPT_PATH)
code = code.gsub(/\$MODE/, 'FLUSH') unless options[:no_flush]
javascript = UIAScriptTemplate.new(SCRIPTS_PATH, options[:script]).result
UIAScriptTemplate.sub_path_var!(javascript, results_dir)
UIAScriptTemplate.sub_read_script_path_var!(javascript, READ_SCRIPT_PATH)
UIAScriptTemplate.sub_timeout_script_path_var!(javascript, TIMEOUT_SCRIPT_PATH)

# Using a :no_* option is confusing.
# TODO Replace :no_flush with :flush_uia_logs; it should default to true
if RunLoop::Environment.xtc?
UIAScriptTemplate.sub_mode_var!(javascript, "FLUSH") unless options[:no_flush]
else
if self.detect_flush_uia_log_option(options)
UIAScriptTemplate.sub_flush_uia_logs_var!(javascript, "FLUSH_LOGS")
end
end

repl_path = File.join(results_dir, 'repl-cmd.pipe')
FileUtils.rm_f(repl_path)
Expand All @@ -111,7 +120,7 @@ def self.run_with_options(options)
if include_calabash_script?(options)
file.puts IO.read(cal_script)
end
file.puts code
file.puts javascript
end

args = options.fetch(:args, [])
Expand All @@ -133,7 +142,7 @@ def self.run_with_options(options)
merged_options = options.merge(discovered_options)

if device.simulator?
self.prepare_simulator(app_details[:app], device, xcode, sim_control, reset_options)
self.prepare_simulator(app_details[:app], device, xcode, simctl, reset_options)
end

self.log_run_loop_options(merged_options, xcode)
Expand Down Expand Up @@ -543,9 +552,9 @@ def self.simulator_target?(run_options, sim_control=nil)
return false if value[DEVICE_UDID_REGEX, 0] != nil

# Check for named simulators and Xcode >= 7.0 simulators.
sim_control = run_options[:sim_control] || RunLoop::SimControl.new
xcode = sim_control.xcode
simulator = sim_control.simulators.find do |sim|
simctl = run_options[:sim_control] || run_options[:simctl] || RunLoop::Simctl.new
xcode = run_options[:xcode] || RunLoop::Xcode.new
simulator = simctl.simulators.find do |sim|
[
sim.instruments_identifier(xcode) == value,
sim.udid == value,
Expand All @@ -559,9 +568,9 @@ def self.simulator_target?(run_options, sim_control=nil)
# @deprecated 2.1.0
#
# Do not call this method.
def self.udid_and_bundle_for_launcher(device_target, options, sim_control=RunLoop::SimControl.new)
def self.udid_and_bundle_for_launcher(device_target, options, simctl=RunLoop::Simctl.new)
RunLoop.deprecated("2.1.0", "No replacement")
xcode = sim_control.xcode
xcode = RunLoop::Xcode.new

bundle_dir_or_bundle_id = options[:app] || RunLoop::Environment.bundle_id || RunLoop::Environment.path_to_app_bundle

Expand Down Expand Up @@ -661,6 +670,31 @@ def self.detect_uia_strategy(options, device, xcode)
strategy
end

# @!visibility private
#
# UIAutomation buffers log output in some very strange ways. RunLoop
# attempts to work around this buffering by forcing characters onto the
# UIALogger buffer. Once the buffer is full, UIAutomation will dump its
# contents. It is essential that the communication between UIAutomation
# and RunLoop be synchronized.
#
# Casual users should never set the :flush_uia_logs key; they should use the
# defaults.
#
# :no_flush is supported (for now) as alternative key.
#
# @param [Hash] options The launch options passed to .run_with_options
def self.detect_flush_uia_log_option(options)
if options.has_key?(:no_flush)
# Confusing.
# :no_flush == false means, flush the logs.
# :no_flush == true means, don't flush the logs.
return !options[:no_flush]
end

return options.fetch(:flush_uia_logs, true)
end

# @!visibility private
#
# @param [Hash] options The launch options passed to .run_with_options
Expand Down
Loading

0 comments on commit 5d5fa4e

Please sign in to comment.