From 9785718031dc0a4213b1c491fa8bb8d0516a9be2 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Wed, 10 Jan 2024 18:07:49 -0600 Subject: [PATCH] Add dart fix support to flutter_driver (#141300) Part of https://github.com/flutter/flutter/issues/139249 This adds dart fix support plus fixes for APIs that are currently deprecated in the flutter_driver package. --- dev/bots/test.dart | 1 + packages/flutter_driver/analysis_options.yaml | 5 ++ .../flutter_driver/lib/fix_data/README.md | 45 ++++++++++++++++++ .../fix_data/fix_flutter_driver/fix_data.yaml | 47 +++++++++++++++++++ .../flutter_driver/lib/fix_data/template.yaml | 25 ++++++++++ .../flutter_driver/test_fixes/.dartignore | 0 packages/flutter_driver/test_fixes/README.md | 33 +++++++++++++ .../test_fixes/analysis_options.yaml | 1 + .../flutter_driver/flutter_driver.dart | 20 ++++++++ .../flutter_driver/flutter_driver.dart.expect | 20 ++++++++ 10 files changed, 197 insertions(+) create mode 100644 packages/flutter_driver/analysis_options.yaml create mode 100644 packages/flutter_driver/lib/fix_data/README.md create mode 100644 packages/flutter_driver/lib/fix_data/fix_flutter_driver/fix_data.yaml create mode 100644 packages/flutter_driver/lib/fix_data/template.yaml create mode 100644 packages/flutter_driver/test_fixes/.dartignore create mode 100644 packages/flutter_driver/test_fixes/README.md create mode 100644 packages/flutter_driver/test_fixes/analysis_options.yaml create mode 100644 packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart create mode 100644 packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart.expect diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 88483126b2..accb331ef2 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -984,6 +984,7 @@ Future _runFrameworkTests() async { await runFixTests('flutter'); await runFixTests('flutter_test'); await runFixTests('integration_test'); + await runFixTests('flutter_driver'); await runPrivateTests(); } diff --git a/packages/flutter_driver/analysis_options.yaml b/packages/flutter_driver/analysis_options.yaml new file mode 100644 index 0000000000..a48f475e03 --- /dev/null +++ b/packages/flutter_driver/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../analysis_options.yaml + +analyzer: + exclude: + - "test_fixes/**" diff --git a/packages/flutter_driver/lib/fix_data/README.md b/packages/flutter_driver/lib/fix_data/README.md new file mode 100644 index 0000000000..1060b4de6e --- /dev/null +++ b/packages/flutter_driver/lib/fix_data/README.md @@ -0,0 +1,45 @@ +## Directory contents + +The `.yaml` files in these directories are used to +define the [`dart fix` framework](https://dart.dev/tools/dart-fix) refactorings +used by `flutter_driver`. + +The number of fix rules defined in a file should not exceed 50 for better +maintainability. Searching for `title:` in a given `.yaml` file will account +for the number of fixes. Splitting out fix rules should be done by class. + +When adding a new `.yaml` file, make a copy of `template.yaml`. Each file should +be for a single class and named `fix_.yaml`. To make sure each file is +grouped with related classes, a `fix_` folder will contain all of the +fix files for the individual classes. + +See the flutter/packages/flutter_driver/test_fixes directory for the tests that +validate these fix rules. + +To run these tests locally, execute this command in the +flutter/packages/flutter_driver/test_fixes directory. +```sh +dart fix --compare-to-golden +``` + +For more documentation about Data Driven Fixes, see +https://dart.dev/go/data-driven-fixes#test-folder. + +To learn more about how fixes are authored in package:flutter_driver, see +https://github.com/flutter/flutter/wiki/Data-driven-Fixes + +## When making structural changes to this directory + +The tests in this directory are also invoked from external +repositories. Specifically, the CI system for the dart-lang/sdk repo +runs these tests in order to ensure that changes to the dart fix file +format do not break Flutter. + +See [tools/bots/flutter/analyze_flutter_flutter.sh](https://github.com/dart-lang/sdk/blob/main/tools/bots/flutter/analyze_flutter_flutter.sh) +for where the flutter fix tests are invoked for the dart repo. + +See [dev/bots/test.dart](https://github.com/flutter/flutter/blob/master/dev/bots/test.dart) +for where the flutter fix tests are invoked for the flutter/flutter repo. + +When possible, please coordinate changes to this directory that might affect the +`analyze_flutter_flutter.sh` script. diff --git a/packages/flutter_driver/lib/fix_data/fix_flutter_driver/fix_data.yaml b/packages/flutter_driver/lib/fix_data/fix_flutter_driver/fix_data.yaml new file mode 100644 index 0000000000..41df9815aa --- /dev/null +++ b/packages/flutter_driver/lib/fix_data/fix_flutter_driver/fix_data.yaml @@ -0,0 +1,47 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the +# flutter/packages/flutter_driver/test_fixes/README.md file for instructions +# on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +version: 1 +transforms: +# Changes made in https://github.com/flutter/flutter/pull/82939 +- title: 'Migrate to setSemantics' + date: 2024-01-10 + element: + uris: [ 'flutter_driver.dart' ] + method: 'enableAccessibility' + inClass: 'FlutterDriver' + changes: + - kind: 'rename' + newName: 'setSemantics' + - kind: 'addParameter' + index: 0 + name: 'enabled' + style: 'required_positional' + argumentValue: + expression: 'true' + +# Changes made in https://github.com/flutter/flutter/pull/79310 +- title: 'Migrate to writeTimelineToFile' + date: 2024-01-10 + element: + uris: [ 'flutter_driver.dart' ] + method: 'writeSummaryToFile' + inClass: 'TimelineSummary' + changes: + - kind: 'rename' + newName: 'writeTimelineToFile' diff --git a/packages/flutter_driver/lib/fix_data/template.yaml b/packages/flutter_driver/lib/fix_data/template.yaml new file mode 100644 index 0000000000..9d21247cba --- /dev/null +++ b/packages/flutter_driver/lib/fix_data/template.yaml @@ -0,0 +1,25 @@ +# Copyright 2014 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# For details regarding the *Flutter Fix* feature, see +# https://flutter.dev/docs/development/tools/flutter-fix + +# Please add new fixes to the top of the file, separated by one blank line +# from other fixes. In a comment, include a link to the PR where the change +# requiring the fix was made. + +# Every fix must be tested. See the +# flutter/packages/flutter_driver/lib/fix_data/README.md file for instructions +# on testing these data driven fixes. + +# For documentation about this file format, see +# https://dart.dev/go/data-driven-fixes. + +# * Fixes in this file are [for CLASS] from the library. * + +# Uncomment version & transforms, and follow with fixes. +# version: 1 +# transforms: + +# Before adding a new fix: read instructions at the top of this file. diff --git a/packages/flutter_driver/test_fixes/.dartignore b/packages/flutter_driver/test_fixes/.dartignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/flutter_driver/test_fixes/README.md b/packages/flutter_driver/test_fixes/README.md new file mode 100644 index 0000000000..647be4469a --- /dev/null +++ b/packages/flutter_driver/test_fixes/README.md @@ -0,0 +1,33 @@ +## Directory contents + +The Dart files and golden master `.expect` files in this directory are used to +test the [`dart fix` framework](https://dart.dev/tools/dart-fix) refactorings +used by the Flutter framework. + +See the flutter/packages/flutter_driver/lib/fix_data directory for the current +package:flutter data-driven fixes. + +To run these tests locally, execute this command in the +flutter/packages/flutter_driver/test_fixes directory. +```sh +dart fix --compare-to-golden +``` + +For more documentation about Data Driven Fixes, see +https://dart.dev/go/data-driven-fixes#test-folder. + +To learn more about how fixes are authored in package:flutter, see +https://github.com/flutter/flutter/wiki/Data-driven-Fixes + +## When making structural changes to this directory + +The tests in this directory are also invoked from external +repositories. Specifically, the CI system for the dart-lang/sdk repo +runs these tests in order to ensure that changes to the dart fix file +format do not break Flutter. + +See [tools/bots/flutter/analyze_flutter_flutter.sh](https://github.com/dart-lang/sdk/blob/main/tools/bots/flutter/analyze_flutter_flutter.sh) +for where the tests are invoked. + +When possible, please coordinate changes to this directory that might affect the +`analyze_flutter_flutter.sh` script. diff --git a/packages/flutter_driver/test_fixes/analysis_options.yaml b/packages/flutter_driver/test_fixes/analysis_options.yaml new file mode 100644 index 0000000000..7cca7b1d5c --- /dev/null +++ b/packages/flutter_driver/test_fixes/analysis_options.yaml @@ -0,0 +1 @@ +# This ensures that parent analysis options do not accidentally break the fix tests. diff --git a/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart b/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart new file mode 100644 index 0000000000..32622390f4 --- /dev/null +++ b/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart @@ -0,0 +1,20 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/flutter_driver.dart'; + +void main() async { + // Changes made in https://github.com/flutter/flutter/pull/82939 + final FlutterDriver driver = FlutterDriver(); + await driver.enableAccessibility(); + + // Changes made in https://github.com/flutter/flutter/pull/79310 + final Timeline timeline = Timeline.fromJson({}); + TimelineSummary.summarize(timeline).writeSummaryToFile('traceName'); + TimelineSummary.summarize(timeline).writeSummaryToFile( + 'traceName', + destinationDirectory: 'destination', + pretty: false, + ); +} diff --git a/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart.expect b/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart.expect new file mode 100644 index 0000000000..3a82efc95c --- /dev/null +++ b/packages/flutter_driver/test_fixes/flutter_driver/flutter_driver.dart.expect @@ -0,0 +1,20 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_driver/flutter_driver.dart'; + +void main() async { + // Changes made in https://github.com/flutter/flutter/pull/82939 + final FlutterDriver driver = FlutterDriver(); + await driver.setSemantics(true); + + // Changes made in https://github.com/flutter/flutter/pull/79310 + final Timeline timeline = Timeline.fromJson({}); + TimelineSummary.summarize(timeline).writeTimelineToFile('traceName'); + TimelineSummary.summarize(timeline).writeTimelineToFile( + 'traceName', + destinationDirectory: 'destination', + pretty: false, + ); +}