@@ -45,11 +45,11 @@ void main(List<String> args) async {
45
45
} else {
46
46
iosEngineVariant = 'ios_debug_sim_unopt' ;
47
47
}
48
- final String dumpXcresultOnFailurePath;
48
+
49
+ // Null if the tests should create and dispose their own temporary directory.
50
+ String ? dumpXcresultOnFailurePath;
49
51
if (results.option ('dump-xcresult-on-failure' ) case final String path) {
50
52
dumpXcresultOnFailurePath = path;
51
- } else {
52
- dumpXcresultOnFailurePath = io.Directory .systemTemp.createTempSync ().path;
53
53
}
54
54
55
55
// Run the actual script.
@@ -88,6 +88,12 @@ void main(List<String> args) async {
88
88
}
89
89
}
90
90
91
+ void _deleteIfPresent (io.FileSystemEntity entity) {
92
+ if (entity.existsSync ()) {
93
+ entity.deleteSync (recursive: true );
94
+ }
95
+ }
96
+
91
97
/// Runs the script.
92
98
///
93
99
/// The [cleanup] set contains cleanup tasks to run when the script is either
@@ -105,7 +111,7 @@ Future<void> _run(
105
111
required String osVersion,
106
112
required bool withImpeller,
107
113
required bool withSkia,
108
- required String dumpXcresultOnFailure,
114
+ required String ? dumpXcresultOnFailure,
109
115
}) async {
110
116
// Terminate early on SIGINT.
111
117
late final StreamSubscription <void > sigint;
@@ -127,7 +133,7 @@ Future<void> _run(
127
133
iosEngineVariant: iosEngineVariant,
128
134
);
129
135
130
- cleanup.add (() => resultBundle. deleteSync (recursive : true ));
136
+ cleanup.add (() => _deleteIfPresent (resultBundle ));
131
137
132
138
if (withSkia) {
133
139
io.stderr.writeln ('Running simulator tests with Skia' );
@@ -141,22 +147,31 @@ Future<void> _run(
141
147
xcodeBuildExtraArgs: [
142
148
// Plist with `FTEEnableImpeller=NO`; all projects in the workspace require this file.
143
149
// For example, `FlutterAppExtensionTestHost` has a dummy file under the below directory.
144
- r'INFOPLIST_FILE=" $(TARGET_NAME)/Info_Skia.plist" ' ,
150
+ r'INFOPLIST_FILE=$(TARGET_NAME)/Info_Skia.plist' ,
145
151
],
146
152
);
147
153
cleanup.add (process.kill);
148
154
155
+ // Create a temporary directory, if needed.
156
+ var storePath = dumpXcresultOnFailure;
157
+ if (storePath == null ) {
158
+ final dumpDir = io.Directory .systemTemp.createTempSync ();
159
+ storePath = dumpDir.path;
160
+ cleanup.add (() => dumpDir.delete (recursive: true ));
161
+ }
162
+
149
163
if (await process.exitCode != 0 ) {
150
164
final String outputPath = _zipAndStoreFailedTestResults (
151
165
iosEngineVariant: iosEngineVariant,
152
- resultBundlePath : resultBundle.path ,
153
- storePath: dumpXcresultOnFailure ,
166
+ resultBundle : resultBundle,
167
+ storePath: storePath ,
154
168
);
155
169
io.stderr.writeln ('Failed test results are stored at $outputPath ' );
156
170
throw _ToolFailure ('test failed.' );
157
171
} else {
158
172
io.stderr.writeln ('test succcess.' );
159
173
}
174
+ _deleteIfPresent (resultBundle);
160
175
}
161
176
162
177
if (withImpeller) {
@@ -169,17 +184,26 @@ Future<void> _run(
169
184
);
170
185
cleanup.add (process.kill);
171
186
187
+ // Create a temporary directory, if needed.
188
+ var storePath = dumpXcresultOnFailure;
189
+ if (storePath == null ) {
190
+ final dumpDir = io.Directory .systemTemp.createTempSync ();
191
+ storePath = dumpDir.path;
192
+ cleanup.add (() => dumpDir.delete (recursive: true ));
193
+ }
194
+
172
195
if (await process.exitCode != 0 ) {
173
196
final String outputPath = _zipAndStoreFailedTestResults (
174
197
iosEngineVariant: iosEngineVariant,
175
- resultBundlePath : resultBundle.path ,
176
- storePath: dumpXcresultOnFailure ,
198
+ resultBundle : resultBundle,
199
+ storePath: storePath ,
177
200
);
178
201
io.stderr.writeln ('Failed test results are stored at $outputPath ' );
179
202
throw _ToolFailure ('test failed.' );
180
203
} else {
181
204
io.stderr.writeln ('test succcess.' );
182
205
}
206
+ _deleteIfPresent (resultBundle);
183
207
}
184
208
}
185
209
@@ -261,8 +285,9 @@ void _ensureSimulatorsRotateAutomaticallyForPlatformViewRotationTest() {
261
285
}
262
286
263
287
void _deleteAnyExistingDevices ({required String deviceName}) {
264
- io.stderr
265
- .writeln ('Deleting any existing simulator devices named $deviceName ...' );
288
+ io.stderr.writeln (
289
+ 'Deleting any existing simulator devices named $deviceName ...' ,
290
+ );
266
291
267
292
bool deleteSimulator () {
268
293
final result = io.Process .runSync (
@@ -314,8 +339,9 @@ void _createDevice({
314
339
));
315
340
316
341
// Create a temporary directory to store the test results.
317
- final result =
318
- io.Directory (scenarioPath).createTempSync ('ios_scenario_xcresult' );
342
+ final result = io.Directory (scenarioPath).createTempSync (
343
+ 'ios_scenario_xcresult' ,
344
+ );
319
345
return (scenarioPath, result);
320
346
}
321
347
@@ -353,7 +379,7 @@ Future<io.Process> _runTests({
353
379
@useResult
354
380
String _zipAndStoreFailedTestResults ({
355
381
required String iosEngineVariant,
356
- required String resultBundlePath ,
382
+ required io. Directory resultBundle ,
357
383
required String storePath,
358
384
}) {
359
385
final outputPath = path.join (storePath, '$iosEngineVariant .zip' );
@@ -363,11 +389,15 @@ String _zipAndStoreFailedTestResults({
363
389
'-q' ,
364
390
'-r' ,
365
391
outputPath,
366
- resultBundlePath ,
392
+ resultBundle.path ,
367
393
],
368
394
);
369
395
if (result.exitCode != 0 ) {
370
- throw Exception ('Failed to zip the test results: ${result .stderr }' );
396
+ throw Exception (
397
+ 'Failed to zip the test results (exit code = ${result .exitCode }).\n\n '
398
+ 'Stderr: ${result .stderr }\n\n '
399
+ 'Stdout: ${result .stdout }' ,
400
+ );
371
401
}
372
402
return outputPath;
373
403
}
0 commit comments