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:
@@ -501,7 +501,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
FlutterError.dumpErrorToConsole(FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: _unmangle(stack),
|
||||
context: 'running a test (but after the test had completed)',
|
||||
context: ErrorDescription('running a test (but after the test had completed)'),
|
||||
library: 'Flutter test framework',
|
||||
), forceReport: true);
|
||||
return;
|
||||
@@ -534,31 +534,33 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
// _this_ zone, the test framework would find this zone was the current
|
||||
// zone and helpfully throw the error in this zone, causing us to be
|
||||
// directly called again.
|
||||
String treeDump;
|
||||
DiagnosticsNode treeDump;
|
||||
try {
|
||||
treeDump = renderViewElement?.toStringDeep() ?? '<no tree>';
|
||||
treeDump = renderViewElement?.toDiagnosticsNode() ?? DiagnosticsNode.message('<no tree>');
|
||||
// TODO(jacobr): this is a hack to make sure the tree can safely be fully dumped.
|
||||
// Potentially everything is good enough without this case.
|
||||
treeDump.toStringDeep();
|
||||
} catch (exception) {
|
||||
treeDump = '<additional error caught while dumping tree: $exception>';
|
||||
treeDump = DiagnosticsNode.message('<additional error caught while dumping tree: $exception>', level: DiagnosticLevel.error);
|
||||
}
|
||||
final StringBuffer expectLine = StringBuffer();
|
||||
final int stackLinesToOmit = reportExpectCall(stack, expectLine);
|
||||
final List<DiagnosticsNode> omittedFrames = <DiagnosticsNode>[];
|
||||
final int stackLinesToOmit = reportExpectCall(stack, omittedFrames);
|
||||
FlutterError.reportError(FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: _unmangle(stack),
|
||||
context: 'running a test',
|
||||
context: ErrorDescription('running a test'),
|
||||
library: 'Flutter test framework',
|
||||
stackFilter: (Iterable<String> frames) {
|
||||
return FlutterError.defaultStackFilter(frames.skip(stackLinesToOmit));
|
||||
},
|
||||
informationCollector: (StringBuffer information) {
|
||||
informationCollector: () sync* {
|
||||
if (stackLinesToOmit > 0)
|
||||
information.writeln(expectLine.toString());
|
||||
yield* omittedFrames;
|
||||
if (showAppDumpInErrors) {
|
||||
information.writeln('At the time of the failure, the widget tree looked as follows:');
|
||||
information.writeln('# ${treeDump.split("\n").takeWhile((String s) => s != "").join("\n# ")}');
|
||||
yield DiagnosticsProperty<DiagnosticsNode>('At the time of the failure, the widget tree looked as follows', treeDump, linePrefix: '# ', style: DiagnosticsTreeStyle.flat);
|
||||
}
|
||||
if (description.isNotEmpty)
|
||||
information.writeln('The test description was:\n$description');
|
||||
yield DiagnosticsProperty<String>('The test description was', description, style: DiagnosticsTreeStyle.errorProperty);
|
||||
},
|
||||
));
|
||||
assert(_parentZone != null);
|
||||
@@ -847,7 +849,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
library: 'Flutter test framework',
|
||||
context: 'while running async test code',
|
||||
context: ErrorDescription('while running async test code'),
|
||||
));
|
||||
return null;
|
||||
}).whenComplete(() {
|
||||
@@ -1335,7 +1337,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
exception: error,
|
||||
stack: stack,
|
||||
library: 'Flutter test framework',
|
||||
context: 'while running async test code',
|
||||
context: ErrorSummary('while running async test code'),
|
||||
));
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
@@ -754,7 +754,7 @@ class _EqualsIgnoringHashCodes extends Matcher {
|
||||
static final Object _mismatchedValueKey = Object();
|
||||
|
||||
static String _normalize(String s) {
|
||||
return s.replaceAll(RegExp(r'#[0-9a-f]{5}'), '#00000');
|
||||
return s.replaceAll(RegExp(r'#[0-9a-fA-F]{5}'), '#00000');
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -4,14 +4,17 @@
|
||||
|
||||
// See also test_async_utils.dart which has some stack manipulation code.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Report call site for `expect()` call. Returns the number of frames that
|
||||
/// should be elided if a stack were to be modified to hide the expect call, or
|
||||
/// zero if no such call was found.
|
||||
///
|
||||
/// If the head of the stack trace consists of a failure as a result of calling
|
||||
/// the test_widgets [expect] function, this will fill the given StringBuffer
|
||||
/// with the precise file and line number that called that function.
|
||||
int reportExpectCall(StackTrace stack, StringBuffer information) {
|
||||
/// the test_widgets [expect] function, this will fill the given
|
||||
/// FlutterErrorBuilder with the precise file and line number that called that
|
||||
/// function.
|
||||
int reportExpectCall(StackTrace stack, List<DiagnosticsNode> information) {
|
||||
final RegExp line0 = RegExp(r'^#0 +fail \(.+\)$');
|
||||
final RegExp line1 = RegExp(r'^#1 +_expect \(.+\)$');
|
||||
final RegExp line2 = RegExp(r'^#2 +expect \(.+\)$');
|
||||
@@ -25,8 +28,11 @@ int reportExpectCall(StackTrace stack, StringBuffer information) {
|
||||
final Match expectMatch = line4.firstMatch(stackLines[4]);
|
||||
assert(expectMatch != null);
|
||||
assert(expectMatch.groupCount == 2);
|
||||
information.writeln('This was caught by the test expectation on the following line:');
|
||||
information.writeln(' ${expectMatch.group(1)} line ${expectMatch.group(2)}');
|
||||
information.add(DiagnosticsStackTrace.singleFrame(
|
||||
'This was caught by the test expectation on the following line',
|
||||
frame: '${expectMatch.group(1)} line ${expectMatch.group(2)}',
|
||||
));
|
||||
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -73,34 +73,37 @@ class TestAsyncUtils {
|
||||
assert(_scopeStack.contains(scope));
|
||||
bool leaked = false;
|
||||
_AsyncScope closedScope;
|
||||
final StringBuffer message = StringBuffer();
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
while (_scopeStack.isNotEmpty) {
|
||||
closedScope = _scopeStack.removeLast();
|
||||
if (closedScope == scope)
|
||||
break;
|
||||
if (!leaked) {
|
||||
message.writeln('Asynchronous call to guarded function leaked. You must use "await" with all Future-returning test APIs.');
|
||||
information.add(ErrorSummary('Asynchronous call to guarded function leaked.'));
|
||||
information.add(ErrorHint('You must use "await" with all Future-returning test APIs.'));
|
||||
leaked = true;
|
||||
}
|
||||
final _StackEntry originalGuarder = _findResponsibleMethod(closedScope.creationStack, 'guard', message);
|
||||
final _StackEntry originalGuarder = _findResponsibleMethod(closedScope.creationStack, 'guard', information);
|
||||
if (originalGuarder != null) {
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'The test API method "${originalGuarder.methodName}" '
|
||||
'from class ${originalGuarder.className} '
|
||||
'was called from ${originalGuarder.callerFile} '
|
||||
'on line ${originalGuarder.callerLine}, '
|
||||
'but never completed before its parent scope closed.'
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
if (leaked) {
|
||||
if (error != null) {
|
||||
message.writeln('An uncaught exception may have caused the guarded function leak. The exception was:');
|
||||
message.writeln('$error');
|
||||
message.writeln('The stack trace associated with this exception was:');
|
||||
FlutterError.defaultStackFilter(stack.toString().trimRight().split('\n')).forEach(message.writeln);
|
||||
information.add(DiagnosticsProperty<dynamic>(
|
||||
'An uncaught exception may have caused the guarded function leak. The exception was',
|
||||
error,
|
||||
style: DiagnosticsTreeStyle.errorProperty,
|
||||
));
|
||||
information.add(DiagnosticsStackTrace('The stack trace associated with this exception was', stack));
|
||||
}
|
||||
throw FlutterError(message.toString().trimRight());
|
||||
throw FlutterError.fromParts(information);
|
||||
}
|
||||
if (error != null)
|
||||
return Future<T>.error(error, stack);
|
||||
@@ -182,27 +185,28 @@ class TestAsyncUtils {
|
||||
assert(candidateScope.zone != null);
|
||||
} while (candidateScope.zone != zone);
|
||||
assert(scope != null);
|
||||
final StringBuffer message = StringBuffer();
|
||||
message.writeln('Guarded function conflict. You must use "await" with all Future-returning test APIs.');
|
||||
final _StackEntry originalGuarder = _findResponsibleMethod(scope.creationStack, 'guard', message);
|
||||
final _StackEntry collidingGuarder = _findResponsibleMethod(StackTrace.current, 'guardSync', message);
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
information.add(ErrorSummary('Guarded function conflict.'));
|
||||
information.add(ErrorHint('You must use "await" with all Future-returning test APIs.'));
|
||||
final _StackEntry originalGuarder = _findResponsibleMethod(scope.creationStack, 'guard', information);
|
||||
final _StackEntry collidingGuarder = _findResponsibleMethod(StackTrace.current, 'guardSync', information);
|
||||
if (originalGuarder != null && collidingGuarder != null) {
|
||||
String originalName;
|
||||
if (originalGuarder.className == null) {
|
||||
originalName = '(${originalGuarder.methodName}) ';
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'The guarded "${originalGuarder.methodName}" function '
|
||||
'was called from ${originalGuarder.callerFile} '
|
||||
'on line ${originalGuarder.callerLine}.'
|
||||
);
|
||||
));
|
||||
} else {
|
||||
originalName = '(${originalGuarder.className}.${originalGuarder.methodName}) ';
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'The guarded method "${originalGuarder.methodName}" '
|
||||
'from class ${originalGuarder.className} '
|
||||
'was called from ${originalGuarder.callerFile} '
|
||||
'on line ${originalGuarder.callerLine}.'
|
||||
);
|
||||
));
|
||||
}
|
||||
final String again = (originalGuarder.callerFile == collidingGuarder.callerFile) &&
|
||||
(originalGuarder.callerLine == collidingGuarder.callerLine) ?
|
||||
@@ -212,53 +216,52 @@ class TestAsyncUtils {
|
||||
(originalGuarder.methodName == collidingGuarder.methodName)) {
|
||||
originalName = '';
|
||||
collidingName = '';
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'Then, it '
|
||||
'was called ${again}from ${collidingGuarder.callerFile} '
|
||||
'on line ${collidingGuarder.callerLine}.'
|
||||
);
|
||||
));
|
||||
} else if (collidingGuarder.className == null) {
|
||||
collidingName = '(${collidingGuarder.methodName}) ';
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'Then, the "${collidingGuarder.methodName}" function '
|
||||
'was called ${again}from ${collidingGuarder.callerFile} '
|
||||
'on line ${collidingGuarder.callerLine}.'
|
||||
);
|
||||
));
|
||||
} else {
|
||||
collidingName = '(${collidingGuarder.className}.${collidingGuarder.methodName}) ';
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'Then, the "${collidingGuarder.methodName}" method '
|
||||
'${originalGuarder.className == collidingGuarder.className ? "(also from class ${collidingGuarder.className})"
|
||||
: "from class ${collidingGuarder.className}"} '
|
||||
'was called ${again}from ${collidingGuarder.callerFile} '
|
||||
'on line ${collidingGuarder.callerLine}.'
|
||||
);
|
||||
));
|
||||
}
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'The first ${originalGuarder.className == null ? "function" : "method"} $originalName'
|
||||
'had not yet finished executing at the time that '
|
||||
'the second ${collidingGuarder.className == null ? "function" : "method"} $collidingName'
|
||||
'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.'
|
||||
);
|
||||
));
|
||||
if (collidingGuarder.className == null && collidingGuarder.methodName == 'expect') {
|
||||
message.writeln(
|
||||
information.add(ErrorHint(
|
||||
'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 ${originalGuarder.methodName} '
|
||||
'method was called, then consider using expectSync() instead.'
|
||||
);
|
||||
));
|
||||
}
|
||||
message.writeln(
|
||||
'\n'
|
||||
'When the first ${originalGuarder.className == null ? "function" : "method"} '
|
||||
information.add(DiagnosticsStackTrace(
|
||||
'\nWhen the first ${originalGuarder.className == null ? "function" : "method"} '
|
||||
'$originalName'
|
||||
'was called, this was the stack:'
|
||||
);
|
||||
message.writeln(FlutterError.defaultStackFilter(scope.creationStack.toString().trimRight().split('\n')).join('\n'));
|
||||
'was called, this was the stack',
|
||||
scope.creationStack,
|
||||
));
|
||||
}
|
||||
throw FlutterError(message.toString().trimRight());
|
||||
throw FlutterError.fromParts(information);
|
||||
}
|
||||
|
||||
/// Verifies that there are no guarded methods currently pending (see [guard]).
|
||||
@@ -266,21 +269,23 @@ class TestAsyncUtils {
|
||||
/// This is used at the end of tests to ensure that nothing leaks out of the test.
|
||||
static void verifyAllScopesClosed() {
|
||||
if (_scopeStack.isNotEmpty) {
|
||||
final StringBuffer message = StringBuffer();
|
||||
message.writeln('Asynchronous call to guarded function leaked. You must use "await" with all Future-returning test APIs.');
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[
|
||||
ErrorSummary('Asynchronous call to guarded function leaked.'),
|
||||
ErrorHint('You must use "await" with all Future-returning test APIs.')
|
||||
];
|
||||
for (_AsyncScope scope in _scopeStack) {
|
||||
final _StackEntry guarder = _findResponsibleMethod(scope.creationStack, 'guard', message);
|
||||
final _StackEntry guarder = _findResponsibleMethod(scope.creationStack, 'guard', information);
|
||||
if (guarder != null) {
|
||||
message.writeln(
|
||||
information.add(ErrorDescription(
|
||||
'The guarded method "${guarder.methodName}" '
|
||||
'${guarder.className != null ? "from class ${guarder.className} " : ""}'
|
||||
'was called from ${guarder.callerFile} '
|
||||
'on line ${guarder.callerLine}, '
|
||||
'but never completed before its parent scope closed.'
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
throw FlutterError(message.toString().trimRight());
|
||||
throw FlutterError.fromParts(information);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +293,7 @@ class TestAsyncUtils {
|
||||
return line != '<asynchronous suspension>';
|
||||
}
|
||||
|
||||
static _StackEntry _findResponsibleMethod(StackTrace rawStack, String method, StringBuffer errors) {
|
||||
static _StackEntry _findResponsibleMethod(StackTrace rawStack, String method, List<DiagnosticsNode> information) {
|
||||
assert(method == 'guard' || method == 'guardSync');
|
||||
final List<String> stack = rawStack.toString().split('\n').where(_stripAsynchronousSuspensions).toList();
|
||||
assert(stack.last == '');
|
||||
@@ -334,18 +339,18 @@ class TestAsyncUtils {
|
||||
// One reason you might get here is if the guarding method was called directly from
|
||||
// a 'dart:' API, like from the Future/microtask mechanism, because dart: URLs in the
|
||||
// stack trace don't have a column number and so don't match the regexp above.
|
||||
errors.writeln('(Unable to parse the stack frame of the method that called the method that called $_className.$method(). The stack may be incomplete or bogus.)');
|
||||
errors.writeln('${stack[index]}');
|
||||
information.add(ErrorSummary('(Unable to parse the stack frame of the method that called the method that called $_className.$method(). The stack may be incomplete or bogus.)'));
|
||||
information.add(ErrorDescription('${stack[index]}'));
|
||||
}
|
||||
} else {
|
||||
errors.writeln('(Unable to find the stack frame of the method that called the method that called $_className.$method(). The stack may be incomplete or bogus.)');
|
||||
information.add(ErrorSummary('(Unable to find the stack frame of the method that called the method that called $_className.$method(). The stack may be incomplete or bogus.)'));
|
||||
}
|
||||
} else {
|
||||
errors.writeln('(Unable to parse the stack frame of the method that called $_className.$method(). The stack may be incomplete or bogus.)');
|
||||
errors.writeln('${stack[index]}');
|
||||
information.add(ErrorSummary('(Unable to parse the stack frame of the method that called $_className.$method(). The stack may be incomplete or bogus.)'));
|
||||
information.add(ErrorDescription('${stack[index]}'));
|
||||
}
|
||||
} else {
|
||||
errors.writeln('(Unable to find the method that called $_className.$method(). The stack may be incomplete or bogus.)');
|
||||
information.add(ErrorSummary('(Unable to find the method that called $_className.$method(). The stack may be incomplete or bogus.)'));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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