scan 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fa3eb576fcee514a38f281dfe851fa5263fa764
4
- data.tar.gz: 64e1862711e7b2add328d938706b0d92655554d9
3
+ metadata.gz: fd24b832b988c2eb8af64873b97f1aafcfe192f7
4
+ data.tar.gz: b2f274327a88c3ed46323c4f4eb093d2d99a6ce7
5
5
  SHA512:
6
- metadata.gz: 625c97a63e9920277284005a3c74fe72749aead9e3100eb9c186f8c63a08852108d7071395dcb23279b00a94f698870dc6dfcefe7099154b4d9aee0b88540cdd
7
- data.tar.gz: 9158dafa5f916f779d23acc7113c31f82a8c4d59a3e5872593c4536a354ef2b7a2adfc4d3248fec64c7345e80bd7b320960762eb90b75a63c902a9c34211a2b8
6
+ metadata.gz: 6d4ae3770b16d96aa13dcba825f567201e87b9ee04f48612a2d4312e66898c904d0ba8f041b7618386261ef233774cdb949cffece8dc5e7e03fbf1e5bfd6a950
7
+ data.tar.gz: e1d38725fb574a9c7052295219e3e0ddb12a269af384b48e3b72521b77b2e618c0de05882746e8b17a7377709f04fdbf71c254ce71f0497ce0605a1bed24695d
@@ -20,8 +20,8 @@ module Scan
20
20
 
21
21
  Scan.project.select_scheme
22
22
 
23
- default_device_ios if Scan.project.ios?
24
- default_device_tvos if Scan.project.tvos?
23
+ detect_simulator_ios if Scan.project.ios?
24
+ detect_simulator_tvos if Scan.project.tvos?
25
25
  detect_destination
26
26
 
27
27
  default_derived_data
@@ -39,103 +39,123 @@ module Scan
39
39
  Scan.config[:derived_data_path] = default_path
40
40
  end
41
41
 
42
- def self.filter_simulators(simulators, deployment_target)
43
- # Filter out any simulators that are not the same major and minor version of our deployment target
42
+ def self.filter_simulators(simulators, operator = :greater_than_or_equal, deployment_target)
44
43
  deployment_target_version = Gem::Version.new(deployment_target)
45
44
  simulators.select do |s|
46
- sim_version = Gem::Version.new(s.ios_version)
47
- (sim_version >= deployment_target_version)
48
- end
49
- end
50
-
51
- def self.default_device_ios
52
- devices = Scan.config[:devices] || Array(Scan.config[:device]) # important to use Array(nil) for when the value is nil
53
- found_devices = []
54
- xcode_target = Scan.project.build_settings(key: "IPHONEOS_DEPLOYMENT_TARGET")
55
-
56
- if devices.any?
57
- # Optionally, we only do this if the user specified a custom device or an array of devices
58
- devices.each do |device|
59
- lookup_device = device.to_s.strip
60
- has_version = lookup_device.include?(xcode_target) || lookup_device.include?('(')
61
- lookup_device = lookup_device.tr('()', '') # Remove parenthesis
62
- # Default to Xcode target version if no device version is specified.
63
- lookup_device = lookup_device + " " + xcode_target unless has_version
64
-
65
- found = FastlaneCore::Simulator.all.detect do |d|
66
- (d.name + " " + d.ios_version).include? lookup_device
67
- end
68
-
69
- if found
70
- found_devices.push(found)
71
- else
72
- UI.error("Ignoring '#{device}', couldn't find matching simulator")
73
- end
74
- end
75
-
76
- if found_devices.any?
77
- Scan.devices = found_devices
78
- return
45
+ sim_version = Gem::Version.new(s.os_version)
46
+ if operator == :greater_than_or_equal
47
+ sim_version >= deployment_target_version
48
+ elsif operator == :equal
49
+ sim_version == deployment_target_version
79
50
  else
80
- UI.error("Couldn't find any matching simulators for '#{devices}' - falling back to default simulator")
51
+ false # this will show an error message in the detect_simulator method
81
52
  end
82
53
  end
54
+ end
83
55
 
84
- sims = FastlaneCore::Simulator.all
85
- sims = filter_simulators(sims, xcode_target)
56
+ def self.regular_expression_for_split_on_whitespace_followed_by_parenthesized_version
57
+ # %r{
58
+ # \s # a whitespace character
59
+ # (?= # followed by -- using lookahead
60
+ # \( # open parenthesis
61
+ # [\d\.]+ # our version -- one or more digits or full stops
62
+ # \) # close parenthesis
63
+ # $ # end of line
64
+ # ) # end of lookahead
65
+ # }
66
+ /\s(?=\([\d\.]+\)$)/
67
+ end
86
68
 
87
- # An iPhone 5s is reasonable small and useful for tests
88
- found = sims.detect { |d| d.name == "iPhone 5s" }
89
- found ||= sims.first # anything is better than nothing
69
+ def self.detect_simulator_ios
70
+ # An iPhone 5s is a reasonably small and useful default for tests
71
+ detect_simulator('iOS', 'IPHONEOS_DEPLOYMENT_TARGET', 'iPhone 5s', nil)
72
+ end
90
73
 
91
- if found
92
- Scan.devices = [found]
93
- else
94
- UI.user_error!("No simulators found on local machine")
95
- end
74
+ def self.detect_simulator_tvos
75
+ detect_simulator('tvOS', 'TVOS_DEPLOYMENT_TARGET', 'Apple TV 1080p', 'TV')
96
76
  end
97
77
 
98
- def self.default_device_tvos
78
+ def self.detect_simulator(requested_os_type, deployment_target_key, default_device_name, simulator_type_descriptor)
79
+ require 'set'
99
80
  devices = Scan.config[:devices] || Array(Scan.config[:device]) # important to use Array(nil) for when the value is nil
100
- found_devices = []
101
81
 
102
- if devices.any?
103
- # Optionally, we only do this if the user specified a custom device or an array of devices
104
- devices.each do |device|
105
- lookup_device = device.to_s.strip.tr('()', '') # Remove parenthesis
82
+ deployment_target_version = Scan.project.build_settings(key: deployment_target_key)
106
83
 
107
- found = FastlaneCore::SimulatorTV.all.detect do |d|
108
- (d.name + " " + d.os_version).include? lookup_device
84
+ simulators = filter_simulators(
85
+ FastlaneCore::DeviceManager.simulators(requested_os_type).tap do |array|
86
+ if array.empty?
87
+ UI.user_error!(['No', simulator_type_descriptor, 'simulators found on local machine'].reject(&:nil?).join(' '))
109
88
  end
89
+ end,
90
+ :greater_than_or_equal,
91
+ deployment_target_version
92
+ ).tap do |sims|
93
+ if sims.empty?
94
+ UI.error("No simulators found that are greater than or equal to the version of deployment target (#{deployment_target_version})")
95
+ end
96
+ end
110
97
 
111
- if found
112
- found_devices.push(found)
113
- else
114
- UI.error("Ignoring '#{device}', couldn't find matching simulator")
98
+ # At this point we have all simulators for the given deployment target (or higher)
99
+
100
+ # We create 2 lambdas, which we iterate over later on
101
+ # If the first lambda `matches` found a simulator to use
102
+ # we'll never call the second one
103
+
104
+ matches = lambda do
105
+ set_of_simulators = devices.inject(
106
+ Set.new # of simulators
107
+ ) do |set, device_string|
108
+ pieces = device_string.split(regular_expression_for_split_on_whitespace_followed_by_parenthesized_version)
109
+
110
+ selector = ->(sim) { pieces.count > 0 && sim.name == pieces.first }
111
+
112
+ set + (
113
+ if pieces.count == 0
114
+ [] # empty array
115
+ elsif pieces.count == 1
116
+ simulators
117
+ .select(&selector)
118
+ .reverse # more efficient, because `simctl` prints higher versions first
119
+ .sort_by! { |sim| Gem::Version.new(sim.os_version) }
120
+ .pop(1)
121
+ else # pieces.count == 2 -- mathematically, because of the 'end of line' part of our regular expression
122
+ version = pieces[1].tr('()', '')
123
+ potential_emptiness_error = lambda do |sims|
124
+ UI.error("No simulators found that are equal to the version " \
125
+ "of specifier (#{version}) and greater than or equal to the version " \
126
+ "of deployment target (#{deployment_target_version})") if sims.empty?
127
+ end
128
+ filter_simulators(simulators, :equal, version).tap(&potential_emptiness_error).select(&selector)
129
+ end
130
+ ).tap do |array|
131
+ UI.error("Ignoring '#{device_string}', couldn’t find matching simulator") if array.empty?
115
132
  end
116
133
  end
117
134
 
118
- if found_devices.any?
119
- Scan.devices = found_devices
120
- return
121
- else
122
- UI.error("Couldn't find any matching simulators for '#{devices}' - falling back to default simulator")
123
- end
135
+ set_of_simulators.to_a
124
136
  end
125
137
 
126
- sims = FastlaneCore::SimulatorTV.all
127
- xcode_target = Scan.project.build_settings(key: "TVOS_DEPLOYMENT_TARGET")
128
- sims = filter_simulators(sims, xcode_target)
138
+ default = lambda do
139
+ UI.error("Couldn't find any matching simulators for '#{devices}' - falling back to default simulator")
129
140
 
130
- # Apple TV 1080p is useful for tests
131
- found = sims.detect { |d| d.name == "Apple TV 1080p" }
132
- found ||= sims.first # anything is better than nothing
141
+ result = Array(
142
+ simulators
143
+ .select { |sim| sim.name == default_device_name }
144
+ .reverse # more efficient, because `simctl` prints higher versions first
145
+ .sort_by! { |sim| Gem::Version.new(sim.os_version) }
146
+ .last || simulators.first
147
+ )
133
148
 
134
- if found
135
- Scan.devices = [found]
136
- else
137
- UI.user_error!("No TV simulators found on the local machine")
149
+ UI.error("Found simulator \"#{result.first.name} (#{result.first.os_version})\"") if result.first
150
+
151
+ result
138
152
  end
153
+
154
+ # grab the first unempty evaluated array
155
+ Scan.devices = [matches, default].lazy.map { |x|
156
+ arr = x.call
157
+ arr unless arr.empty?
158
+ }.reject(&:nil?).first
139
159
  end
140
160
 
141
161
  def self.min_xcode8?
data/lib/scan/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Scan
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  DESCRIPTION = "The easiest way to run tests of your iOS and Mac app"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastlane_core
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubyforge_project:
273
- rubygems_version: 2.4.5.1
273
+ rubygems_version: 2.6.6
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: The easiest way to run tests of your iOS and Mac app