1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:file/file.dart';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' show ProcessException, ProcessResult;
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';
import 'package:test/test.dart';
import '../src/common.dart';
import '../src/context.dart';
class MockProcessManager extends Mock implements ProcessManager {}
class MockFile extends Mock implements File {}
void main() {
final FakePlatform osx = new FakePlatform.fromPlatform(const LocalPlatform());
osx.operatingSystem = 'macos';
group('IMobileDevice', () {
group('screenshot', () {
final String outputPath = fs.path.join('some', 'test', 'path', 'image.png');
MockProcessManager mockProcessManager;
MockFile mockOutputFile;
setUp(() {
mockProcessManager = new MockProcessManager();
mockOutputFile = new MockFile();
});
testUsingContext('error if idevicescreenshot is not installed', () async {
when(mockOutputFile.path).thenReturn(outputPath);
// Let `idevicescreenshot` fail with exit code 1.
when(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
environment: null,
workingDirectory: null
)).thenReturn(new ProcessResult(4, 1, '', ''));
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Platform: () => osx,
});
testUsingContext('idevicescreenshot captures and returns screenshot', () async {
when(mockOutputFile.path).thenReturn(outputPath);
when(mockProcessManager.run(any, environment: null, workingDirectory: null))
.thenReturn(new Future<ProcessResult>.value(new ProcessResult(4, 0, '', '')));
await iMobileDevice.takeScreenshot(mockOutputFile);
verify(mockProcessManager.run(<String>['idevicescreenshot', outputPath],
environment: null,
workingDirectory: null
));
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
});
});
group('Xcode', () {
MockProcessManager mockProcessManager;
Xcode xcode;
setUp(() {
mockProcessManager = new MockProcessManager();
xcode = new Xcode();
});
testUsingContext('xcodeSelectPath returns null when xcode-select is not installed', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcode-select', '--print-path']))
.thenThrow(const ProcessException('/usr/bin/xcode-select', const <String>['--print-path']));
expect(xcode.xcodeSelectPath, isNull);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('xcodeSelectPath returns path when xcode-select is installed', () {
final String xcodePath = '/Applications/Xcode8.0.app/Contents/Developer';
when(mockProcessManager.runSync(<String>['/usr/bin/xcode-select', '--print-path']))
.thenReturn(new ProcessResult(1, 0, xcodePath, ''));
expect(xcode.xcodeSelectPath, xcodePath);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('xcodeVersionText returns null when xcodebuild is not installed', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcodebuild', '-version']))
.thenThrow(const ProcessException('/usr/bin/xcodebuild', const <String>['-version']));
expect(xcode.xcodeVersionText, isNull);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('xcodeVersionText returns null when xcodebuild is not installed', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcodebuild', '-version']))
.thenReturn(new ProcessResult(1, 0, 'Xcode 8.3.3\nBuild version 8E3004b', ''));
expect(xcode.xcodeVersionText, 'Xcode 8.3.3, Build version 8E3004b');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('eulaSigned is false when clang is not installed', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcrun', 'clang']))
.thenThrow(const ProcessException('/usr/bin/xcrun', const <String>['clang']));
expect(xcode.eulaSigned, isFalse);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('eulaSigned is false when clang output indicates EULA not yet accepted', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcrun', 'clang']))
.thenReturn(new ProcessResult(1, 1, '', 'Xcode EULA has not been accepted.\nLaunch Xcode and accept the license.'));
expect(xcode.eulaSigned, isFalse);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('eulaSigned is true when clang output indicates EULA has been accepted', () {
when(mockProcessManager.runSync(<String>['/usr/bin/xcrun', 'clang']))
.thenReturn(new ProcessResult(1, 1, '', 'clang: error: no input files'));
expect(xcode.eulaSigned, isTrue);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('getAvailableDevices throws ToolExit when instruments is not installed', () async {
when(mockProcessManager.run(<String>['/usr/bin/instruments', '-s', 'devices']))
.thenThrow(const ProcessException('/usr/bin/instruments', const <String>['-s', 'devices']));
expect(() async => await xcode.getAvailableDevices(), throwsToolExit());
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('getAvailableDevices throws ToolExit when instruments returns non-zero', () async {
when(mockProcessManager.run(<String>['/usr/bin/instruments', '-s', 'devices']))
.thenReturn(new ProcessResult(1, 1, '', 'Sad today'));
expect(() async => await xcode.getAvailableDevices(), throwsToolExit());
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
testUsingContext('getAvailableDevices returns instruments output when installed', () async {
when(mockProcessManager.run(<String>['/usr/bin/instruments', '-s', 'devices']))
.thenReturn(new ProcessResult(1, 0, 'Known Devices:\niPhone 6s (10.3.3) [foo]', ''));
expect(await xcode.getAvailableDevices(), 'Known Devices:\niPhone 6s (10.3.3) [foo]');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
});
});
group('Diagnose Xcode build failure', () {
BuildableIOSApp app;
setUp(() {
app = new BuildableIOSApp(
projectBundleId: 'test.app',
buildSettings: <String, String>{
'For our purposes': 'a non-empty build settings map is valid',
},
);
});
testUsingContext('No provisioning profile shows message', () async {
final XcodeBuildResult buildResult = new XcodeBuildResult(
success: false,
stdout: '''
Launching lib/main.dart on iPhone in debug mode...
Signing iOS app for device deployment using developer identity: "iPhone Developer: test@flutter.io (1122334455)"
Running Xcode build... 1.3s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Xcode's output:
↳
Build settings from command line:
ARCHS = arm64
BUILD_DIR = /Users/blah/blah
DEVELOPMENT_TEAM = AABBCCDDEE
ONLY_ACTIVE_ARCH = YES
SDKROOT = iphoneos10.3
=== CLEAN TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
Check dependencies
[BCEROR]No profiles for 'com.yourcompany.test' were found: Xcode couldn't find a provisioning profile matching 'com.yourcompany.test'.
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Create product structure
/bin/mkdir -p /Users/blah/Runner.app
Clean.Remove clean /Users/blah/Runner.app.dSYM
builtin-rm -rf /Users/blah/Runner.app.dSYM
Clean.Remove clean /Users/blah/Runner.app
builtin-rm -rf /Users/blah/Runner.app
Clean.Remove clean /Users/blah/Runner-dfvicjniknvzghgwsthwtgcjhtsk/Build/Intermediates/Runner.build/Release-iphoneos/Runner.build
builtin-rm -rf /Users/blah/Runner-dfvicjniknvzghgwsthwtgcjhtsk/Build/Intermediates/Runner.build/Release-iphoneos/Runner.build
** CLEAN SUCCEEDED **
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
Check dependencies
No profiles for 'com.yourcompany.test' were found: Xcode couldn't find a provisioning profile matching 'com.yourcompany.test'.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Could not build the precompiled application for the device.
Error launching application on iPhone.''',
xcodeBuildExecution: new XcodeBuildExecution(
<String>['xcrun', 'xcodebuild', 'blah'],
'/blah/blah',
buildForPhysicalDevice: true
),
);
await diagnoseXcodeBuildFailure(buildResult, app);
expect(
testLogger.errorText,
contains('No Provisioning Profile was found for your project\'s Bundle Identifier or your device.'),
);
});
testUsingContext('No development team shows message', () async {
final XcodeBuildResult buildResult = new XcodeBuildResult(
success: false,
stdout: '''
Running "flutter packages get" in flutter_gallery... 0.6s
Launching lib/main.dart on x in release mode...
Running pod install... 1.2s
Running Xcode build... 1.4s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Xcode's output:
↳
blah
=== CLEAN TARGET url_launcher OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
blah
=== CLEAN TARGET Pods-Runner OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
blah
=== CLEAN TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
Check dependencies
[BCEROR]Signing for "Runner" requires a development team. Select a development team in the project editor.
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
[BCEROR]Code signing is required for product type 'Application' in SDK 'iOS 10.3'
blah
** CLEAN SUCCEEDED **
=== BUILD TARGET url_launcher OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
blah
=== BUILD TARGET Pods-Runner OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
blah
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Release ===
Check dependencies
Signing for "Runner" requires a development team. Select a development team in the project editor.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Code signing is required for product type 'Application' in SDK 'iOS 10.3'
Could not build the precompiled application for the device.''',
xcodeBuildExecution: new XcodeBuildExecution(
<String>['xcrun', 'xcodebuild', 'blah'],
'/blah/blah',
buildForPhysicalDevice: true
),
);
await diagnoseXcodeBuildFailure(buildResult, app);
expect(
testLogger.errorText,
contains('Building a deployable iOS app requires a selected Development Team with a Provisioning Profile'),
);
});
});
}