Declare locals final where not reassigned (flutter_test) (#8569)

This commit is contained in:
Chris Bracken
2017-03-03 17:51:01 -08:00
committed by GitHub
parent 7a09316cd0
commit 895f3e6350
12 changed files with 67 additions and 67 deletions

View File

@@ -154,7 +154,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
Future<Null> setLocale(String languageCode, String countryCode) {
return TestAsyncUtils.guard(() async {
assert(inTest);
Locale locale = new Locale(languageCode, countryCode);
final Locale locale = new Locale(languageCode, countryCode);
dispatchLocaleChanged(locale);
return null;
});
@@ -220,7 +220,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
/// null in that case.
dynamic takeException() {
assert(inTest);
dynamic result = _pendingExceptionDetails?.exception;
final dynamic result = _pendingExceptionDetails?.exception;
_pendingExceptionDetails = null;
return result;
}
@@ -315,7 +315,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}
};
_currentTestCompleter = new Completer<Null>();
ZoneSpecification errorHandlingZoneSpecification = new ZoneSpecification(
final ZoneSpecification errorHandlingZoneSpecification = new ZoneSpecification(
handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone, dynamic exception, StackTrace stack) {
if (_currentTestCompleter.isCompleted) {
// Well this is not a good sign.
@@ -388,7 +388,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}
);
_parentZone = Zone.current;
Zone testZone = _parentZone.fork(specification: errorHandlingZoneSpecification);
final Zone testZone = _parentZone.fork(specification: errorHandlingZoneSpecification);
testZone.runBinaryGuarded(_runTestBody, testBody, invariantTester)
.whenComplete(_testCompletionHandler);
asyncBarrier(); // When using AutomatedTestWidgetsFlutterBinding, this flushes the microtasks.
@@ -498,7 +498,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
Future<Null> idle() {
Future<Null> result = super.idle();
final Future<Null> result = super.idle();
_fakeAsync.flushMicrotasks();
return result;
}
@@ -755,16 +755,16 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
Point globalToLocal(Point point) {
Matrix4 transform = renderView.configuration.toHitTestMatrix();
double det = transform.invert();
final Matrix4 transform = renderView.configuration.toHitTestMatrix();
final double det = transform.invert();
assert(det != 0.0);
Point result = MatrixUtils.transformPoint(transform, point);
final Point result = MatrixUtils.transformPoint(transform, point);
return result;
}
@override
Point localToGlobal(Point point) {
Matrix4 transform = renderView.configuration.toHitTestMatrix();
final Matrix4 transform = renderView.configuration.toHitTestMatrix();
return MatrixUtils.transformPoint(transform, point);
}
}
@@ -853,8 +853,8 @@ class _LiveTestRenderView extends RenderView {
@override
bool hitTest(HitTestResult result, { Point position }) {
Matrix4 transform = configuration.toHitTestMatrix();
double det = transform.invert();
final Matrix4 transform = configuration.toHitTestMatrix();
final double det = transform.invert();
assert(det != 0.0);
position = MatrixUtils.transformPoint(transform, position);
return super.hitTest(result, position: position);
@@ -878,7 +878,7 @@ class _LiveTestRenderView extends RenderView {
..style = PaintingStyle.stroke;
bool dirty = false;
for (int pointer in _pointers.keys) {
_LiveTestPointerRecord record = _pointers[pointer];
final _LiveTestPointerRecord record = _pointers[pointer];
paint.color = record.color.withOpacity(record.decay < 0 ? (record.decay / (_kPointerDecay - 1)) : 1.0);
canvas.drawPath(path.shift(record.position.toOffset()), paint);
if (record.decay < 0)

View File

@@ -75,7 +75,7 @@ class WidgetController {
Iterable<T> widgetList<T extends Widget>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().map<T>((Element element) {
T result = element.widget;
final T result = element.widget;
return result;
});
}
@@ -223,7 +223,7 @@ class WidgetController {
Iterable<T> renderObjectList<T extends RenderObject>(Finder finder) {
TestAsyncUtils.guardSync();
return finder.evaluate().map<T>((Element element) {
T result = element.renderObject;
final T result = element.renderObject;
return result;
});
}
@@ -235,7 +235,7 @@ class WidgetController {
TestAsyncUtils.guardSync();
yield layer;
if (layer is ContainerLayer) {
ContainerLayer root = layer;
final ContainerLayer root = layer;
Layer child = root.firstChild;
while (child != null) {
yield* _walkLayers(child);
@@ -259,7 +259,7 @@ class WidgetController {
/// location.
Future<Null> tapAt(Point location, { int pointer: 1 }) {
return TestAsyncUtils.guard(() async {
TestGesture gesture = await startGesture(location, pointer: pointer);
final TestGesture gesture = await startGesture(location, pointer: pointer);
await gesture.up();
return null;
});
@@ -278,7 +278,7 @@ class WidgetController {
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
Future<Null> longPressAt(Point location, { int pointer: 1 }) {
return TestAsyncUtils.guard(() async {
TestGesture gesture = await startGesture(location, pointer: pointer);
final TestGesture gesture = await startGesture(location, pointer: pointer);
await pump(kLongPressTimeout + kPressTimeout);
await gesture.up();
return null;
@@ -360,7 +360,7 @@ class WidgetController {
/// the given offset, and a pointer up.
Future<Null> scrollAt(Point startLocation, Offset offset, { int pointer: 1 }) {
return TestAsyncUtils.guard(() async {
TestGesture gesture = await startGesture(startLocation, pointer: pointer);
final TestGesture gesture = await startGesture(startLocation, pointer: pointer);
await gesture.moveBy(offset);
await gesture.up();
return null;
@@ -421,8 +421,8 @@ class WidgetController {
Point _getElementPoint(Finder finder, Point sizeToPoint(Size size)) {
TestAsyncUtils.guardSync();
Element element = finder.evaluate().single;
RenderBox box = element.renderObject;
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;
assert(box != null);
return box.localToGlobal(sizeToPoint(box.size));
}
@@ -431,8 +431,8 @@ class WidgetController {
/// the widget's render object has been laid out at least once.
Size getSize(Finder finder) {
TestAsyncUtils.guardSync();
Element element = finder.evaluate().single;
RenderBox box = element.renderObject;
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;
assert(box != null);
return box.size;
}

View File

@@ -341,7 +341,7 @@ class _TextFinder extends MatchFinder {
bool matches(Element candidate) {
if (candidate.widget is! Text)
return false;
Text textWidget = candidate.widget;
final Text textWidget = candidate.widget;
return textWidget.data == text;
}
}
@@ -358,7 +358,7 @@ class _IconFinder extends MatchFinder {
bool matches(Element candidate) {
if (candidate.widget is! Icon)
return false;
Icon iconWidget = candidate.widget;
final Icon iconWidget = candidate.widget;
return iconWidget.icon == icon;
}
}
@@ -379,7 +379,7 @@ class _WidgetWithTextFinder extends Finder {
if (textElement.widget is! Text)
return null;
Text textWidget = textElement.widget;
final Text textWidget = textElement.widget;
if (textWidget.data == text) {
try {
textElement.visitAncestorElements((Element element) {

View File

@@ -100,7 +100,7 @@ class _FindsWidgetMatcher extends Matcher {
assert(min == null || max == null || min <= max);
matchState[Finder] = finder;
int count = 0;
Iterator<Element> iterator = finder.evaluate().iterator;
final Iterator<Element> iterator = finder.evaluate().iterator;
if (min != null) {
while (count < min && iterator.moveNext())
count += 1;
@@ -146,8 +146,8 @@ class _FindsWidgetMatcher extends Matcher {
Map<dynamic, dynamic> matchState,
bool verbose
) {
Finder finder = matchState[Finder];
int count = finder.evaluate().length;
final Finder finder = matchState[Finder];
final int count = finder.evaluate().length;
if (count == 0) {
assert(min != null && min > 0);
if (min == 1 && max == 1)
@@ -167,7 +167,7 @@ class _FindsWidgetMatcher extends Matcher {
}
bool _hasAncestorMatching(Finder finder, bool predicate(Widget widget)) {
Iterable<Element> nodes = finder.evaluate();
final Iterable<Element> nodes = finder.evaluate();
if (nodes.length != 1)
return false;
bool result = false;
@@ -206,12 +206,12 @@ class _IsOnstage extends Matcher {
@override
bool matches(covariant Finder finder, Map<dynamic, dynamic> matchState) {
Iterable<Element> nodes = finder.evaluate();
final Iterable<Element> nodes = finder.evaluate();
if (nodes.length != 1)
return false;
bool result = true;
nodes.single.visitAncestorElements((Element ancestor) {
Widget widget = ancestor.widget;
final Widget widget = ancestor.widget;
if (widget is Offstage) {
result = !widget.offstage;
return false;
@@ -250,7 +250,7 @@ class _HasOneLineDescription extends Matcher {
@override
bool matches(Object object, Map<dynamic, dynamic> matchState) {
String description = object.toString();
final String description = object.toString();
return description.isNotEmpty
&& !description.contains('\n')
&& !description.contains('Instance of ')

View File

@@ -23,7 +23,7 @@ int reportExpectCall(StackTrace stack, StringBuffer information) {
line2.firstMatch(stackLines[2]) != null &&
line3.firstMatch(stackLines[3]) != null
) {
Match expectMatch = line4.firstMatch(stackLines[4]);
final Match expectMatch = line4.firstMatch(stackLines[4]);
assert(expectMatch != null);
assert(expectMatch.groupCount == 2);
information.writeln('This was caught by the test expectation on the following line:');
@@ -31,4 +31,4 @@ int reportExpectCall(StackTrace stack, StringBuffer information) {
return 4;
}
return 0;
}
}

View File

@@ -59,20 +59,20 @@ class TestAsyncUtils {
/// This method first calls [guardSync].
static Future<Null> guard(Future<Null> body()) {
guardSync();
Zone zone = Zone.current.fork(
final Zone zone = Zone.current.fork(
zoneValues: <dynamic, dynamic>{
_scopeStack: true // so we can recognize this as our own zone
}
);
_AsyncScope scope = new _AsyncScope(StackTrace.current, zone);
final _AsyncScope scope = new _AsyncScope(StackTrace.current, zone);
_scopeStack.add(scope);
Future<Null> result = scope.zone.run(body);
final Future<Null> result = scope.zone.run(body);
void completionHandler(dynamic error, StackTrace stack) {
assert(_scopeStack.isNotEmpty);
assert(_scopeStack.contains(scope));
bool leaked = false;
_AsyncScope closedScope;
StringBuffer message = new StringBuffer();
final StringBuffer message = new StringBuffer();
while (_scopeStack.isNotEmpty) {
closedScope = _scopeStack.removeLast();
if (closedScope == scope)
@@ -177,7 +177,7 @@ class TestAsyncUtils {
assert(candidateScope.zone != null);
} while (candidateScope.zone != zone);
assert(scope != null);
StringBuffer message = new StringBuffer();
final StringBuffer message = new StringBuffer();
message.writeln('Guarded function conflict. You must use "await" with all Future-returning test APIs.');
final _StackEntry originalGuarder = _findResponsibleMethod(scope.creationStack, 'guard', message);
final _StackEntry collidingGuarder = _findResponsibleMethod(StackTrace.current, 'guardSync', message);
@@ -261,7 +261,7 @@ class TestAsyncUtils {
/// This is used at the end of tests to ensure that nothing leaks out of the test.
static void verifyAllScopesClosed() {
if (_scopeStack.isNotEmpty) {
StringBuffer message = new StringBuffer();
final StringBuffer message = new StringBuffer();
message.writeln('Asynchronous call to guarded function leaked. You must use "await" with all Future-returning test APIs.');
for (_AsyncScope scope in _scopeStack) {
final _StackEntry guarder = _findResponsibleMethod(scope.creationStack, 'guard', message);

View File

@@ -61,7 +61,7 @@ class TestPointer {
/// argument.
PointerMoveEvent move(Point newLocation, { Duration timeStamp: Duration.ZERO }) {
assert(isDown);
Offset delta = newLocation - location;
final Offset delta = newLocation - location;
_location = newLocation;
return new PointerMoveEvent(
timeStamp: timeStamp,

View File

@@ -44,11 +44,11 @@ class TestTextInput {
void updateEditingState(TextEditingState state) {
expect(_client, isNonZero);
String message = JSON.encode(<String, dynamic>{
final String message = JSON.encode(<String, dynamic>{
'method': 'TextInputClient.updateEditingState',
'args': <dynamic>[_client, state.toJSON()],
});
Uint8List encoded = UTF8.encoder.convert(message);
final Uint8List encoded = UTF8.encoder.convert(message);
PlatformMessages.handlePlatformMessage(
_kTextInputClientChannel, encoded.buffer.asByteData(), (_) {});
}

View File

@@ -47,8 +47,8 @@ void testWidgets(String description, WidgetTesterCallback callback, {
bool skip: false,
test_package.Timeout timeout
}) {
TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
WidgetTester tester = new WidgetTester._(binding);
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final WidgetTester tester = new WidgetTester._(binding);
timeout ??= binding.defaultTestTimeout;
test_package.group('-', () {
test_package.test(description, () => binding.runTest(() => callback(tester), tester._endOfTestVerifications), skip: skip);
@@ -106,9 +106,9 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
print('└─────────────────────────────────────────────────╌┄┈ 🐢');
return true;
});
TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
assert(binding is! AutomatedTestWidgetsFlutterBinding);
WidgetTester tester = new WidgetTester._(binding);
final WidgetTester tester = new WidgetTester._(binding);
return binding.runTest(() => callback(tester), tester._endOfTestVerifications) ?? new Future<Null>.value();
}