Skip to content

Commit

Permalink
Update _leak_filter_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Sep 20, 2023
1 parent 87309b6 commit 6c681c4
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pkgs/leak_tracker/test/tests/leak_tracking/_leak_filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import 'package:leak_tracker/src/leak_tracking/_leak_filter.dart';
import 'package:leak_tracker/src/leak_tracking/_object_record.dart';
import 'package:test/test.dart';

ObjectRecord _stringRecord(PhaseSettings phase) =>
ObjectRecord(0, {}, '', phase);
ObjectRecord _arrayRecord(PhaseSettings phase) =>
ObjectRecord([], {}, '', phase);
ObjectRecord _dateTimeRecord(PhaseSettings phase) =>
ObjectRecord(0, {}, '', phase);
ObjectRecord(DateTime.now(), {}, '', phase);

void main() {
test('All leaks are reported with default settings.', () {
final filter = LeakFilter(const Switches());
final record = _stringRecord(const PhaseSettings());
final record = _arrayRecord(const PhaseSettings());

expect(filter.shouldReport(LeakType.notDisposed, record), true);
expect(filter.shouldReport(LeakType.notGCed, record), true);
Expand All @@ -24,8 +24,7 @@ void main() {

test('$LeakFilter respects allowAllNotDisposed.', () {
final filter = LeakFilter(const Switches());
final record =
_stringRecord(const PhaseSettings(allowAllNotDisposed: true));
final record = _arrayRecord(const PhaseSettings(allowAllNotDisposed: true));

expect(filter.shouldReport(LeakType.notDisposed, record), false);
expect(filter.shouldReport(LeakType.notGCed, record), true);
Expand All @@ -34,7 +33,7 @@ void main() {

test('$LeakFilter respects allowAllNotGCed.', () {
final filter = LeakFilter(const Switches());
final record = _stringRecord(const PhaseSettings(allowAllNotGCed: true));
final record = _arrayRecord(const PhaseSettings(allowAllNotGCed: true));

expect(filter.shouldReport(LeakType.notDisposed, record), true);
expect(filter.shouldReport(LeakType.notGCed, record), false);
Expand All @@ -43,41 +42,41 @@ void main() {

test('$LeakFilter respects notGCedAllowList.', () {
final filter = LeakFilter(const Switches());
const phase = PhaseSettings(notGCedAllowList: {'String': null});
final stringRecord = _stringRecord(phase);
const phase = PhaseSettings(notGCedAllowList: {'List<dynamic>': null});
final arrayRecord = _arrayRecord(phase);
final dateTimeRecord = _dateTimeRecord(phase);

expect(filter.shouldReport(LeakType.notDisposed, stringRecord), true);
expect(filter.shouldReport(LeakType.notGCed, stringRecord), false);
expect(filter.shouldReport(LeakType.gcedLate, stringRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, arrayRecord), true);
expect(filter.shouldReport(LeakType.notGCed, arrayRecord), false);
expect(filter.shouldReport(LeakType.gcedLate, arrayRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, dateTimeRecord), true);
expect(filter.shouldReport(LeakType.notGCed, dateTimeRecord), true);
expect(filter.shouldReport(LeakType.gcedLate, dateTimeRecord), true);
});

test('$LeakFilter respects notDisposedAllowList.', () {
final filter = LeakFilter(const Switches());
const phase = PhaseSettings(notDisposedAllowList: {'String': null});
final stringRecord = _stringRecord(phase);
const phase = PhaseSettings(notDisposedAllowList: {'List<dynamic>': null});
final arrayRecord = _arrayRecord(phase);
final dateTimeRecord = _dateTimeRecord(phase);

expect(filter.shouldReport(LeakType.notDisposed, stringRecord), false);
expect(filter.shouldReport(LeakType.notGCed, stringRecord), true);
expect(filter.shouldReport(LeakType.gcedLate, stringRecord), true);
expect(filter.shouldReport(LeakType.notDisposed, arrayRecord), false);
expect(filter.shouldReport(LeakType.notGCed, arrayRecord), true);
expect(filter.shouldReport(LeakType.gcedLate, arrayRecord), true);
expect(filter.shouldReport(LeakType.notDisposed, dateTimeRecord), true);
expect(filter.shouldReport(LeakType.notGCed, dateTimeRecord), true);
expect(filter.shouldReport(LeakType.gcedLate, dateTimeRecord), true);
});

test('$LeakFilter respects limit.', () {
final filter = LeakFilter(const Switches());
const phase = PhaseSettings(notDisposedAllowList: {'String': 2});
final stringRecord = _stringRecord(phase);
const phase = PhaseSettings(notDisposedAllowList: {'List<dynamic>': 2});
final arrayRecord = _arrayRecord(phase);
final dateTimeRecord = _dateTimeRecord(phase);

expect(filter.shouldReport(LeakType.notDisposed, dateTimeRecord), true);
expect(filter.shouldReport(LeakType.notDisposed, stringRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, stringRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, stringRecord), true);
expect(filter.shouldReport(LeakType.notDisposed, arrayRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, arrayRecord), false);
expect(filter.shouldReport(LeakType.notDisposed, arrayRecord), true);
});
}

0 comments on commit 6c681c4

Please sign in to comment.