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

Ignore test helpers. #196

Merged
merged 55 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f8ffe3f
Update model.dart
polina-c Dec 11, 2023
abed3f6
Merge branch 'main' of github.com:dart-lang/leak_tracker into ignoreF…
polina-c Dec 11, 2023
4fe85fc
-
polina-c Dec 17, 2023
d7c50dd
Merge branch 'main' of github.com:dart-lang/leak_tracker into ignoreF…
polina-c Dec 17, 2023
6f00362
Create test_helpers_test.dart
polina-c Dec 18, 2023
4b8e35f
-
polina-c Dec 18, 2023
b57b706
-
polina-c Dec 19, 2023
04a4a8e
Update test_helpers_test.dart
polina-c Dec 19, 2023
ac83246
Update leak_testing.dart
polina-c Dec 19, 2023
b1f96fe
Update _test_helper_detector.dart
polina-c Dec 19, 2023
8c1a473
Update _test_helper_detector.dart
polina-c Dec 20, 2023
d801df7
-
polina-c Dec 22, 2023
f02b51a
Update testing.dart
polina-c Dec 22, 2023
5c8cf7d
Update testing_test.dart
polina-c Dec 22, 2023
e1f3ef1
Update testing.dart
polina-c Dec 22, 2023
717055e
Merge branch 'switch' into ignoreFrame
polina-c Dec 22, 2023
5826392
-
polina-c Dec 23, 2023
ed4b61e
Merge branch 'main' of github.com:dart-lang/leak_tracker into switch
polina-c Dec 23, 2023
000e93c
-
polina-c Dec 23, 2023
331b852
Merge branch 'main' of github.com:dart-lang/leak_tracker into ignoreF…
polina-c Dec 23, 2023
f3af854
Merge branch 'switch' into ignoreFrame
polina-c Dec 23, 2023
d77c650
Update leak_tracker_flutter_testing.dart
polina-c Dec 23, 2023
378ee00
Update test_helpers_test.dart
polina-c Dec 23, 2023
8ec30cf
-
polina-c Dec 23, 2023
688da78
Update _test_helper_detector.dart
polina-c Dec 23, 2023
bbb5cbc
Update _test_helper_detector.dart
polina-c Dec 23, 2023
0612782
Update _test_helper_detector.dart
polina-c Dec 23, 2023
aab7120
-
polina-c Dec 23, 2023
01c05a6
-
polina-c Dec 25, 2023
e779e7e
-
polina-c Dec 25, 2023
277fed3
Update leak_testing.dart
polina-c Dec 25, 2023
2603191
Update leak_testing.dart
polina-c Dec 25, 2023
9e22673
Merge branch 'switch-1' into ignoreFrame-2
polina-c Dec 25, 2023
2dedfa2
Update test_case.dart
polina-c Dec 25, 2023
2f1d091
-
polina-c Dec 25, 2023
fda50bf
-
polina-c Dec 26, 2023
8762c46
Update test_settings.dart
polina-c Dec 26, 2023
4e2dae6
-
polina-c Dec 26, 2023
c6f2ece
Update test_case.dart
polina-c Dec 26, 2023
9d77ef8
Update test_settings.dart
polina-c Dec 30, 2023
64d0ebf
Merge branch 'main' of github.com:dart-lang/leak_tracker into ignoreF…
polina-c Dec 30, 2023
13d5003
Merge branch 'main' of github.com:dart-lang/leak_tracker into ignoreF…
polina-c Jan 4, 2024
8cd9920
-
polina-c Jan 5, 2024
d8617a5
-
polina-c Jan 5, 2024
8ae0506
-
polina-c Jan 5, 2024
1697ca0
Update test_settings.dart
polina-c Jan 5, 2024
7d7779f
Update _test_helper_detector.dart
polina-c Jan 5, 2024
fba6c60
-
polina-c Jan 6, 2024
229d5d4
Update _test_helper_detector.dart
polina-c Jan 6, 2024
6cedace
-
polina-c Jan 6, 2024
fddae97
Update test_helpers_test.dart
polina-c Jan 7, 2024
e12a1af
-
polina-c Jan 7, 2024
7789fbd
-
polina-c Jan 8, 2024
22ee0e5
Update model.dart
polina-c Jan 8, 2024
10311d7
-
polina-c Jan 9, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// 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.

Expand Down Expand Up @@ -27,8 +27,16 @@ final _startFrame = RegExp(
r')',
);

bool isCreatedByTestHelper(String trace, List<RegExp> exceptions) {
final frames = trace.split('\n');
/// If true, leaking objects created by test helpers will be ignored.
polina-c marked this conversation as resolved.
Show resolved Hide resolved
///
/// Frames, that match [exceptions] will be ignored.
///
/// See details 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ class IgnoredLeaks {
/// If true, leaking objects created by test helpers will be ignored.
///
/// An object counts as created by a test helper if the stack trace of
/// start of leak tracking contains a frame, loactaed after the test body
/// frame, thet points to the folder `test` or the package `flutter_test`,
/// start of leak tracking contains a frame, located after the test body
/// frame, that points to the folder `test` or the package `flutter_test`,
/// except:
/// * methods intended to be called from test body like `runAsunc` or `pump`
/// * frames that match [testHelperExceptions]
final bool createdByTestHelpers;

/// Stack frames that match this pattern, will not be treated as test helpers.
/// Stack frames that match this pattern will not be treated as test helpers.
///
/// Is used to test functionality of
/// the leak tracker.
Expand Down
7 changes: 4 additions & 3 deletions pkgs/leak_tracker/lib/src/shared/shared_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ class Leaks {
final leaks = <String?, Map<LeakType, List<LeakReport>>>{};
for (final entry in byType.entries) {
for (final leak in entry.value) {
leaks[leak.phase] ??= {};
leaks[leak.phase]![entry.key] ??= [];
leaks[leak.phase]![entry.key]!.add(leak);
leaks
.putIfAbsent(leak.phase, () => {})
.putIfAbsent(entry.key, () => <LeakReport>[])
.add(leak);
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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.

import 'package:leak_tracker/src/leak_tracking/primitives/_test_helper_detector.dart';
polina-c marked this conversation as resolved.
Show resolved Hide resolved
import 'package:test/test.dart';

Expand Down Expand Up @@ -104,19 +108,19 @@ final _tests = [
name: 'test-only factory method',
isHelper: true,
stackTrace: '''
// #0 ObjectTracker.startTracking (package:leak_tracker/src/leak_tracking/_object_tracker.dart:69:31)
// #1 LeakTracking.dispatchObjectCreated.<anonymous closure> (package:leak_tracker/src/leak_tracking/leak_tracking.dart:124:35)
// #2 LeakTracking.dispatchObjectCreated (package:leak_tracker/src/leak_tracking/leak_tracking.dart:133:6)
// #3 new LeakTrackedClass (package:leak_tracker_flutter_testing/src/test_classes.dart:40:18)
// #4 new StatelessLeakingWidget (package:leak_tracker_flutter_testing/src/test_classes.dart:20:27)
// #5 createTestWidget (file:///Users/polinach/_/leak_tracker/pkgs/leak_tracker_flutter_testing/test/tests/end_to_end/test_helpers_test.dart:46:46)
// #6 main.<anonymous closure> (file:///Users/polinach/_/leak_tracker/pkgs/leak_tracker_flutter_testing/test/tests/end_to_end/test_helpers_test.dart:38:5)
// #7 Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:215:19)
// <asynchronous suspension>
// #8 Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:213:7)
// <asynchronous suspension>
// #9 Invoker._waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:258:9)
// <asynchronous suspension>
#0 ObjectTracker.startTracking (package:leak_tracker/src/leak_tracking/_object_tracker.dart:69:31)
#1 LeakTracking.dispatchObjectCreated.<anonymous closure> (package:leak_tracker/src/leak_tracking/leak_tracking.dart:124:35)
#2 LeakTracking.dispatchObjectCreated (package:leak_tracker/src/leak_tracking/leak_tracking.dart:133:6)
#3 new LeakTrackedClass (package:leak_tracker_flutter_testing/src/test_classes.dart:40:18)
#4 new StatelessLeakingWidget (package:leak_tracker_flutter_testing/src/test_classes.dart:20:27)
#5 createTestWidget (file:///Users/polinach/_/leak_tracker/pkgs/leak_tracker_flutter_testing/test/tests/end_to_end/test_helpers_test.dart:46:46)
#6 main.<anonymous closure> (file:///Users/polinach/_/leak_tracker/pkgs/leak_tracker_flutter_testing/test/tests/end_to_end/test_helpers_test.dart:38:5)
#7 Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:215:19)
<asynchronous suspension>
#8 Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:213:7)
<asynchronous suspension>
#9 Invoker._waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:258:9)
<asynchronous suspension>
''',
),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This forlder contains model and tests to test that methods like `testWidgets`,
This folder contains model and tests to test that methods like `testWidgets`,
that use API of this package, detect leaks as expected.

See example of usage in [the test](../../../test/tests/end_to_end/testing_test.dart).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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.
// 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.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand All @@ -9,12 +9,12 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'test_helpers.dart';

/// Objects that should not be GCed during.
final List<InstrumentedDisposable> _retainer = <InstrumentedDisposable>[];
final _retainer = <InstrumentedDisposable>[];

/// Test cases for memory leaks.
///
/// They are separate from test execution to allow to except only them
/// from test helpers.
/// They are separate from test execution to allow to allow
polina-c marked this conversation as resolved.
Show resolved Hide resolved
/// excluding them from test helpers.
final List<LeakTestCase> memoryLeakTests = <LeakTestCase>[
LeakTestCase(
name: 'no leaks',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// 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.
// 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.

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

/// Test only function that create a leaking object.
/// Test only function that creates a leaking object.
///
/// If test helpers are ignored in leak tracking settings,
/// leaks from objects created by this function will be ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import 'package:test/test.dart';
import '../../test_infra/memory_leak_tests.dart';

class _TestExecution {
_TestExecution(
{required this.settings, required this.settingName, required this.test});
_TestExecution({
required this.settings,
required this.settingName,
required this.test,
});

final String settingName;
final LeakTesting settings;
Expand Down