@@ -111,8 +111,12 @@ class GoldenTestCommand extends Command {
111
111
...cmdArguments,
112
112
],
113
113
description: 'Golden tests' ,
114
+ throwOnError: false ,
114
115
);
115
116
117
+ // After running the tests, we don't need the image anymore. Remove it.
118
+ await _removeDockerImage ();
119
+
116
120
// Mapping the failure directories causes them to be created automatically, even without any failing test.
117
121
// Remove all the empty failure directories.
118
122
for (final dirName in dirs) {
@@ -268,7 +272,11 @@ class UpdateGoldensCommand extends Command {
268
272
...cmdArguments,
269
273
],
270
274
description: 'Update goldens' ,
275
+ throwOnError: false ,
271
276
);
277
+
278
+ // After running the tests, we don't need the image anymore. Remove it.
279
+ await _removeDockerImage ();
272
280
}
273
281
}
274
282
@@ -295,6 +303,20 @@ Future<void> _buildDockerImage() async {
295
303
);
296
304
}
297
305
306
+ /// Removes the image built by the golden tester.
307
+ Future <void > _removeDockerImage () async {
308
+ await _runProcess (
309
+ executable: 'docker' ,
310
+ arguments: [
311
+ 'image' , 'rm' , //
312
+ '-f' ,
313
+ 'supereditor_golden_tester' ,
314
+ ],
315
+ description: 'Removing image' ,
316
+ throwOnError: false ,
317
+ );
318
+ }
319
+
298
320
/// Runs [executable] with the given [arguments] .
299
321
///
300
322
/// [executable] could be an absolute path or it could be resolved from the PATH.
@@ -305,12 +327,15 @@ Future<void> _buildDockerImage() async {
305
327
///
306
328
/// The child process stdout and stderr are written to the current process stdout.
307
329
///
308
- /// Throws and exception using [description] in the message if the process exists with a non-zero exit code.
309
- Future <void > _runProcess ({
330
+ /// If [throwOnError] is `true` , throws an exception if the process exits with a non-zero exit code.
331
+ ///
332
+ /// If [throwOnError] is `false` , the function returns the exit code.
333
+ Future <int > _runProcess ({
310
334
required String executable,
311
335
required List <String > arguments,
312
336
required String description,
313
337
String ? workingDirectory,
338
+ bool throwOnError = true ,
314
339
}) async {
315
340
final process = await Process .start (
316
341
executable,
@@ -323,7 +348,9 @@ Future<void> _runProcess({
323
348
324
349
final exitCode = await process.exitCode;
325
350
326
- if (exitCode != 0 ) {
351
+ if (exitCode != 0 && throwOnError ) {
327
352
throw Exception ('$description failed' );
328
353
}
354
+
355
+ return exitCode;
329
356
}
0 commit comments