forked from dart-lang/leak_tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:dart-lang/leak_tracker into publish
- Loading branch information
Showing
35 changed files
with
745 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
# Configuration for .github/workflows/pull_request_label.yml. | ||
|
||
'type-infra': | ||
- '.github/**' | ||
- changed-files: | ||
- any-glob-to-any-file: '.github/**' | ||
|
||
'package:leak_tracker': | ||
- 'pkgs/leak_tracker/**' | ||
- changed-files: | ||
- any-glob-to-any-file: 'pkgs/leak_tracker/**' | ||
|
||
'package:leak_tracker_flutter_testing': | ||
- 'pkgs/leak_tracker_flutter_testing/**' | ||
- changed-files: | ||
- any-glob-to-any-file: 'pkgs/leak_tracker_flutter_testing/**' | ||
|
||
'package:leak_tracker_testing': | ||
- 'pkgs/leak_tracker_testing/**' | ||
- changed-files: | ||
- any-glob-to-any-file: 'pkgs/leak_tracker_testing/**' | ||
|
||
'package:memory_usage': | ||
- 'pkgs/memory_usage/**' | ||
- changed-files: | ||
- any-glob-to-any-file: 'pkgs/memory_usage/**' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ analyzer: | |
linter: | ||
rules: | ||
- avoid_print | ||
- comment_references | ||
- only_throw_errors | ||
- unawaited_futures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
pkgs/leak_tracker/lib/src/leak_tracking/primitives/_test_helper_detector.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Frames pointing the folder `test` or the package `flutter_test`. | ||
final _testHelperFrame = RegExp( | ||
r'(?:' + | ||
RegExp.escape(r'/test/') + | ||
r'|' + | ||
RegExp.escape(r'(package:flutter_test/') + | ||
r')', | ||
); | ||
|
||
/// Frames that match [_testHelperFrame], but are not test helpers. | ||
final _exceptions = RegExp( | ||
r'(?:' | ||
r'AutomatedTestWidgetsFlutterBinding.\w|' | ||
r'WidgetTester.\w' | ||
')', | ||
); | ||
|
||
/// Test body or closure inside test body. | ||
final _startFrame = RegExp( | ||
r'(?:' | ||
r'TestAsyncUtils.guard.<anonymous closure>|' | ||
r' main.<anonymous closure>' | ||
r')', | ||
); | ||
|
||
/// Returns whether the leak reported by [objectCreationTrace] | ||
/// was created by a test helper. | ||
/// | ||
/// Frames, that match [exceptions] will be ignored. | ||
/// | ||
/// See details on what means to be created by a test helper | ||
/// in doc for `LeakTesting.createdByTestHelpers`. | ||
bool isCreatedByTestHelper( | ||
String objectCreationTrace, | ||
List<RegExp> exceptions, | ||
) { | ||
final frames = objectCreationTrace.split('\n'); | ||
for (final frame in frames) { | ||
if (_startFrame.hasMatch(frame)) { | ||
return false; | ||
} | ||
if (_testHelperFrame.hasMatch(frame)) { | ||
if (exceptions.any((exception) => exception.hasMatch(frame)) || | ||
_exceptions.hasMatch(frame)) { | ||
continue; | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.