@@ -45,11 +45,11 @@ void main(List<String> args) async {
4545 } else {
4646 iosEngineVariant = 'ios_debug_sim_unopt' ;
4747 }
48- final String dumpXcresultOnFailurePath;
48+
49+ // Null if the tests should create and dispose their own temporary directory.
50+ String ? dumpXcresultOnFailurePath;
4951 if (results.option ('dump-xcresult-on-failure' ) case final String path) {
5052 dumpXcresultOnFailurePath = path;
51- } else {
52- dumpXcresultOnFailurePath = io.Directory .systemTemp.createTempSync ().path;
5353 }
5454
5555 // Run the actual script.
@@ -88,6 +88,12 @@ void main(List<String> args) async {
8888 }
8989}
9090
91+ void _deleteIfPresent (io.FileSystemEntity entity) {
92+ if (entity.existsSync ()) {
93+ entity.deleteSync (recursive: true );
94+ }
95+ }
96+
9197/// Runs the script.
9298///
9399/// The [cleanup] set contains cleanup tasks to run when the script is either
@@ -105,7 +111,7 @@ Future<void> _run(
105111 required String osVersion,
106112 required bool withImpeller,
107113 required bool withSkia,
108- required String dumpXcresultOnFailure,
114+ required String ? dumpXcresultOnFailure,
109115}) async {
110116 // Terminate early on SIGINT.
111117 late final StreamSubscription <void > sigint;
@@ -127,7 +133,7 @@ Future<void> _run(
127133 iosEngineVariant: iosEngineVariant,
128134 );
129135
130- cleanup.add (() => resultBundle. deleteSync (recursive : true ));
136+ cleanup.add (() => _deleteIfPresent (resultBundle ));
131137
132138 if (withSkia) {
133139 io.stderr.writeln ('Running simulator tests with Skia' );
@@ -141,22 +147,31 @@ Future<void> _run(
141147 xcodeBuildExtraArgs: [
142148 // Plist with `FTEEnableImpeller=NO`; all projects in the workspace require this file.
143149 // 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' ,
145151 ],
146152 );
147153 cleanup.add (process.kill);
148154
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+
149163 if (await process.exitCode != 0 ) {
150164 final String outputPath = _zipAndStoreFailedTestResults (
151165 iosEngineVariant: iosEngineVariant,
152- resultBundlePath : resultBundle.path ,
153- storePath: dumpXcresultOnFailure ,
166+ resultBundle : resultBundle,
167+ storePath: storePath ,
154168 );
155169 io.stderr.writeln ('Failed test results are stored at $outputPath ' );
156170 throw _ToolFailure ('test failed.' );
157171 } else {
158172 io.stderr.writeln ('test succcess.' );
159173 }
174+ _deleteIfPresent (resultBundle);
160175 }
161176
162177 if (withImpeller) {
@@ -169,17 +184,26 @@ Future<void> _run(
169184 );
170185 cleanup.add (process.kill);
171186
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+
172195 if (await process.exitCode != 0 ) {
173196 final String outputPath = _zipAndStoreFailedTestResults (
174197 iosEngineVariant: iosEngineVariant,
175- resultBundlePath : resultBundle.path ,
176- storePath: dumpXcresultOnFailure ,
198+ resultBundle : resultBundle,
199+ storePath: storePath ,
177200 );
178201 io.stderr.writeln ('Failed test results are stored at $outputPath ' );
179202 throw _ToolFailure ('test failed.' );
180203 } else {
181204 io.stderr.writeln ('test succcess.' );
182205 }
206+ _deleteIfPresent (resultBundle);
183207 }
184208}
185209
@@ -261,8 +285,9 @@ void _ensureSimulatorsRotateAutomaticallyForPlatformViewRotationTest() {
261285}
262286
263287void _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+ );
266291
267292 bool deleteSimulator () {
268293 final result = io.Process .runSync (
@@ -314,8 +339,9 @@ void _createDevice({
314339 ));
315340
316341 // 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+ );
319345 return (scenarioPath, result);
320346}
321347
@@ -353,7 +379,7 @@ Future<io.Process> _runTests({
353379@useResult
354380String _zipAndStoreFailedTestResults ({
355381 required String iosEngineVariant,
356- required String resultBundlePath ,
382+ required io. Directory resultBundle ,
357383 required String storePath,
358384}) {
359385 final outputPath = path.join (storePath, '$iosEngineVariant .zip' );
@@ -363,11 +389,15 @@ String _zipAndStoreFailedTestResults({
363389 '-q' ,
364390 '-r' ,
365391 outputPath,
366- resultBundlePath ,
392+ resultBundle.path ,
367393 ],
368394 );
369395 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+ );
371401 }
372402 return outputPath;
373403}
0 commit comments