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

[rfw] Activate leak testing #8370

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/rfw/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
lcov_parser: 0.1.2
leak_tracker_flutter_testing: any

topics:
- ui
Expand Down
2 changes: 2 additions & 0 deletions packages/rfw/test/argument_decoders_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void main() {
},
}))
..update(const LibraryName(<String>['test']), parseLibraryFile('import core; widget root = SizedBox();'));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -235,6 +236,7 @@ void main() {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['test']), parseLibraryFile('import core; widget root = SizedBox();'));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down
3 changes: 3 additions & 0 deletions packages/rfw/test/core_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {
testWidgets('Core widgets', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -243,11 +244,13 @@ void main() {
expect(childSize.height, fractionallySizedBoxSize.height * 0.8);
expect(tester.widget<Text>(find.text('test')).textScaler, const TextScaler.linear(3));
expect(tester.widget<FractionallySizedBox>(find.byType(FractionallySizedBox)).alignment, Alignment.center);
imageCache.clear();
});

testWidgets('More core widgets', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down
13 changes: 13 additions & 0 deletions packages/rfw/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2013 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.

import 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
LeakTesting.enable();
LeakTracking.warnForUnsupportedPlatforms = false;
await testMain();
}
4 changes: 3 additions & 1 deletion packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ void main() {
const LibraryName testName = LibraryName(<String>['test']);

Runtime setupRuntime() {
return Runtime()
final Runtime runtime = Runtime()
..update(coreName, createCoreWidgets())
..update(materialName, createMaterialWidgets());
addTearDown(runtime.dispose);
return runtime;
}

setUpAll(() {
Expand Down
1 change: 1 addition & 0 deletions packages/rfw/test/readme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ void main() {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['material']), createMaterialWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(parseDataFile(gameData));
for (final String region in rawRemoteWidgetSnippets.keys) {
final String body = rawRemoteWidgetSnippets[region]!;
Expand Down
2 changes: 2 additions & 0 deletions packages/rfw/test/remote_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ void main() {
import core;
widget root = Placeholder();
'''));
addTearDown(runtime1.dispose);
final Runtime runtime2 = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
widget root = Container();
'''));
addTearDown(runtime2.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down
37 changes: 37 additions & 0 deletions packages/rfw/test/runtime_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
testWidgets('list lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[ 0, 1, 2, 3, 4 ],
});
Expand Down Expand Up @@ -55,6 +56,7 @@ void main() {
return const SizedBox.shrink();
},
}));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{ 'a': 0 },
Expand Down Expand Up @@ -131,6 +133,7 @@ void main() {
testWidgets('updateText, updateBinary, clearLibraries', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -167,6 +170,7 @@ void main() {
testWidgets('Runtime cached build', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -203,6 +207,7 @@ void main() {
..update(const LibraryName(<String>['b']), parseLibraryFile('''
import a;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -219,6 +224,7 @@ void main() {
..update(const LibraryName(<String>['a']), parseLibraryFile('''
import a;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -235,6 +241,7 @@ void main() {
..update(const LibraryName(<String>['a']), parseLibraryFile('''
import b;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -249,6 +256,7 @@ void main() {

testWidgets('Missing libraries in specified widget', (WidgetTester tester) async {
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -267,6 +275,7 @@ void main() {
import b;
widget widget = test();
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -282,6 +291,7 @@ void main() {
testWidgets('Missing widget', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['a']), parseLibraryFile(''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -297,6 +307,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -327,6 +338,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -350,6 +362,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
expect(runtime.libraries.length, 1);
final LibraryName libraryName = runtime.libraries.entries.first.key;
expect('$libraryName', 'core');
Expand All @@ -362,6 +375,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -389,6 +403,7 @@ void main() {
testWidgets('DynamicContent', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -435,6 +450,7 @@ void main() {
testWidgets('binding loop variables', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{
Expand Down Expand Up @@ -600,6 +616,7 @@ void main() {
testWidgets('list lookup of esoteric values', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -720,6 +737,7 @@ void main() {
testWidgets('data lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'map': <String, Object?>{ 'list': <Object?>[ 0xAB ] },
});
Expand All @@ -744,6 +762,7 @@ void main() {
testWidgets('args lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -767,6 +786,7 @@ void main() {
testWidgets('state lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -789,6 +809,7 @@ void main() {
testWidgets('switch', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -824,6 +845,7 @@ void main() {
testWidgets('events with arguments', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -872,6 +894,7 @@ void main() {
testWidgets('_CurriedWidget toStrings', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
Expand Down Expand Up @@ -911,6 +934,7 @@ void main() {
testWidgets('state setting', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -1029,6 +1053,7 @@ void main() {

testWidgets('DataSource', (WidgetTester tester) async {
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -1094,6 +1119,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
runtime.update(coreLibraryName, createCoreWidgets());
runtime.update(localLibraryName, LocalWidgetLibrary(<String, LocalWidgetBuilder> {
Expand Down Expand Up @@ -1127,6 +1153,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
const String expectedErrorMessage = 'Not a builder at [builder] (got core:Text {} {text: Not a builder :/}) for local:Builder.';

Expand Down Expand Up @@ -1163,6 +1190,7 @@ void main() {
};
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['a']), parseLibraryFile(''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -1182,6 +1210,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1214,6 +1243,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1247,6 +1277,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1283,6 +1314,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object>{'value': 0});
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1322,6 +1354,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<RfwEvent> dispatchedEvents = <RfwEvent>[];
final Finder textFinder = find.byType(Text);
Expand Down Expand Up @@ -1363,6 +1396,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);
runtime.update(coreLibraryName, createCoreWidgets());
Expand Down Expand Up @@ -1408,6 +1442,7 @@ void main() {
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Map<String, VoidCallback> handlers = <String, VoidCallback>{};
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'a1': 'apricot',
'b1': 'blueberry',
Expand Down Expand Up @@ -1474,6 +1509,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1522,6 +1558,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);
runtime.update(coreLibraryName, createCoreWidgets());
Expand Down
1 change: 1 addition & 0 deletions packages/rfw/test/source_locations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ widget verify { state: true } = switch args.value.c.0 {
// We use the actual source text as the sourceIdentifier to make it trivial to find the source contents.
// In normal operation, the sourceIdentifier would be the file name or some similar object.
..update(const LibraryName(<String>['test']), parseLibraryFile(sourceFile, sourceIdentifier: sourceFile));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{
Expand Down
Loading