Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug information should not wipe other settings. #182

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/leak_tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 9.0.15

* Fix: debug information should not wipe other settings.
* Add arguments allNotGCed and allNotDisposed to withTracked.
* Remove the dependency on `package:intl`.
* Updated to use `package:lints/recommended.yaml` for analysis.
Expand Down
6 changes: 3 additions & 3 deletions pkgs/leak_tracker/lib/src/leak_tracking/leak_testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LeakTesting {
@useResult
LeakTesting withCreationStackTrace() {
return copyWith(
leakDiagnosticConfig: const LeakDiagnosticConfig(
leakDiagnosticConfig: leakDiagnosticConfig.copyWith(
collectStackTraceOnStart: true,
),
);
Expand All @@ -74,7 +74,7 @@ class LeakTesting {
@useResult
LeakTesting withDisposalStackTrace() {
return copyWith(
leakDiagnosticConfig: const LeakDiagnosticConfig(
leakDiagnosticConfig: leakDiagnosticConfig.copyWith(
collectStackTraceOnDisposal: true,
),
);
Expand All @@ -84,7 +84,7 @@ class LeakTesting {
@useResult
LeakTesting withRetainingPath() {
return copyWith(
leakDiagnosticConfig: const LeakDiagnosticConfig(
leakDiagnosticConfig: leakDiagnosticConfig.copyWith(
collectRetainingPathForNotGCed: true,
),
);
Expand Down
15 changes: 15 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/primitives/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ class LeakDiagnosticConfig {
/// In release mode this flag does not work.
final bool collectRetainingPathForNotGCed;

LeakDiagnosticConfig copyWith({
bool? collectRetainingPathForNotGCed,
bool? collectStackTraceOnStart,
bool? collectStackTraceOnDisposal,
}) {
return LeakDiagnosticConfig(
collectRetainingPathForNotGCed:
collectRetainingPathForNotGCed ?? this.collectRetainingPathForNotGCed,
collectStackTraceOnStart:
collectStackTraceOnStart ?? this.collectStackTraceOnStart,
collectStackTraceOnDisposal:
collectStackTraceOnDisposal ?? this.collectStackTraceOnDisposal,
);
}

@override
bool operator ==(Object other) {
if (identical(other, this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ import 'package:test/test.dart';

void main() {
group('$LeakTesting', () {
test('debug info preserves other settings', () {
final settings = LeakTesting.settings
.withIgnored(notDisposed: {'MyClass': 1})
.withCreationStackTrace()
.withDisposalStackTrace()
.withRetainingPath();

expect(
settings.leakDiagnosticConfig.collectRetainingPathForNotGCed,
true,
);
expect(
settings.leakDiagnosticConfig.collectStackTraceOnDisposal,
true,
);
expect(
settings.leakDiagnosticConfig.collectStackTraceOnStart,
true,
);
expect(
settings.ignoredLeaks.notDisposed.byClass.keys.firstOrNull,
'MyClass',
);
});

group('withTracked', () {
test('not provided args do not affect the instance, tracked', () {
final settings = LeakTesting.settings.withTrackedAll().withIgnored(
Expand Down