Unverified Commit 6839b3cb authored by pdblasi-google's avatar pdblasi-google Committed by GitHub

Adds `dart_fix` support to `flutter_test` (#124347)

Adds `dart_fix` support to `flutter_test`
parent be2aa1c2
...@@ -927,7 +927,7 @@ Future<void> _runFrameworkTests() async { ...@@ -927,7 +927,7 @@ Future<void> _runFrameworkTests() async {
} }
} }
Future<void> runFixTests() async { Future<void> runFixTests(String package) async {
final List<String> args = <String>[ final List<String> args = <String>[
'fix', 'fix',
'--compare-to-golden', '--compare-to-golden',
...@@ -935,7 +935,7 @@ Future<void> _runFrameworkTests() async { ...@@ -935,7 +935,7 @@ Future<void> _runFrameworkTests() async {
await runCommand( await runCommand(
dart, dart,
args, args,
workingDirectory: path.join(flutterRoot, 'packages', 'flutter', 'test_fixes'), workingDirectory: path.join(flutterRoot, 'packages', package, 'test_fixes'),
); );
} }
...@@ -965,7 +965,8 @@ Future<void> _runFrameworkTests() async { ...@@ -965,7 +965,8 @@ Future<void> _runFrameworkTests() async {
Future<void> runSlow() async { Future<void> runSlow() async {
printProgress('${green}Running slow package tests$reset for directories other than packages/flutter'); printProgress('${green}Running slow package tests$reset for directories other than packages/flutter');
await runTracingTests(); await runTracingTests();
await runFixTests(); await runFixTests('flutter');
await runFixTests('flutter_test');
await runPrivateTests(); await runPrivateTests();
} }
......
...@@ -5,7 +5,7 @@ define the [`dart fix` framework](https://dart.dev/tools/dart-fix) refactorings ...@@ -5,7 +5,7 @@ define the [`dart fix` framework](https://dart.dev/tools/dart-fix) refactorings
used by the Flutter framework. used by the Flutter framework.
The number of fix rules defined in a file should not exceed 50 for better The number of fix rules defined in a file should not exceed 50 for better
maintainability. Searching for `title:` is a given `.yaml` file will account 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. for the number of fixes. Splitting out fix rules should be done by class.
When adding a new `.yaml` file, make a copy of `fix_template.yaml`. If the new When adding a new `.yaml` file, make a copy of `fix_template.yaml`. If the new
......
include: ../analysis_options.yaml
analyzer:
exclude:
- "test_fixes/**"
## 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_test`.
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_<class>.yaml`. To make sure each file is
grouped with related classes, a `fix_<filename>` folder will contain all of the
fix files for the individual classes.
See the flutter/packages/flutter_test/test_fixes directory for the tests that
validate these fix rules.
To run these tests locally, execute this command in the
flutter/packages/flutter_test/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_test, 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.
# 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_test/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.
# * Fixes in this file are for AnimationSheetBuilder from the flutter_test/animation_sheet.dart file. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/83337
# The related deprecation for `sheetSize` doesn't have a fix because there
# isn't an alternative API, it's being removed completely.
- title: 'Migrate to collate'
date: 2023-03-29
element:
uris: [ 'flutter_test.dart' ]
method: 'display'
inClass: 'AnimationSheetBuilder'
changes:
- kind: 'rename'
newName: 'collate'
- kind: 'removeParameter'
name: 'key'
- kind: 'addParameter'
index: 0
name: 'cellsPerRow'
style: 'required_positional'
argumentValue:
expression: '1'
# 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_test/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.
# * Fixes in this file are for AutomatedTestWidgetsFlutterBinding from the flutter_test/binding.dart file. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/89952
- title: "Remove timeout"
date: 2023-03-30
element:
uris: [ 'flutter_test.dart' ]
method: 'runTest'
inClass: 'AutomatedTestWidgetsFlutterBinding'
changes:
- kind: 'removeParameter'
name: 'timeout'
# 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_test/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.
# * Fixes in this file are for LiveTestWidgetsFlutterBinding from the flutter_test/binding.dart file. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/89952
- title: "Remove timeout"
date: 2023-03-30
element:
uris: [ 'flutter_test.dart' ]
method: 'runTest'
inClass: 'LiveTestWidgetsFlutterBinding'
changes:
- kind: 'removeParameter'
name: 'timeout'
# 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_test/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.
# * Fixes in this file are for TestWidgetsFlutterBinding from the flutter_test/binding.dart file. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/89952
- title: "Remove timeout"
date: 2023-03-30
element:
uris: [ 'flutter_test.dart' ]
method: 'runTest'
inClass: 'TestWidgetsFlutterBinding'
changes:
- kind: 'removeParameter'
name: 'timeout'
# Changes made in https://github.com/flutter/flutter/pull/89952
# The related deprecation for `addTime` doesn't have a fix as the method is
# being removed completely.
- title: "Remove additionalTime"
date: 2023-03-30
element:
uris: [ 'flutter_test.dart' ]
method: 'runAsync'
inClass: 'TestWidgetsFlutterBinding'
changes:
- kind: 'removeParameter'
name: 'additionalTime'
# 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_test/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.
# * Fixes in this file are for the flutter_test/widget_tester.dart file. *
version: 1
transforms:
# Changes made in https://github.com/flutter/flutter/pull/89952
- title: "Migrate to timeout"
date: 2023-03-30
element:
uris: [ 'flutter_test.dart' ]
function: 'testWidgets'
oneOf:
- if: "initialTimeout != '' && timeout == ''"
changes:
- kind: 'addParameter'
index: 3
name: 'timeout'
style: optional_named
argumentValue:
expression: 'Timeout({% initialTimeout %})'
requiredIf: "initialTimeout != '' && timeout == ''"
- kind: 'removeParameter'
name: 'initialTimeout'
- if: "initialTimeout != '' && timeout != ''"
changes:
- kind: 'removeParameter'
name: 'initialTimeout'
variables:
initialTimeout:
kind: 'fragment'
value: 'arguments[initialTimeout]'
timeout:
kind: 'fragment'
value: 'arguments[timeout]'
# 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_test/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 <XXX> library. *
# Uncomment version & transforms, and follow with fixes.
# version: 1
# transforms:
# Before adding a new fix: read instructions at the top of this file.
...@@ -759,6 +759,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -759,6 +759,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. ' 'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. '
'This feature was deprecated after v2.6.0-1.0.pre.' 'This feature was deprecated after v2.6.0-1.0.pre.'
) )
// TODO(pdblasi-google): Do not remove until https://github.com/flutter/flutter/issues/124346
// is complete, as this removal will cascade into `integration_test`
Duration? timeout, Duration? timeout,
}); });
...@@ -1430,6 +1432,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1430,6 +1432,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. ' 'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. '
'This feature was deprecated after v2.6.0-1.0.pre.' 'This feature was deprecated after v2.6.0-1.0.pre.'
) )
// TODO(pdblasi-google): Do not remove until https://github.com/flutter/flutter/issues/124346
// is complete, as this removal will cascade into `integration_test`
Duration? timeout, Duration? timeout,
}) { }) {
assert(!inTest); assert(!inTest);
...@@ -1927,6 +1931,8 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1927,6 +1931,8 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. ' 'This parameter has no effect. Use the `timeout` parameter on `testWidgets` instead. '
'This feature was deprecated after v2.6.0-1.0.pre.' 'This feature was deprecated after v2.6.0-1.0.pre.'
) )
// TODO(pdblasi-google): Do not remove until https://github.com/flutter/flutter/issues/124346
// is complete, as this removal will cascade into `integration_test`
Duration? timeout, Duration? timeout,
}) { }) {
assert(!inTest); assert(!inTest);
......
# This ensures that parent analysis options do not accidentally break the fix tests.
// 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('test', (WidgetTester tester) async {
final AnimationSheetBuilder animationSheet =
AnimationSheetBuilder(frameSize: const Size(48, 24));
// This line will remain unchanged as there is no replacement for the
// `sheetSize` API.
tester.binding.setSurfaceSize(animationSheet.sheetSize());
// These lines will replace the calls to `display` with a call to `collate`
// but will still have a build error.
// Changes made in https://github.com/flutter/flutter/pull/83337
final Widget display = await animationSheet.display();
final Widget display2 = await animationSheet.display(key: UniqueKey());
});
}
// 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('test', (WidgetTester tester) async {
final AnimationSheetBuilder animationSheet =
AnimationSheetBuilder(frameSize: const Size(48, 24));
// This line will remain unchanged as there is no replacement for the
// `sheetSize` API.
tester.binding.setSurfaceSize(animationSheet.sheetSize());
// These lines will replace the calls to `display` with a call to `collate`
// but will still have a build error.
// Changes made in https://github.com/flutter/flutter/pull/83337
final Widget display = await animationSheet.collate(1);
final Widget display2 = await animationSheet.collate(1);
});
}
// 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_test/flutter_test.dart';
void main() {
final binding = AutomatedTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async { },
() { },
// Changes made in https://github.com/flutter/flutter/pull/89952
timeout: Duration(minutes: 30),
);
}
// 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_test/flutter_test.dart';
void main() {
final binding = AutomatedTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async { },
() { },
);
}
// 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_test/flutter_test.dart';
void main() {
final binding = LiveTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async { },
() { },
// Changes made in https://github.com/flutter/flutter/pull/89952
timeout: Duration(minutes: 30),
);
}
// 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_test/flutter_test.dart';
void main() {
final binding = LiveTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async { },
() { },
);
}
// 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 'dart:ui';
import 'package:clock/src/clock.dart';
import 'package:flutter_test/flutter_test.dart';
void main() async {
TestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async {
// This will be unchanged as there is no equivalent API.
binding.addTime(Duration(seconds: 30));
await binding.runAsync(
() async {},
// Changes made in https://github.com/flutter/flutter/pull/89952
additionalTime: Duration(seconds: 25),
);
},
() { },
// This timeout will be removed and not replaced since there is no
// equivalent API at this layer.
timeout: Duration(minutes: 30),
);
}
// 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_test/flutter_test.dart';
void main() async {
TestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding.ensureInitialized();
binding.runTest(
() async {
// This will be unchanged as there is no equivalent API.
binding.addTime(Duration(seconds: 30));
await binding.runAsync(
() async {},
);
},
() { },
);
}
// 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_test/flutter_test.dart';
void main() {
testWidgets('test', (WidgetTester tester) async {
// This call will be unchanged
// Changes made in https://github.com/flutter/flutter/pull/89952
}, timeout: Timeout(Duration(hours: 1)));
testWidgets('test', (WidgetTester tester) async {
// The `timeout` will remain unchanged, but `initialTimeout` will be removed
// Changes made in https://github.com/flutter/flutter/pull/89952
},
timeout: Timeout(Duration(minutes: 45)),
initialTimeout: Duration(minutes: 30));
testWidgets('test', (WidgetTester tester) async {
// initialTimeout will be wrapped in a Timeout and changed to `timeout`
// Changes made in https://github.com/flutter/flutter/pull/89952
}, initialTimeout: Duration(seconds: 30));
}
// 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_test/flutter_test.dart';
void main() {
testWidgets('test', (WidgetTester tester) async {
// This call will be unchanged
// Changes made in https://github.com/flutter/flutter/pull/89952
}, timeout: Timeout(Duration(hours: 1)));
testWidgets('test', (WidgetTester tester) async {
// The `timeout` will remain unchanged, but `initialTimeout` will be removed
// Changes made in https://github.com/flutter/flutter/pull/89952
},
timeout: Timeout(Duration(minutes: 45)));
testWidgets('test', (WidgetTester tester) async {
// initialTimeout will be wrapped in a Timeout and changed to `timeout`
// Changes made in https://github.com/flutter/flutter/pull/89952
}, timeout: Timeout(Duration(seconds: 30)));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment