diff --git a/pkgs/leak_tracker/CHANGELOG.md b/pkgs/leak_tracker/CHANGELOG.md index 7e18c646..a60e0ef7 100644 --- a/pkgs/leak_tracker/CHANGELOG.md +++ b/pkgs/leak_tracker/CHANGELOG.md @@ -1,3 +1,7 @@ +# 10.0.8 + +* Make link to documentation customizable. + # 10.0.7 * Fix broken link in error message. diff --git a/pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart b/pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart index 0f1a404e..fb281b82 100644 --- a/pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart +++ b/pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart @@ -25,6 +25,14 @@ abstract class LeakTracking { /// requested for a non-supported platform. static bool warnForUnsupportedPlatforms = true; + /// Customized link to documentation on how to troubleshoot leaks. + /// + /// Used to provide a link to the user in the generated leak report. + /// If not provided, the [Links.gitHubTroubleshooting] is used. + static String get troubleshootingDocumentationLink => documentationLinkToUse; + static set troubleshootingDocumentationLink(String value) => + documentationLinkToUse = value; + /// Settings for leak tracking phase. /// /// Can be modified before leak tracking is started and while it diff --git a/pkgs/leak_tracker/lib/src/shared/_primitives.dart b/pkgs/leak_tracker/lib/src/shared/_primitives.dart index 7628f9c8..67029dcf 100644 --- a/pkgs/leak_tracker/lib/src/shared/_primitives.dart +++ b/pkgs/leak_tracker/lib/src/shared/_primitives.dart @@ -24,10 +24,16 @@ class ObjectRef { T value; } -final leakTrackerYamlHeader = ''' +/// Customized link to documentation on how to troubleshoot leaks. +/// +/// Used to provide a link to the user in the generated leak report. +/// Defaults to [Links.gitHubTroubleshooting]. +String documentationLinkToUse = Links.gitHubTroubleshooting.value; + +String leakTrackerYamlHeader() => ''' # The text is generated by leak_tracker. # For leak troubleshooting tips open: -# ${Links.gitHubTroubleshooting.value} +# $documentationLinkToUse '''; /// Some links used in the package. diff --git a/pkgs/leak_tracker/lib/src/shared/shared_model.dart b/pkgs/leak_tracker/lib/src/shared/shared_model.dart index 7eb59db2..bca89058 100644 --- a/pkgs/leak_tracker/lib/src/shared/shared_model.dart +++ b/pkgs/leak_tracker/lib/src/shared/shared_model.dart @@ -144,7 +144,7 @@ class Leaks { ), ) .join(); - return '$leakTrackerYamlHeader$leaks'; + return '${leakTrackerYamlHeader()}$leaks'; } } diff --git a/pkgs/leak_tracker/pubspec.yaml b/pkgs/leak_tracker/pubspec.yaml index 393182b2..97615d9a 100644 --- a/pkgs/leak_tracker/pubspec.yaml +++ b/pkgs/leak_tracker/pubspec.yaml @@ -1,5 +1,5 @@ name: leak_tracker -version: 10.0.7 +version: 10.0.8 description: A framework for memory leak tracking for Dart and Flutter applications. repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker diff --git a/pkgs/leak_tracker_flutter_testing/CHANGELOG.md b/pkgs/leak_tracker_flutter_testing/CHANGELOG.md index 0d51a25d..d7349296 100644 --- a/pkgs/leak_tracker_flutter_testing/CHANGELOG.md +++ b/pkgs/leak_tracker_flutter_testing/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.9 + +* Upgrade leak_tracker to 10.0.8. + + ## 3.0.8 * Upgrade leak_tracker to 10.0.7. diff --git a/pkgs/leak_tracker_flutter_testing/pubspec.yaml b/pkgs/leak_tracker_flutter_testing/pubspec.yaml index 206c5e7d..4dfb1560 100644 --- a/pkgs/leak_tracker_flutter_testing/pubspec.yaml +++ b/pkgs/leak_tracker_flutter_testing/pubspec.yaml @@ -1,5 +1,5 @@ name: leak_tracker_flutter_testing -version: 3.0.8 +version: 3.0.9 description: An internal package to test leak tracking with Flutter. repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker_flutter_testing @@ -10,7 +10,7 @@ environment: dependencies: flutter: sdk: flutter - leak_tracker: '>=10.0.7 <11.0.0' + leak_tracker: '>=10.0.8 <11.0.0' leak_tracker_testing: '>=3.0.1 <4.0.0' matcher: ^0.12.16 meta: ^1.8.0 diff --git a/pkgs/leak_tracker_testing/CHANGELOG.md b/pkgs/leak_tracker_testing/CHANGELOG.md index 3f5a474d..9927af11 100644 --- a/pkgs/leak_tracker_testing/CHANGELOG.md +++ b/pkgs/leak_tracker_testing/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.0.1-wip +## 3.0.1 * Fixed typo by renaming `experimantalAllNotGCed` to `experimentalAllNotGCed`. diff --git a/pkgs/leak_tracker_testing/test/matchers_test.dart b/pkgs/leak_tracker_testing/test/matchers_test.dart index 267f9155..31f82c1a 100644 --- a/pkgs/leak_tracker_testing/test/matchers_test.dart +++ b/pkgs/leak_tracker_testing/test/matchers_test.dart @@ -2,7 +2,7 @@ // 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/shared/shared_model.dart'; +import 'package:leak_tracker/leak_tracker.dart'; import 'package:leak_tracker_testing/leak_tracker_testing.dart'; import 'package:test/test.dart'; @@ -27,4 +27,57 @@ void main() { test('$isLeakFree fails.', () async { expect(isLeakFree.matches(_leaks, {}), false); }); + + test('$isLeakFree fails.', () async { + expect(isLeakFree.matches(_leaks, {}), false); + }); + + group('troubleshootingDocumentationLink', () { + late String originalLink; + setUp(() { + originalLink = LeakTracking.troubleshootingDocumentationLink; + }); + tearDown(() { + LeakTracking.troubleshootingDocumentationLink = originalLink; + }); + + test('defaults to TROUBLESHOOT.md', () async { + expect(LeakTracking.troubleshootingDocumentationLink, + 'https://github.com/dart-lang/leak_tracker/blob/main/doc/leak_tracking/TROUBLESHOOT.md'); + }); + + test('is preserved', () async { + expect(LeakTracking.troubleshootingDocumentationLink, originalLink); + LeakTracking.troubleshootingDocumentationLink = 'https://example.com'; + expect( + LeakTracking.troubleshootingDocumentationLink, 'https://example.com'); + }); + + test('is preserved', () async { + expect(LeakTracking.troubleshootingDocumentationLink, originalLink); + LeakTracking.troubleshootingDocumentationLink = 'https://example.com'; + expect( + LeakTracking.troubleshootingDocumentationLink, 'https://example.com'); + }); + + test('is used in leak report when default', () async { + expect(LeakTracking.troubleshootingDocumentationLink, originalLink); + checkLinkIsUsed(); + }); + + test('is used in leak report when default', () async { + LeakTracking.troubleshootingDocumentationLink = + 'https://custom_example.com'; + expect(LeakTracking.troubleshootingDocumentationLink, + 'https://custom_example.com'); + checkLinkIsUsed(); + }); + }); +} + +void checkLinkIsUsed() { + final description = isLeakFree.describeMismatch( + _leaks, StringDescription(), {}, false) as StringDescription; + expect(description.toString(), + contains(LeakTracking.troubleshootingDocumentationLink)); }