@@ -58,7 +58,7 @@ void main() {
58
58
'--config' ,
59
59
'excerpt' ,
60
60
'--output' ,
61
- 'excerpts' ,
61
+ UpdateExcerptsCommand .excerptOutputDir ,
62
62
'--delete-conflicting-outputs' ,
63
63
],
64
64
example.path),
@@ -85,7 +85,7 @@ void main() {
85
85
'--config' ,
86
86
'excerpt' ,
87
87
'--output' ,
88
- 'excerpts' ,
88
+ UpdateExcerptsCommand .excerptOutputDir ,
89
89
'--delete-conflicting-outputs' ,
90
90
],
91
91
example.path),
@@ -129,7 +129,7 @@ void main() {
129
129
'--config' ,
130
130
'excerpt' ,
131
131
'--output' ,
132
- 'excerpts' ,
132
+ UpdateExcerptsCommand .excerptOutputDir ,
133
133
'--delete-conflicting-outputs' ,
134
134
],
135
135
example.path),
@@ -174,7 +174,7 @@ void main() {
174
174
'--config' ,
175
175
'excerpt' ,
176
176
'--output' ,
177
- 'excerpts' ,
177
+ UpdateExcerptsCommand .excerptOutputDir ,
178
178
'--delete-conflicting-outputs' ,
179
179
],
180
180
example.path),
@@ -416,4 +416,52 @@ void main() {
416
416
contains ('Unable to determine local file state' ),
417
417
]));
418
418
});
419
+
420
+ test ('cleans up excerpt output by default' , () async {
421
+ final RepositoryPackage package = createFakePackage (
422
+ 'a_package' , packagesDir,
423
+ extraFiles: < String > [kReadmeExcerptConfigPath]);
424
+ // Simulate the creation of the output directory.
425
+ final Directory excerptOutputDir = package
426
+ .getExamples ()
427
+ .first
428
+ .directory
429
+ .childDirectory (UpdateExcerptsCommand .excerptOutputDir);
430
+ excerptOutputDir.createSync (recursive: true );
431
+
432
+ const String changedFilePath = 'packages/a_plugin/linux/CMakeLists.txt' ;
433
+ processRunner.mockProcessesForExecutable['git' ] = < FakeProcessInfo > [
434
+ FakeProcessInfo (MockProcess (stdout: changedFilePath)),
435
+ ];
436
+
437
+ await runCapturingPrint (runner, < String > ['update-excerpts' ]);
438
+
439
+ expect (excerptOutputDir.existsSync (), false );
440
+ });
441
+
442
+ test ('cleans up excerpt output by default' , () async {
443
+ final RepositoryPackage package = createFakePackage (
444
+ 'a_package' , packagesDir,
445
+ extraFiles: < String > [kReadmeExcerptConfigPath]);
446
+ // Simulate the creation of the output directory.
447
+ const String outputDirName = UpdateExcerptsCommand .excerptOutputDir;
448
+ final Directory excerptOutputDir =
449
+ package.getExamples ().first.directory.childDirectory (outputDirName);
450
+ excerptOutputDir.createSync (recursive: true );
451
+
452
+ const String changedFilePath = 'packages/a_plugin/linux/CMakeLists.txt' ;
453
+ processRunner.mockProcessesForExecutable['git' ] = < FakeProcessInfo > [
454
+ FakeProcessInfo (MockProcess (stdout: changedFilePath)),
455
+ ];
456
+
457
+ final List <String > output = await runCapturingPrint (
458
+ runner, < String > ['update-excerpts' , '--no-cleanup' ]);
459
+
460
+ expect (
461
+ output,
462
+ containsAllInOrder (< Matcher > [
463
+ contains ('Extraction output is in example/$outputDirName /' ),
464
+ ]));
465
+ expect (excerptOutputDir.existsSync (), true );
466
+ });
419
467
}
0 commit comments