From 416612fb8bf1de80538fbc6eaa9591c003ac3f25 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 02:32:59 +0300 Subject: [PATCH 01/23] change fix_data uris to be absolute to fix lints --- packages/go_router/lib/fix_data.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/go_router/lib/fix_data.yaml b/packages/go_router/lib/fix_data.yaml index 99f978243a0..7a725388561 100644 --- a/packages/go_router/lib/fix_data.yaml +++ b/packages/go_router/lib/fix_data.yaml @@ -21,7 +21,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'replaceNamed' inClass: 'GoRouter' changes: @@ -35,7 +35,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'pushReplacementNamed' inClass: 'GoRouter' changes: @@ -50,7 +50,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'pushNamed' inClass: 'GoRouter' changes: @@ -65,7 +65,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'goNamed' inClass: 'GoRouter' changes: @@ -80,7 +80,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouter' changes: @@ -95,7 +95,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouterState' changes: @@ -110,7 +110,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] field: 'queryParams' inClass: 'GoRouterState' changes: @@ -121,7 +121,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] field: 'fullpath' inClass: 'GoRouterState' changes: @@ -132,7 +132,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] field: 'params' inClass: 'GoRouterState' changes: @@ -143,7 +143,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + uris: [ 'package:go_router/go_router.dart' ] field: 'subloc' inClass: 'GoRouterState' changes: From 17ff4d1d62563864289d7f6e768faa655651efd9 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 02:41:56 +0300 Subject: [PATCH 02/23] changed version --- packages/go_router/CHANGELOG.md | 4 ++++ packages/go_router/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index d46e9de8c32..669a45c3ea7 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.0.1 + +- Fixes the `dart fix --apply` command not working + ## 7.0.0 - **BREAKING CHANGE**: diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 4d1cb1fda84..0c93fa921b3 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 7.0.0 +version: 7.0.1 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 From c4a70c72505257c5789d651d990855f13b10cdd9 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 03:09:02 +0300 Subject: [PATCH 03/23] add both relative and absoulte paths to uri --- packages/go_router/lib/fix_data.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/go_router/lib/fix_data.yaml b/packages/go_router/lib/fix_data.yaml index 7a725388561..4a31c08073b 100644 --- a/packages/go_router/lib/fix_data.yaml +++ b/packages/go_router/lib/fix_data.yaml @@ -21,7 +21,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'replaceNamed' inClass: 'GoRouter' changes: @@ -35,7 +35,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushReplacementNamed' inClass: 'GoRouter' changes: @@ -50,7 +50,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushNamed' inClass: 'GoRouter' changes: @@ -65,7 +65,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'goNamed' inClass: 'GoRouter' changes: @@ -80,7 +80,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouter' changes: @@ -95,7 +95,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouterState' changes: @@ -110,7 +110,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'queryParams' inClass: 'GoRouterState' changes: @@ -121,7 +121,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'fullpath' inClass: 'GoRouterState' changes: @@ -132,7 +132,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'params' inClass: 'GoRouterState' changes: @@ -143,7 +143,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'package:go_router/go_router.dart' ] + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'subloc' inClass: 'GoRouterState' changes: From 082bd0965321eab6a8168d00d954afcac0477ca0 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 05:16:05 +0300 Subject: [PATCH 04/23] added tests --- packages/go_router/pubspec.yaml | 2 + packages/go_router/test_fixes/pubspec.yaml | 13 +++++ packages/go_router/tool/run_tests.dart | 67 ++++++++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 packages/go_router/test_fixes/pubspec.yaml diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 0c93fa921b3..18da1517140 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -21,4 +21,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + io: ^1.0.4 path: ^1.8.2 + yaml_edit: ^2.1.0 \ No newline at end of file diff --git a/packages/go_router/test_fixes/pubspec.yaml b/packages/go_router/test_fixes/pubspec.yaml new file mode 100644 index 00000000000..34cc73fda16 --- /dev/null +++ b/packages/go_router/test_fixes/pubspec.yaml @@ -0,0 +1,13 @@ +name: test_fixes +publish_to: "none" +version: 1.0.0+1 + +environment: + sdk: ">=2.18.0 <4.0.0" + flutter: ">=3.3.0" + +dependencies: + flutter: + sdk: flutter + go_router: + path: ../ diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 39fe8cc0361..892dced3b35 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -9,27 +9,86 @@ // ignore_for_file: avoid_print import 'dart:io'; +import 'package:io/io.dart' as io; import 'package:path/path.dart' as p; +import 'package:yaml_edit/yaml_edit.dart'; Future main(List args) async { - if (!Platform.isMacOS) { - print('This test can only be run on macOS.'); + if (!Platform.isMacOS && !Platform.isWindows) { + print('This test can only be run on macOS or windows.'); exit(0); } + final p.Context ctx = p.context; final Directory packageRoot = - Directory(p.dirname(Platform.script.path)).parent; + Directory(ctx.dirname(_ensureTrimLeadingSeparator(Platform.script.path))) + .parent; + + //copy from go_router/test_fixes to /go_router_test_fixes + final String testFixesTargetDir = + ctx.join(ctx.dirname(packageRoot.path), 'go_router_test_fixes'); + await _prepareTemplate( + ctx: ctx, + testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), + testFixesTargetDir: testFixesTargetDir, + //Switching this to true, will depend on go_router v7.0.0, which will fail the golden test + testBadVersion: false, + ); + final int pubGet = await _runProcess( + 'dart', + [ + 'pub', + 'upgrade', + ], + workingDirectory: testFixesTargetDir, + ); + if (pubGet != 0) { + exit(pubGet); + } final int status = await _runProcess( 'dart', [ 'fix', '--compare-to-golden', ], - workingDirectory: p.join(packageRoot.path, 'test_fixes'), + workingDirectory: testFixesTargetDir, ); exit(status); } +Future _prepareTemplate({ + required String testFixesDir, + required String testFixesTargetDir, + required p.Context ctx, + required bool testBadVersion, +}) async { + await io.copyPath(testFixesDir, testFixesTargetDir); + + final String pubspecYamlPath = ctx.join(testFixesTargetDir, 'pubspec.yaml'); + final File targetPubspecPath = File(pubspecYamlPath); + //write .gitignore to ignore the newly created folder + await File(ctx.join(testFixesTargetDir, '.gitignore')).writeAsString('*'); + + final YamlEditor editor = YamlEditor(await targetPubspecPath.readAsString()); + if (testBadVersion) { + editor.update(['dependencies', 'go_router'], '7.0.0'); + } else { + editor + .update(['dependencies', 'go_router', 'path'], '../go_router'); + } + final String newYaml = editor.toString(); + await targetPubspecPath.writeAsString(newYaml); +} + +String _ensureTrimLeadingSeparator(String path) { + if (Platform.isWindows) { + if (path.startsWith('/')) { + return path.substring(1); + } + } + return path; +} + Future _streamOutput(Future processFuture) async { final Process process = await processFuture; stdout.addStream(process.stdout); From 6dd50cac42a9b6d38584f8c9d383af64dafc7bd2 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 14:48:18 +0300 Subject: [PATCH 05/23] create a temp folder instead --- packages/go_router/tool/run_tests.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 892dced3b35..27bd9644367 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -14,8 +14,8 @@ import 'package:path/path.dart' as p; import 'package:yaml_edit/yaml_edit.dart'; Future main(List args) async { - if (!Platform.isMacOS && !Platform.isWindows) { - print('This test can only be run on macOS or windows.'); + if (!Platform.isMacOS /* && !Platform.isWindows*/) { + print('This test can only be run on macOS' /*' or windows.'*/); exit(0); } final p.Context ctx = p.context; @@ -23,13 +23,13 @@ Future main(List args) async { Directory(ctx.dirname(_ensureTrimLeadingSeparator(Platform.script.path))) .parent; - //copy from go_router/test_fixes to /go_router_test_fixes - final String testFixesTargetDir = - ctx.join(ctx.dirname(packageRoot.path), 'go_router_test_fixes'); + //copy from go_router/test_fixes to temp directory + final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); + await _prepareTemplate( ctx: ctx, testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), - testFixesTargetDir: testFixesTargetDir, + testFixesTargetDir: testFixesTargetDir.path, //Switching this to true, will depend on go_router v7.0.0, which will fail the golden test testBadVersion: false, ); @@ -39,7 +39,7 @@ Future main(List args) async { 'pub', 'upgrade', ], - workingDirectory: testFixesTargetDir, + workingDirectory: testFixesTargetDir.path, ); if (pubGet != 0) { exit(pubGet); @@ -50,7 +50,7 @@ Future main(List args) async { 'fix', '--compare-to-golden', ], - workingDirectory: testFixesTargetDir, + workingDirectory: testFixesTargetDir.path, ); exit(status); @@ -66,15 +66,15 @@ Future _prepareTemplate({ final String pubspecYamlPath = ctx.join(testFixesTargetDir, 'pubspec.yaml'); final File targetPubspecPath = File(pubspecYamlPath); - //write .gitignore to ignore the newly created folder - await File(ctx.join(testFixesTargetDir, '.gitignore')).writeAsString('*'); final YamlEditor editor = YamlEditor(await targetPubspecPath.readAsString()); if (testBadVersion) { editor.update(['dependencies', 'go_router'], '7.0.0'); } else { - editor - .update(['dependencies', 'go_router', 'path'], '../go_router'); + editor.update( + ['dependencies', 'go_router', 'path'], + ctx.dirname(testFixesDir), + ); } final String newYaml = editor.toString(); await targetPubspecPath.writeAsString(newYaml); From 22979c16556a960910af603268dc8d6a1dcbb3f0 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:18:43 +0300 Subject: [PATCH 06/23] demonstrate testPubVersion --- packages/go_router/tool/run_tests.dart | 65 ++++++++++++++------------ 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 27bd9644367..466d2ca89ae 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -25,42 +25,45 @@ Future main(List args) async { //copy from go_router/test_fixes to temp directory final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); - - await _prepareTemplate( - ctx: ctx, - testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), - testFixesTargetDir: testFixesTargetDir.path, - //Switching this to true, will depend on go_router v7.0.0, which will fail the golden test - testBadVersion: false, - ); - final int pubGet = await _runProcess( - 'dart', - [ - 'pub', - 'upgrade', - ], - workingDirectory: testFixesTargetDir.path, - ); - if (pubGet != 0) { - exit(pubGet); + for (final bool testPubVersion in [true, false]) { + //testPubVersion=true will lead to failiure on go_router v7.0.0 + await _prepareTemplate( + ctx: ctx, + testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), + testFixesTargetDir: testFixesTargetDir.path, + testPubVersion: testPubVersion, + ); + final int pubGet = await _runProcess( + 'dart', + [ + 'pub', + 'upgrade', + ], + workingDirectory: testFixesTargetDir.path, + ); + if (pubGet != 0) { + exit(pubGet); + } + final int status = await _runProcess( + 'dart', + [ + 'fix', + '--compare-to-golden', + ], + workingDirectory: testFixesTargetDir.path, + ); + if (status != 0) { + exit(status); + } } - final int status = await _runProcess( - 'dart', - [ - 'fix', - '--compare-to-golden', - ], - workingDirectory: testFixesTargetDir.path, - ); - - exit(status); + exit(0); } Future _prepareTemplate({ required String testFixesDir, required String testFixesTargetDir, required p.Context ctx, - required bool testBadVersion, + required bool testPubVersion, }) async { await io.copyPath(testFixesDir, testFixesTargetDir); @@ -68,8 +71,8 @@ Future _prepareTemplate({ final File targetPubspecPath = File(pubspecYamlPath); final YamlEditor editor = YamlEditor(await targetPubspecPath.readAsString()); - if (testBadVersion) { - editor.update(['dependencies', 'go_router'], '7.0.0'); + if (testPubVersion) { + editor.update(['dependencies', 'go_router'], 'any'); } else { editor.update( ['dependencies', 'go_router', 'path'], From 3c15fd15fdbe431d2233389f2a9d45d866574fa3 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:28:42 +0300 Subject: [PATCH 07/23] remove testPubVersion entirely --- packages/go_router/tool/run_tests.dart | 70 +++++++++++--------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 466d2ca89ae..75510645402 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -25,45 +25,39 @@ Future main(List args) async { //copy from go_router/test_fixes to temp directory final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); - for (final bool testPubVersion in [true, false]) { - //testPubVersion=true will lead to failiure on go_router v7.0.0 - await _prepareTemplate( - ctx: ctx, - testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), - testFixesTargetDir: testFixesTargetDir.path, - testPubVersion: testPubVersion, - ); - final int pubGet = await _runProcess( - 'dart', - [ - 'pub', - 'upgrade', - ], - workingDirectory: testFixesTargetDir.path, - ); - if (pubGet != 0) { - exit(pubGet); - } - final int status = await _runProcess( - 'dart', - [ - 'fix', - '--compare-to-golden', - ], - workingDirectory: testFixesTargetDir.path, - ); - if (status != 0) { - exit(status); - } + + await _prepareTemplate( + ctx: ctx, + testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), + testFixesTargetDir: testFixesTargetDir.path, + ); + final int pubGet = await _runProcess( + 'dart', + [ + 'pub', + 'upgrade', + ], + workingDirectory: testFixesTargetDir.path, + ); + if (pubGet != 0) { + exit(pubGet); } - exit(0); + final int status = await _runProcess( + 'dart', + [ + 'fix', + '--compare-to-golden', + ], + workingDirectory: testFixesTargetDir.path, + ); + + exit(status); } Future _prepareTemplate({ required String testFixesDir, required String testFixesTargetDir, required p.Context ctx, - required bool testPubVersion, }) async { await io.copyPath(testFixesDir, testFixesTargetDir); @@ -71,14 +65,10 @@ Future _prepareTemplate({ final File targetPubspecPath = File(pubspecYamlPath); final YamlEditor editor = YamlEditor(await targetPubspecPath.readAsString()); - if (testPubVersion) { - editor.update(['dependencies', 'go_router'], 'any'); - } else { - editor.update( - ['dependencies', 'go_router', 'path'], - ctx.dirname(testFixesDir), - ); - } + editor.update( + ['dependencies', 'go_router', 'path'], + ctx.dirname(testFixesDir), + ); final String newYaml = editor.toString(); await targetPubspecPath.writeAsString(newYaml); } From 89b929ecd536d181978642ddca72aca54e763686 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:30:29 +0300 Subject: [PATCH 08/23] enable test for windows too --- packages/go_router/tool/run_tests.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 75510645402..a8ada4cbf0b 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -14,8 +14,8 @@ import 'package:path/path.dart' as p; import 'package:yaml_edit/yaml_edit.dart'; Future main(List args) async { - if (!Platform.isMacOS /* && !Platform.isWindows*/) { - print('This test can only be run on macOS' /*' or windows.'*/); + if (!Platform.isMacOS && !Platform.isWindows) { + print('This test can only be run on macOS or windows.'); exit(0); } final p.Context ctx = p.context; From c0eddc07bb7dea541cb56373ebd4ea9f77a37bf3 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:37:41 +0300 Subject: [PATCH 09/23] dart format to please the CI --- packages/go_router/tool/run_tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index a8ada4cbf0b..c4f6a282cd5 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -25,7 +25,7 @@ Future main(List args) async { //copy from go_router/test_fixes to temp directory final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); - + await _prepareTemplate( ctx: ctx, testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), From 06a65d5bb9254c8abd5934091c7d1a34002b780e Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:57:19 +0300 Subject: [PATCH 10/23] address comments --- packages/go_router/lib/fix_data.yaml | 10 ++++++++ packages/go_router/pubspec.yaml | 2 +- packages/go_router/test_fixes/pubspec.yaml | 13 ---------- packages/go_router/tool/run_tests.dart | 28 ++++++++++++++++++---- 4 files changed, 35 insertions(+), 18 deletions(-) delete mode 100644 packages/go_router/test_fixes/pubspec.yaml diff --git a/packages/go_router/lib/fix_data.yaml b/packages/go_router/lib/fix_data.yaml index 4a31c08073b..18bdfedb66e 100644 --- a/packages/go_router/lib/fix_data.yaml +++ b/packages/go_router/lib/fix_data.yaml @@ -21,6 +21,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'replaceNamed' inClass: 'GoRouter' @@ -35,6 +36,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushReplacementNamed' inClass: 'GoRouter' @@ -50,6 +52,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushNamed' inClass: 'GoRouter' @@ -65,6 +68,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'goNamed' inClass: 'GoRouter' @@ -80,6 +84,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouter' @@ -95,6 +100,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouterState' @@ -110,6 +116,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'queryParams' inClass: 'GoRouterState' @@ -121,6 +128,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'fullpath' inClass: 'GoRouterState' @@ -132,6 +140,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'params' inClass: 'GoRouterState' @@ -143,6 +152,7 @@ transforms: date: 2023-04-24 bulkApply: true element: + # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'subloc' inClass: 'GoRouterState' diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 18da1517140..227507bcfde 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -23,4 +23,4 @@ dev_dependencies: sdk: flutter io: ^1.0.4 path: ^1.8.2 - yaml_edit: ^2.1.0 \ No newline at end of file + yaml_edit: ^2.1.0 diff --git a/packages/go_router/test_fixes/pubspec.yaml b/packages/go_router/test_fixes/pubspec.yaml deleted file mode 100644 index 34cc73fda16..00000000000 --- a/packages/go_router/test_fixes/pubspec.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: test_fixes -publish_to: "none" -version: 1.0.0+1 - -environment: - sdk: ">=2.18.0 <4.0.0" - flutter: ">=3.3.0" - -dependencies: - flutter: - sdk: flutter - go_router: - path: ../ diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index c4f6a282cd5..2b3998a37bc 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -23,7 +23,9 @@ Future main(List args) async { Directory(ctx.dirname(_ensureTrimLeadingSeparator(Platform.script.path))) .parent; - //copy from go_router/test_fixes to temp directory + // Copy test_fixes/ to be tested in a temp directory. + // This ensures the dart fix can be applied to project + // outside of this package. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); await _prepareTemplate( @@ -50,8 +52,12 @@ Future main(List args) async { ], workingDirectory: testFixesTargetDir.path, ); - - exit(status); + if (status != 0) { + exit(status); + } + //Cleanup temp folder + await testFixesTargetDir.delete(recursive: true); + exit(0); } Future _prepareTemplate({ @@ -63,8 +69,22 @@ Future _prepareTemplate({ final String pubspecYamlPath = ctx.join(testFixesTargetDir, 'pubspec.yaml'); final File targetPubspecPath = File(pubspecYamlPath); + const String initialYaml = ''' +name: test_fixes +publish_to: "none" +version: 1.0.0+1 + +environment: + sdk: ">=2.18.0 <4.0.0" + flutter: ">=3.3.0" - final YamlEditor editor = YamlEditor(await targetPubspecPath.readAsString()); +dependencies: + flutter: + sdk: flutter + go_router: + path: +'''; + final YamlEditor editor = YamlEditor(initialYaml); editor.update( ['dependencies', 'go_router', 'path'], ctx.dirname(testFixesDir), From 6b730cabd64d9068550429fb1a6d973d8d4edcfd Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 20:58:58 +0300 Subject: [PATCH 11/23] change comments --- packages/go_router/lib/fix_data.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/go_router/lib/fix_data.yaml b/packages/go_router/lib/fix_data.yaml index 18bdfedb66e..fb73a4fd743 100644 --- a/packages/go_router/lib/fix_data.yaml +++ b/packages/go_router/lib/fix_data.yaml @@ -21,7 +21,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'replaceNamed' inClass: 'GoRouter' @@ -36,7 +36,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushReplacementNamed' inClass: 'GoRouter' @@ -52,7 +52,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushNamed' inClass: 'GoRouter' @@ -68,7 +68,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'goNamed' inClass: 'GoRouter' @@ -84,7 +84,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouter' @@ -100,7 +100,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouterState' @@ -116,7 +116,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'queryParams' inClass: 'GoRouterState' @@ -128,7 +128,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'fullpath' inClass: 'GoRouterState' @@ -140,7 +140,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'params' inClass: 'GoRouterState' @@ -152,7 +152,7 @@ transforms: date: 2023-04-24 bulkApply: true element: - # todo: Workaround for https://github.com/dart-lang/sdk/issues/52233 + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'subloc' inClass: 'GoRouterState' From dc99f4734449e368792a0bc20835fc5aa369e28d Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 2 May 2023 21:26:31 +0300 Subject: [PATCH 12/23] allow io, yaml_edit since they are both dart owned --- script/configs/allowed_unpinned_deps.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index 7598a99afed..318ec7c7538 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -57,6 +57,8 @@ - vm_service - wasm - yaml +- io +- yaml_edit # Google-owned packages - adaptive_navigation - file From b0445fa99beb982889307ea62d0eec50d1250814 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Wed, 3 May 2023 02:47:36 +0300 Subject: [PATCH 13/23] cleanUp --- packages/go_router/tool/run_tests.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 2b3998a37bc..18dee6382fb 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -24,7 +24,7 @@ Future main(List args) async { .parent; // Copy test_fixes/ to be tested in a temp directory. - // This ensures the dart fix can be applied to project + // This ensures the dart fix can be applied to projects // outside of this package. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); @@ -42,7 +42,7 @@ Future main(List args) async { workingDirectory: testFixesTargetDir.path, ); if (pubGet != 0) { - exit(pubGet); + await cleanUpAndExit(statusCode: pubGet, toDelete: testFixesTargetDir); } final int status = await _runProcess( 'dart', @@ -53,11 +53,18 @@ Future main(List args) async { workingDirectory: testFixesTargetDir.path, ); if (status != 0) { - exit(status); + await cleanUpAndExit(statusCode: status, toDelete: testFixesTargetDir); } //Cleanup temp folder - await testFixesTargetDir.delete(recursive: true); - exit(0); + await cleanUpAndExit(statusCode: 0, toDelete: testFixesTargetDir); +} + +Future cleanUpAndExit({ + required int statusCode, + required Directory toDelete, +}) async { + await toDelete.delete(recursive: true); + exit(statusCode); } Future _prepareTemplate({ From 78a6b4d9b402b57c5d727b3cdf4b089d772a6204 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela <63286031+ahmednfwela@users.noreply.github.com> Date: Wed, 3 May 2023 22:13:22 +0300 Subject: [PATCH 14/23] Apply suggestions from code review Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> --- packages/go_router/CHANGELOG.md | 2 +- packages/go_router/tool/run_tests.dart | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 669a45c3ea7..ca33cc8a570 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,6 +1,6 @@ ## 7.0.1 -- Fixes the `dart fix --apply` command not working +- Adds a workaround for the `dart fix --apply` issue, https://github.com/dart-lang/sdk/issues/52233. ## 7.0.0 diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 18dee6382fb..ccc07b4b409 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -55,7 +55,6 @@ Future main(List args) async { if (status != 0) { await cleanUpAndExit(statusCode: status, toDelete: testFixesTargetDir); } - //Cleanup temp folder await cleanUpAndExit(statusCode: 0, toDelete: testFixesTargetDir); } From 78cb45c440804449fb8fa5ae44961b562b865cc6 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Thu, 4 May 2023 01:49:45 +0300 Subject: [PATCH 15/23] Trigger From 258871ff2435fde47e405b5999f6e9fc6a810d63 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Thu, 4 May 2023 20:02:44 +0300 Subject: [PATCH 16/23] reworked tests + added comments --- packages/go_router/pubspec.yaml | 1 - packages/go_router/tool/run_tests.dart | 93 ++++++++++------------- script/configs/allowed_unpinned_deps.yaml | 1 - 3 files changed, 42 insertions(+), 53 deletions(-) diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 227507bcfde..0104fca6eaf 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -23,4 +23,3 @@ dev_dependencies: sdk: flutter io: ^1.0.4 path: ^1.8.2 - yaml_edit: ^2.1.0 diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index ccc07b4b409..6c9b644732f 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -11,40 +11,53 @@ import 'dart:io'; import 'package:io/io.dart' as io; import 'package:path/path.dart' as p; -import 'package:yaml_edit/yaml_edit.dart'; +/// This test runner simulates a consumption of go_router that checks if +/// the breaking changes introduced in `V7.0.0` are applied correctly. +/// This is done by copying the `test_fixes/` directory to a temp directory +/// that references `go_router`, and running `dart fix --compare-to-golden` +/// on the temp directory Future main(List args) async { - if (!Platform.isMacOS && !Platform.isWindows) { - print('This test can only be run on macOS or windows.'); - exit(0); - } - final p.Context ctx = p.context; - final Directory packageRoot = - Directory(ctx.dirname(_ensureTrimLeadingSeparator(Platform.script.path))) - .parent; - - // Copy test_fixes/ to be tested in a temp directory. - // This ensures the dart fix can be applied to projects - // outside of this package. + /// The go_router directory + final Directory packageRoot = File.fromUri(Platform.script).parent.parent; + + // The src test_fixes directory + final Directory testFixesSrcDir = + Directory(p.join(packageRoot.path, 'test_fixes')); + // The target temp directory. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); + // Cleans up the temp directory and exits + // with a given statusCode + Future cleanUpAndExit(int statusCode) async { + await testFixesTargetDir.delete(recursive: true); + exit(statusCode); + } + + // Copies the test_fixes folder to the temporary testFixesTargetDir + // This also creates the proper pubspec.yaml in the temp directory await _prepareTemplate( - ctx: ctx, - testFixesDir: ctx.join(packageRoot.path, 'test_fixes'), + testFixesDir: testFixesSrcDir.path, testFixesTargetDir: testFixesTargetDir.path, ); - final int pubGet = await _runProcess( + + //Run dart pub get in the temp directory to set it up + final int pubGetStatusCode = await _runProcess( 'dart', [ 'pub', - 'upgrade', + 'get', ], workingDirectory: testFixesTargetDir.path, ); - if (pubGet != 0) { - await cleanUpAndExit(statusCode: pubGet, toDelete: testFixesTargetDir); + + if (pubGetStatusCode != 0) { + await cleanUpAndExit(pubGetStatusCode); } - final int status = await _runProcess( + + // This is the actual test that runs dart fix --compare-to-golden + // in the temp directory (the actual test) + final int dartFixStatusCode = await _runProcess( 'dart', [ 'fix', @@ -52,30 +65,22 @@ Future main(List args) async { ], workingDirectory: testFixesTargetDir.path, ); - if (status != 0) { - await cleanUpAndExit(statusCode: status, toDelete: testFixesTargetDir); - } - await cleanUpAndExit(statusCode: 0, toDelete: testFixesTargetDir); -} -Future cleanUpAndExit({ - required int statusCode, - required Directory toDelete, -}) async { - await toDelete.delete(recursive: true); - exit(statusCode); + await cleanUpAndExit(dartFixStatusCode); } Future _prepareTemplate({ required String testFixesDir, required String testFixesTargetDir, - required p.Context ctx, }) async { + //Copy from src `test_fixes/` to the temp directory await io.copyPath(testFixesDir, testFixesTargetDir); - final String pubspecYamlPath = ctx.join(testFixesTargetDir, 'pubspec.yaml'); - final File targetPubspecPath = File(pubspecYamlPath); - const String initialYaml = ''' + //The pubspec.yaml file to create + final File targetPubspecFile = + File(p.join(testFixesTargetDir, 'pubspec.yaml')); + + final String targetYaml = ''' name: test_fixes publish_to: "none" version: 1.0.0+1 @@ -88,24 +93,10 @@ dependencies: flutter: sdk: flutter go_router: - path: + path: ${p.dirname(testFixesDir)} '''; - final YamlEditor editor = YamlEditor(initialYaml); - editor.update( - ['dependencies', 'go_router', 'path'], - ctx.dirname(testFixesDir), - ); - final String newYaml = editor.toString(); - await targetPubspecPath.writeAsString(newYaml); -} -String _ensureTrimLeadingSeparator(String path) { - if (Platform.isWindows) { - if (path.startsWith('/')) { - return path.substring(1); - } - } - return path; + await targetPubspecFile.writeAsString(targetYaml); } Future _streamOutput(Future processFuture) async { diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index 318ec7c7538..45e46878273 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -58,7 +58,6 @@ - wasm - yaml - io -- yaml_edit # Google-owned packages - adaptive_navigation - file From 91e8973a674dc202b0a4a46918b7bad13c684919 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Thu, 4 May 2023 21:09:56 +0300 Subject: [PATCH 17/23] small refactor --- packages/go_router/tool/run_tests.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 6c9b644732f..424fc1e1fa3 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -21,9 +21,6 @@ Future main(List args) async { /// The go_router directory final Directory packageRoot = File.fromUri(Platform.script).parent.parent; - // The src test_fixes directory - final Directory testFixesSrcDir = - Directory(p.join(packageRoot.path, 'test_fixes')); // The target temp directory. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); @@ -37,7 +34,7 @@ Future main(List args) async { // Copies the test_fixes folder to the temporary testFixesTargetDir // This also creates the proper pubspec.yaml in the temp directory await _prepareTemplate( - testFixesDir: testFixesSrcDir.path, + packageRoot: packageRoot, testFixesTargetDir: testFixesTargetDir.path, ); @@ -70,11 +67,15 @@ Future main(List args) async { } Future _prepareTemplate({ - required String testFixesDir, + required Directory packageRoot, required String testFixesTargetDir, }) async { + // The src test_fixes directory + final Directory testFixesSrcDir = + Directory(p.join(packageRoot.path, 'test_fixes')); + //Copy from src `test_fixes/` to the temp directory - await io.copyPath(testFixesDir, testFixesTargetDir); + await io.copyPath(testFixesSrcDir.path, testFixesTargetDir); //The pubspec.yaml file to create final File targetPubspecFile = @@ -93,7 +94,7 @@ dependencies: flutter: sdk: flutter go_router: - path: ${p.dirname(testFixesDir)} + path: ${packageRoot.path} '''; await targetPubspecFile.writeAsString(targetYaml); From a836a06e16b982fe667d6e39930b75f89c783776 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Thu, 4 May 2023 21:34:23 +0300 Subject: [PATCH 18/23] dart format --- packages/go_router/tool/run_tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 424fc1e1fa3..a00d29cbe1f 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -73,7 +73,7 @@ Future _prepareTemplate({ // The src test_fixes directory final Directory testFixesSrcDir = Directory(p.join(packageRoot.path, 'test_fixes')); - + //Copy from src `test_fixes/` to the temp directory await io.copyPath(testFixesSrcDir.path, testFixesTargetDir); From 2c43ec509acaf92d8b5be371ff957319a2a45a46 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Fri, 5 May 2023 17:50:52 +0300 Subject: [PATCH 19/23] address comments --- packages/go_router/tool/run_tests.dart | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index a00d29cbe1f..afe35b0c237 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -16,29 +16,28 @@ import 'package:path/path.dart' as p; /// the breaking changes introduced in `V7.0.0` are applied correctly. /// This is done by copying the `test_fixes/` directory to a temp directory /// that references `go_router`, and running `dart fix --compare-to-golden` -/// on the temp directory +/// on the temp directory. Future main(List args) async { - /// The go_router directory + /// The go_router directory. final Directory packageRoot = File.fromUri(Platform.script).parent.parent; // The target temp directory. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); - // Cleans up the temp directory and exits - // with a given statusCode + // Cleans up the temp directory and exits with a given statusCode. Future cleanUpAndExit(int statusCode) async { await testFixesTargetDir.delete(recursive: true); exit(statusCode); } // Copies the test_fixes folder to the temporary testFixesTargetDir - // This also creates the proper pubspec.yaml in the temp directory + // This also creates the proper pubspec.yaml in the temp directory. await _prepareTemplate( packageRoot: packageRoot, - testFixesTargetDir: testFixesTargetDir.path, + testFixesTargetDir: testFixesTargetDir, ); - //Run dart pub get in the temp directory to set it up + // Run dart pub get in the temp directory to set it up. final int pubGetStatusCode = await _runProcess( 'dart', [ @@ -53,7 +52,7 @@ Future main(List args) async { } // This is the actual test that runs dart fix --compare-to-golden - // in the temp directory (the actual test) + // in the temp directory (the actual test). final int dartFixStatusCode = await _runProcess( 'dart', [ @@ -68,23 +67,23 @@ Future main(List args) async { Future _prepareTemplate({ required Directory packageRoot, - required String testFixesTargetDir, + required Directory testFixesTargetDir, }) async { - // The src test_fixes directory + // The src test_fixes directory. final Directory testFixesSrcDir = Directory(p.join(packageRoot.path, 'test_fixes')); - //Copy from src `test_fixes/` to the temp directory - await io.copyPath(testFixesSrcDir.path, testFixesTargetDir); + // Copy from src `test_fixes/` to the temp directory. + await io.copyPath(testFixesSrcDir.path, testFixesTargetDir.path); - //The pubspec.yaml file to create + // The pubspec.yaml file to create. final File targetPubspecFile = - File(p.join(testFixesTargetDir, 'pubspec.yaml')); + File(p.join(testFixesTargetDir.path, 'pubspec.yaml')); final String targetYaml = ''' name: test_fixes publish_to: "none" -version: 1.0.0+1 +version: 1.0.0 environment: sdk: ">=2.18.0 <4.0.0" From 70ad1c9b75a82ff4c645d3880799778da1bbc6c5 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Fri, 5 May 2023 22:41:16 +0300 Subject: [PATCH 20/23] Trigger CI From 11e168d4483f6206819d92720cc4eb7f0036dfea Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 9 May 2023 19:01:36 +0300 Subject: [PATCH 21/23] address review --- packages/go_router/tool/run_tests.dart | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index afe35b0c237..fcf3c4f19a9 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -12,14 +12,15 @@ import 'dart:io'; import 'package:io/io.dart' as io; import 'package:path/path.dart' as p; -/// This test runner simulates a consumption of go_router that checks if -/// the breaking changes introduced in `V7.0.0` are applied correctly. -/// This is done by copying the `test_fixes/` directory to a temp directory -/// that references `go_router`, and running `dart fix --compare-to-golden` -/// on the temp directory. +// This test runner simulates a consumption of go_router that checks if +// the dart fixes are applied correctly. +// This is done by copying the `test_fixes/` directory to a temp directory +// that references `go_router`, and running `dart fix --compare-to-golden` +// on the temp directory. Future main(List args) async { /// The go_router directory. - final Directory packageRoot = File.fromUri(Platform.script).parent.parent; + final Directory goRouterPackageRoot = + File.fromUri(Platform.script).parent.parent; // The target temp directory. final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); @@ -30,10 +31,11 @@ Future main(List args) async { exit(statusCode); } - // Copies the test_fixes folder to the temporary testFixesTargetDir + // Copy the test_fixes folder to the temporary testFixesTargetDir. + // // This also creates the proper pubspec.yaml in the temp directory. await _prepareTemplate( - packageRoot: packageRoot, + packageRoot: goRouterPackageRoot, testFixesTargetDir: testFixesTargetDir, ); @@ -51,8 +53,7 @@ Future main(List args) async { await cleanUpAndExit(pubGetStatusCode); } - // This is the actual test that runs dart fix --compare-to-golden - // in the temp directory (the actual test). + // Run dart fix --compare-to-golden in the temp directory. final int dartFixStatusCode = await _runProcess( 'dart', [ From 1bed8f87b752f3be6b53841faabb7320fc560d94 Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Tue, 9 May 2023 19:37:31 +0300 Subject: [PATCH 22/23] address review --- packages/go_router/tool/run_tests.dart | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index fcf3c4f19a9..7386de8426b 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -18,16 +18,14 @@ import 'package:path/path.dart' as p; // that references `go_router`, and running `dart fix --compare-to-golden` // on the temp directory. Future main(List args) async { - /// The go_router directory. final Directory goRouterPackageRoot = File.fromUri(Platform.script).parent.parent; - // The target temp directory. - final Directory testFixesTargetDir = await Directory.systemTemp.createTemp(); + final Directory testTempDir = await Directory.systemTemp.createTemp(); // Cleans up the temp directory and exits with a given statusCode. Future cleanUpAndExit(int statusCode) async { - await testFixesTargetDir.delete(recursive: true); + await testTempDir.delete(recursive: true); exit(statusCode); } @@ -36,7 +34,7 @@ Future main(List args) async { // This also creates the proper pubspec.yaml in the temp directory. await _prepareTemplate( packageRoot: goRouterPackageRoot, - testFixesTargetDir: testFixesTargetDir, + testTempDir: testTempDir, ); // Run dart pub get in the temp directory to set it up. @@ -46,7 +44,7 @@ Future main(List args) async { 'pub', 'get', ], - workingDirectory: testFixesTargetDir.path, + workingDirectory: testTempDir.path, ); if (pubGetStatusCode != 0) { @@ -60,7 +58,7 @@ Future main(List args) async { 'fix', '--compare-to-golden', ], - workingDirectory: testFixesTargetDir.path, + workingDirectory: testTempDir.path, ); await cleanUpAndExit(dartFixStatusCode); @@ -68,18 +66,18 @@ Future main(List args) async { Future _prepareTemplate({ required Directory packageRoot, - required Directory testFixesTargetDir, + required Directory testTempDir, }) async { // The src test_fixes directory. final Directory testFixesSrcDir = Directory(p.join(packageRoot.path, 'test_fixes')); // Copy from src `test_fixes/` to the temp directory. - await io.copyPath(testFixesSrcDir.path, testFixesTargetDir.path); + await io.copyPath(testFixesSrcDir.path, testTempDir.path); // The pubspec.yaml file to create. final File targetPubspecFile = - File(p.join(testFixesTargetDir.path, 'pubspec.yaml')); + File(p.join(testTempDir.path, 'pubspec.yaml')); final String targetYaml = ''' name: test_fixes From 219b9b0232327340f11d7a973a9c6b2adb458b6f Mon Sep 17 00:00:00 2001 From: Ahmed Fwela Date: Wed, 10 May 2023 21:42:09 +0300 Subject: [PATCH 23/23] format --- packages/go_router/tool/run_tests.dart | 3 +-- script/configs/allowed_unpinned_deps.yaml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 7386de8426b..58c689bf942 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -76,8 +76,7 @@ Future _prepareTemplate({ await io.copyPath(testFixesSrcDir.path, testTempDir.path); // The pubspec.yaml file to create. - final File targetPubspecFile = - File(p.join(testTempDir.path, 'pubspec.yaml')); + final File targetPubspecFile = File(p.join(testTempDir.path, 'pubspec.yaml')); final String targetYaml = ''' name: test_fixes diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index 45e46878273..1cf35c8881e 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -41,6 +41,7 @@ - html - http - intl +- io - js - json_serializable - lints @@ -57,7 +58,6 @@ - vm_service - wasm - yaml -- io # Google-owned packages - adaptive_navigation - file