Refactor core uses of FlutterError. (#30983)
Make FlutterError objects more structured so they can be displayed better in debugging tools such as Dart DevTools.
This commit is contained in:
@@ -149,7 +149,8 @@ void main() {
|
||||
expect('Foo#a3b4d', isNot(equalsIgnoringHashCodes('Foo#000000')));
|
||||
expect('Foo#a3b4d', isNot(equalsIgnoringHashCodes('Foo#123456')));
|
||||
|
||||
expect('Foo#A3b4D', isNot(equalsIgnoringHashCodes('Foo#00000')));
|
||||
expect('FOO#A3b4D', equalsIgnoringHashCodes('FOO#00000'));
|
||||
expect('FOO#A3b4J', isNot(equalsIgnoringHashCodes('FOO#00000')));
|
||||
|
||||
expect('Foo#12345(Bar#9110f)',
|
||||
equalsIgnoringHashCodes('Foo#00000(Bar#00000)'));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
@@ -10,9 +11,10 @@ void main() {
|
||||
expect(false, isTrue);
|
||||
throw 'unexpectedly did not throw';
|
||||
} catch (e, stack) {
|
||||
final StringBuffer information = StringBuffer();
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
expect(reportExpectCall(stack, information), 4);
|
||||
final List<String> lines = information.toString().split('\n');
|
||||
final TextTreeRenderer renderer = TextTreeRenderer();
|
||||
final List<String> lines = information.map((DiagnosticsNode node) => renderer.render(node).trimRight()).join('\n').split('\n');
|
||||
expect(lines[0], 'This was caught by the test expectation on the following line:');
|
||||
expect(lines[1], matches(r'^ .*stack_manipulation_test.dart line [0-9]+$'));
|
||||
}
|
||||
@@ -20,9 +22,9 @@ void main() {
|
||||
try {
|
||||
throw null;
|
||||
} catch (e, stack) {
|
||||
final StringBuffer information = StringBuffer();
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
expect(reportExpectCall(stack, information), 0);
|
||||
expect(information.toString(), '');
|
||||
expect(information, isEmpty);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -43,12 +44,13 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.'));
|
||||
real_test.expect(lines[2], matches(r'Then, the "testGuard2" method \(also from class TestAPI\) was called from .*test_async_utils_test.dart on line [0-9]+\.'));
|
||||
real_test.expect(lines[3], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPI.testGuard2) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[4], '');
|
||||
real_test.expect(lines[5], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines[0], 'Guarded function conflict.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.'));
|
||||
real_test.expect(lines[3], matches(r'Then, the "testGuard2" method \(also from class TestAPI\) was called from .*test_async_utils_test.dart on line [0-9]+\.'));
|
||||
real_test.expect(lines[4], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPI.testGuard2) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[5], '');
|
||||
real_test.expect(lines[6], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(6));
|
||||
}
|
||||
expect(await f1, isNull);
|
||||
@@ -64,13 +66,14 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[2], matches(r'^Then, the "testGuard2" method \(also from class TestAPI\) was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPI.testGuard2) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[4], '');
|
||||
real_test.expect(lines[5], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(6));
|
||||
real_test.expect(lines[0], 'Guarded function conflict.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], matches(r'^Then, the "testGuard2" method \(also from class TestAPI\) was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[4], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPI.testGuard2) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[5], '');
|
||||
real_test.expect(lines[6], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(7));
|
||||
}
|
||||
expect(await f1, isNull);
|
||||
expect(f2, isNull);
|
||||
@@ -85,13 +88,14 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[2], matches(r'^Then, the "testGuard3" method from class TestAPISubclass was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPISubclass.testGuard3) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[4], '');
|
||||
real_test.expect(lines[5], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(6));
|
||||
real_test.expect(lines[0], 'Guarded function conflict.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], matches(r'^Then, the "testGuard3" method from class TestAPISubclass was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[4], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second method (TestAPISubclass.testGuard3) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[5], '');
|
||||
real_test.expect(lines[6], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(7));
|
||||
}
|
||||
expect(await f1, isNull);
|
||||
expect(f2, isNull);
|
||||
@@ -106,13 +110,14 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[2], matches(r'^Then, the "expect" function was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second function (expect) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[4], 'If you are confident that all test APIs are being called using "await", and this expect() call is not being called at the top level but is itself being called from some sort of callback registered before the testGuard1 method was called, then consider using expectSync() instead.');
|
||||
real_test.expect(lines[5], '');
|
||||
real_test.expect(lines[6], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines[0], 'Guarded function conflict.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "testGuard1" from class TestAPI was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], matches(r'^Then, the "expect" function was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[4], 'The first method (TestAPI.testGuard1) had not yet finished executing at the time that the second function (expect) was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[5], 'If you are confident that all test APIs are being called using "await", and this expect() call is not being called at the top level but is itself being called from some sort of callback registered before the testGuard1 method was called, then consider using expectSync() instead.');
|
||||
real_test.expect(lines[6], '');
|
||||
real_test.expect(lines[7], 'When the first method (TestAPI.testGuard1) was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(7));
|
||||
}
|
||||
expect(await f1, isNull);
|
||||
@@ -126,13 +131,35 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[2], matches(r'^Then, it was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], 'The first method had not yet finished executing at the time that the second method was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[4], '');
|
||||
real_test.expect(lines[5], 'When the first method was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(6));
|
||||
real_test.expect(lines[0], 'Guarded function conflict.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[3], matches(r'^Then, it was called from .*test_async_utils_test.dart on line [0-9]+\.$'));
|
||||
real_test.expect(lines[4], 'The first method had not yet finished executing at the time that the second method was called. Since both are guarded, and the second was not a nested call inside the first, the first must complete its execution before the second can be called. Typically, this is achieved by putting an "await" statement in front of the call to the first.');
|
||||
real_test.expect(lines[5], '');
|
||||
real_test.expect(lines[6], 'When the first method was called, this was the stack:');
|
||||
real_test.expect(lines.length, greaterThan(7));
|
||||
// TODO(jacobr): add more tests like this if they are useful.
|
||||
|
||||
final DiagnosticPropertiesBuilder propertiesBuilder = DiagnosticPropertiesBuilder();
|
||||
e.debugFillProperties(propertiesBuilder);
|
||||
final List<DiagnosticsNode> information = propertiesBuilder.properties;
|
||||
real_test.expect(information.length, 6);
|
||||
real_test.expect(information[0].level, DiagnosticLevel.summary);
|
||||
real_test.expect(information[1].level, DiagnosticLevel.hint);
|
||||
real_test.expect(information[2].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[3].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[4].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[5].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[0], isInstanceOf<DiagnosticsProperty<void>>());
|
||||
real_test.expect(information[1], isInstanceOf<DiagnosticsProperty<void>>());
|
||||
real_test.expect(information[2], isInstanceOf<DiagnosticsProperty<void>>());
|
||||
real_test.expect(information[3], isInstanceOf<DiagnosticsProperty<void>>());
|
||||
real_test.expect(information[4], isInstanceOf<DiagnosticsProperty<void>>());
|
||||
real_test.expect(information[5], isInstanceOf<DiagnosticsStackTrace>());
|
||||
final DiagnosticsStackTrace stackTraceProperty = information[5];
|
||||
real_test.expect(stackTraceProperty.name, '\nWhen the first method was called, this was the stack');
|
||||
real_test.expect(stackTraceProperty.value, isInstanceOf<StackTrace>());
|
||||
}
|
||||
await f1;
|
||||
await f2;
|
||||
@@ -146,10 +173,19 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Asynchronous call to guarded function leaked. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+, but never completed before its parent scope closed\.$'));
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "pump" from class AutomatedTestWidgetsFlutterBinding was called from [^ ]+ on line [0-9]+, but never completed before its parent scope closed\.'));
|
||||
real_test.expect(lines.length, 3);
|
||||
real_test.expect(lines[0], 'Asynchronous call to guarded function leaked.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+, but never completed before its parent scope closed\.$'));
|
||||
real_test.expect(lines[3], matches(r'^The guarded method "pump" from class AutomatedTestWidgetsFlutterBinding was called from [^ ]+ on line [0-9]+, but never completed before its parent scope closed\.'));
|
||||
real_test.expect(lines.length, 4);
|
||||
final DiagnosticPropertiesBuilder propertiesBuilder = DiagnosticPropertiesBuilder();
|
||||
e.debugFillProperties(propertiesBuilder);
|
||||
final List<DiagnosticsNode> information = propertiesBuilder.properties;
|
||||
real_test.expect(information.length, 4);
|
||||
real_test.expect(information[0].level, DiagnosticLevel.summary);
|
||||
real_test.expect(information[1].level, DiagnosticLevel.hint);
|
||||
real_test.expect(information[2].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[3].level, DiagnosticLevel.info);
|
||||
}
|
||||
await f1;
|
||||
});
|
||||
@@ -162,10 +198,19 @@ void main() {
|
||||
throw 'unexpectedly did not throw';
|
||||
} on FlutterError catch (e) {
|
||||
final List<String> lines = e.message.split('\n');
|
||||
real_test.expect(lines[0], 'Asynchronous call to guarded function leaked. You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[1], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+, but never completed before its parent scope closed\.$'));
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "pump" from class AutomatedTestWidgetsFlutterBinding was called from [^ ]+ on line [0-9]+, but never completed before its parent scope closed\.'));
|
||||
real_test.expect(lines.length, 3);
|
||||
real_test.expect(lines[0], 'Asynchronous call to guarded function leaked.');
|
||||
real_test.expect(lines[1], 'You must use "await" with all Future-returning test APIs.');
|
||||
real_test.expect(lines[2], matches(r'^The guarded method "pump" from class WidgetTester was called from .*test_async_utils_test.dart on line [0-9]+, but never completed before its parent scope closed\.$'));
|
||||
real_test.expect(lines[3], matches(r'^The guarded method "pump" from class AutomatedTestWidgetsFlutterBinding was called from [^ ]+ on line [0-9]+, but never completed before its parent scope closed\.'));
|
||||
real_test.expect(lines.length, 4);
|
||||
final DiagnosticPropertiesBuilder propertiesBuilder = DiagnosticPropertiesBuilder();
|
||||
e.debugFillProperties(propertiesBuilder);
|
||||
final List<DiagnosticsNode> information = propertiesBuilder.properties;
|
||||
real_test.expect(information.length, 4);
|
||||
real_test.expect(information[0].level, DiagnosticLevel.summary);
|
||||
real_test.expect(information[1].level, DiagnosticLevel.hint);
|
||||
real_test.expect(information[2].level, DiagnosticLevel.info);
|
||||
real_test.expect(information[3].level, DiagnosticLevel.info);
|
||||
}
|
||||
await f1;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user