Skip to content

Commit

Permalink
Make link to documentation customizable. (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Oct 22, 2024
1 parent be75122 commit b5522b3
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkgs/leak_tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 10.0.8

* Make link to documentation customizable.

# 10.0.7

* Fix broken link in error message.
Expand Down
8 changes: 8 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/leak_tracking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pkgs/leak_tracker/lib/src/shared/_primitives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ class ObjectRef<T> {
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.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/leak_tracker/lib/src/shared/shared_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Leaks {
),
)
.join();
return '$leakTrackerYamlHeader$leaks';
return '${leakTrackerYamlHeader()}$leaks';
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/leak_tracker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions pkgs/leak_tracker_flutter_testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.0.9

* Upgrade leak_tracker to 10.0.8.


## 3.0.8

* Upgrade leak_tracker to 10.0.7.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/leak_tracker_flutter_testing/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/leak_tracker_testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.0.1-wip
## 3.0.1

* Fixed typo by renaming `experimantalAllNotGCed` to `experimentalAllNotGCed`.

Expand Down
55 changes: 54 additions & 1 deletion pkgs/leak_tracker_testing/test/matchers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
}

0 comments on commit b5522b3

Please sign in to comment.