From f1fa6d95d402cfa259828b67da1346dc255cae7f Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 18 Apr 2023 13:47:42 -0700 Subject: [PATCH 1/5] Allow example readme snippets --- script/tool/lib/src/update_excerpts_command.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script/tool/lib/src/update_excerpts_command.dart b/script/tool/lib/src/update_excerpts_command.dart index e65bed846cb..4004a6c03ce 100644 --- a/script/tool/lib/src/update_excerpts_command.dart +++ b/script/tool/lib/src/update_excerpts_command.dart @@ -89,6 +89,9 @@ class UpdateExcerptsCommand extends PackageLoopingCommand { if (!await _injectSnippets(example, targetPackage: package)) { return PackageResult.fail(['Unable to inject excerpts']); } + if (!await _injectSnippets(example, targetPackage: example)) { + return PackageResult.fail(['Unable to inject excerpts']); + } } finally { // Clean up the pubspec changes and extracted excerpts directory. _undoPubspecChanges(example); From a4de0d4a3b804d25c3c0c3aff1634b671e6d92bf Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 18 Apr 2023 13:50:27 -0700 Subject: [PATCH 2/5] changelog --- script/tool/CHANGELOG.md | 4 ++++ script/tool/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 31adba72697..44d1d72473e 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.13.4+4 + +* Allows code excerpts in `example/README.md`. + ## 0.13.4+3 * Moves source to flutter/packages. diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index dd42b0dde00..0926fe48616 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_plugin_tools description: Productivity and CI utils for flutter/packages repository: https://github.com/flutter/packages/tree/main/script/tool -version: 0.13.4+3 +version: 0.13.4+4 dependencies: args: ^2.1.0 From 791aad81298af061ca42607d875bed4b17775c72 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 18 Apr 2023 21:58:26 -0700 Subject: [PATCH 3/5] test --- script/tool/test/update_excerpts_command_test.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/script/tool/test/update_excerpts_command_test.dart b/script/tool/test/update_excerpts_command_test.dart index 193001fed6c..fe45633eef5 100644 --- a/script/tool/test/update_excerpts_command_test.dart +++ b/script/tool/test/update_excerpts_command_test.dart @@ -100,6 +100,17 @@ void main() { '../README.md', ], example.path), + ProcessCall( + 'dart', + const [ + 'run', + 'code_excerpt_updater', + '--write-in-place', + '--yaml', + '--no-escape-ng-interpolation', + 'README.md', + ], + example.path), ])); expect( From 56a2f854aa80585e404862e78a1465e949321926 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Tue, 18 Apr 2023 22:06:12 -0700 Subject: [PATCH 4/5] clearer --- .../tool/lib/src/update_excerpts_command.dart | 3 +- .../test/update_excerpts_command_test.dart | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/script/tool/lib/src/update_excerpts_command.dart b/script/tool/lib/src/update_excerpts_command.dart index 4004a6c03ce..8583e4993c7 100644 --- a/script/tool/lib/src/update_excerpts_command.dart +++ b/script/tool/lib/src/update_excerpts_command.dart @@ -90,7 +90,8 @@ class UpdateExcerptsCommand extends PackageLoopingCommand { return PackageResult.fail(['Unable to inject excerpts']); } if (!await _injectSnippets(example, targetPackage: example)) { - return PackageResult.fail(['Unable to inject excerpts']); + return PackageResult.fail( + ['Unable to inject example excerpts']); } } finally { // Clean up the pubspec changes and extracted excerpts directory. diff --git a/script/tool/test/update_excerpts_command_test.dart b/script/tool/test/update_excerpts_command_test.dart index fe45633eef5..a13cc4a2aa8 100644 --- a/script/tool/test/update_excerpts_command_test.dart +++ b/script/tool/test/update_excerpts_command_test.dart @@ -100,6 +100,39 @@ void main() { '../README.md', ], example.path), + ])); + + expect( + output, + containsAllInOrder([ + contains('Ran for 1 package(s)'), + ])); + }); + + test('updates example readme when config is present', () async { + final RepositoryPackage package = createFakePlugin('a_package', packagesDir, + extraFiles: [kReadmeExcerptConfigPath]); + final Directory example = getExampleDir(package); + + final List output = + await runCapturingPrint(runner, ['update-excerpts']); + + expect( + processRunner.recordedCalls, + containsAll([ + ProcessCall( + 'dart', + const [ + 'run', + 'build_runner', + 'build', + '--config', + 'excerpt', + '--output', + 'excerpts', + '--delete-conflicting-outputs', + ], + example.path), ProcessCall( 'dart', const [ From 96d10b204a1f764a9602a849cfc7873c08b42fd6 Mon Sep 17 00:00:00 2001 From: tarrinneal Date: Wed, 19 Apr 2023 11:24:53 -0700 Subject: [PATCH 5/5] final test --- .../test/update_excerpts_command_test.dart | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/script/tool/test/update_excerpts_command_test.dart b/script/tool/test/update_excerpts_command_test.dart index a13cc4a2aa8..7bb0297de13 100644 --- a/script/tool/test/update_excerpts_command_test.dart +++ b/script/tool/test/update_excerpts_command_test.dart @@ -275,6 +275,34 @@ void main() { ])); }); + test('fails if example injection fails', () async { + createFakePlugin('a_package', packagesDir, + extraFiles: [kReadmeExcerptConfigPath]); + + processRunner.mockProcessesForExecutable['dart'] = [ + FakeProcessInfo(MockProcess(), ['pub', 'get']), + FakeProcessInfo(MockProcess(), ['run', 'build_runner']), + FakeProcessInfo(MockProcess(), ['run', 'code_excerpt_updater']), + FakeProcessInfo( + MockProcess(exitCode: 1), ['run', 'code_excerpt_updater']), + ]; + + Error? commandError; + final List output = await runCapturingPrint( + runner, ['update-excerpts'], errorHandler: (Error e) { + commandError = e; + }); + + expect(commandError, isA()); + expect( + output, + containsAllInOrder([ + contains('The following packages had errors:'), + contains('a_package:\n' + ' Unable to inject example excerpts') + ])); + }); + test('fails if READMEs are changed with --fail-on-change', () async { createFakePlugin('a_plugin', packagesDir, extraFiles: [kReadmeExcerptConfigPath]);