Upgrade leak_tracker. (#141153)

This commit is contained in:
Polina Cherkasova
2024-01-09 12:02:35 -08:00
committed by GitHub
parent 51af82d3db
commit 1f3103e50d
52 changed files with 211 additions and 267 deletions

View File

@@ -1,54 +0,0 @@
// 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/widgets.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
class LeakTrackedClass {
LeakTrackedClass() {
LeakTracking.dispatchObjectCreated(
library: library,
className: '$LeakTrackedClass',
object: this,
);
}
static const String library = 'package:my_package/lib/src/my_lib.dart';
void dispose() {
LeakTracking.dispatchObjectDisposed(object: this);
}
}
final List<LeakTrackedClass> _notGCedObjects = <LeakTrackedClass>[];
class LeakingClass {
LeakingClass() {
_notGCedObjects.add(LeakTrackedClass()..dispose());
}
}
class StatelessLeakingWidget extends StatelessWidget {
StatelessLeakingWidget({
super.key,
this.notGCed = true,
this.notDisposed = true,
}) {
if (notGCed) {
_notGCedObjects.add(LeakTrackedClass()..dispose());
}
if (notDisposed) {
// ignore: unused_local_variable, it is unused intentionally, to illustrate not disposed object.
final LeakTrackedClass notDisposedObject = LeakTrackedClass();
}
}
final bool notGCed;
final bool notDisposed;
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}

View File

@@ -7,8 +7,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'utils/leaking_classes.dart';
late final String _test1TrackingOnNoLeaks;
late final String _test2TrackingOffLeaks;
late final String _test3TrackingOnLeaks;
@@ -74,11 +72,11 @@ void main() {
);
testWidgets(_test6TrackingOnNoLeaks = 'test6, tracking-on, no leaks', (_) async {
LeakTrackedClass().dispose();
InstrumentedDisposable().dispose();
});
testWidgets(_test7TrackingOnNoLeaks = 'test7, tracking-on, tear down, no leaks', (_) async {
final LeakTrackedClass myClass = LeakTrackedClass();
final InstrumentedDisposable myClass = InstrumentedDisposable();
addTearDown(myClass.dispose);
});
@@ -86,7 +84,7 @@ void main() {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, _test8TrackingOnNotDisposed);
expect(LeakTracking.phase.ignoreLeaks, false);
LeakTrackedClass();
InstrumentedDisposable();
});
}
@@ -196,7 +194,7 @@ void _verifyLeakList(
expect(list.length, expectedCount, reason: testDescription);
for (final LeakReport leak in list) {
expect(leak.trackedClass, contains(LeakTrackedClass.library));
expect(leak.trackedClass, contains('$LeakTrackedClass'));
expect(leak.trackedClass, contains(InstrumentedDisposable.library));
expect(leak.trackedClass, contains('$InstrumentedDisposable'));
}
}