Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Oct 13, 2023
1 parent 159609a commit cd3d03e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,27 @@ abstract class LeakTrackingForTests {
/// Creates copy of current settings to debug notGCed leaks.
static LeakTrackingForTestsSettings withCreationStackTrace() {
return settings.copyWith(
leakDiagnosticConfig:
const LeakDiagnosticConfig(collectStackTraceOnStart: true),
leakDiagnosticConfig: const LeakDiagnosticConfig(
collectStackTraceOnStart: true,
),
);
}

/// Creates copy of current settings to debug notDisposed leaks.
static LeakTrackingForTestsSettings withDisposalStackTrace() {
return settings.copyWith(
leakDiagnosticConfig:
const LeakDiagnosticConfig(collectStackTraceOnDisposal: true),
leakDiagnosticConfig: const LeakDiagnosticConfig(
collectStackTraceOnDisposal: true,
),
);
}

/// Creates copy of current settings, that collects retaining path for not GCed objects.
static LeakTrackingForTestsSettings withRetainingPath() {
return settings.copyWith(
leakDiagnosticConfig:
const LeakDiagnosticConfig(collectRetainingPathForNotGCed: true),
leakDiagnosticConfig: const LeakDiagnosticConfig(
collectRetainingPathForNotGCed: true,
),
);
}

Expand All @@ -50,7 +53,7 @@ abstract class LeakTrackingForTests {
bool allNotDisposed = false,
List<String> classes = const [],
}) {
settings = withSkipped(
settings = copyWithSkippedLeaks(
notDisposed: notDisposed,
notGCed: notGCed,
allNotDisposed: allNotDisposed,
Expand All @@ -63,7 +66,7 @@ abstract class LeakTrackingForTests {
///
/// In the result the skip limit for a class is maximum of two original skip limits.
/// Items in [classes] will be added to all skip lists.
static LeakTrackingForTestsSettings withSkipped({
static LeakTrackingForTestsSettings copyWithSkippedLeaks({
Map<String, int?> notGCed = const {},
bool allNotGCed = false,
Map<String, int?> notDisposed = const {},
Expand All @@ -74,7 +77,10 @@ abstract class LeakTrackingForTests {
Map<String, int?> map,
List<String> classes,
) {
return {...map}..addEntries(classes.map((c) => MapEntry(c, null)));
return {
...map,
for (final c in classes) c: null,
};
}

return settings.copyWith(
Expand All @@ -98,7 +104,7 @@ abstract class LeakTrackingForTests {
/// Returns copy of [settings] with reduced skip lists.
///
/// Items in [classes] will be removed from all skip lists.
static LeakTrackingForTestsSettings withTracked({
static LeakTrackingForTestsSettings copyWithTrackedLeaks({
List<String> notGCed = const [],
List<String> notDisposed = const [],
List<String> classes = const [],
Expand All @@ -122,7 +128,7 @@ abstract class LeakTrackingForTests {
List<String> notDisposed = const [],
List<String> classes = const [],
}) {
settings = withTracked(
settings = copyWithTrackedLeaks(
notDisposed: notDisposed,
notGCed: notGCed,
classes: classes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void main() {
);

// Get adjusted settings.
final settings = LeakTrackingForTests.withSkipped(
final settings = LeakTrackingForTests.copyWithSkippedLeaks(
notGCed: {_Classes.notGCed1: null},
notDisposed: {_Classes.notDisposed1: null},
);
Expand Down

0 comments on commit cd3d03e

Please sign in to comment.