mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Be more consistent about how stack traces are output from flutter_test (#9361)
This commit is contained in:
parent
62613ddf6e
commit
00dfa224d1
|
@ -0,0 +1,58 @@
|
|||
[^═]*(this line contains the test framework's output with the clock and so forth)?
|
||||
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
|
||||
The following message was thrown running a test:
|
||||
Who lives, who dies, who tells your story\?
|
||||
|
||||
When the exception was thrown, this was the stack:
|
||||
#0 main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:10:5\)
|
||||
<asynchronous suspension>
|
||||
#1 .+ \(package:flutter_test[/\\]src[/\\]widget_tester\.dart:[0-9]+:[0-9]+\)
|
||||
<<skip until matching line>>
|
||||
^\(elided [0-9]+ .+[^)]$
|
||||
^.+\)$
|
||||
|
||||
The test description was:
|
||||
Exception handling in test harness - string
|
||||
════════════════════════════════════════════════════════════════════════════════════════════════════
|
||||
.*(this line has more of the test framework's output)?
|
||||
Test failed\. See exception logs above\.
|
||||
*
|
||||
[^═]*(this line contains the test framework's output with the clock and so forth)?
|
||||
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
|
||||
The following assertion was thrown running a test:
|
||||
Who lives, who dies, who tells your story\?
|
||||
|
||||
When the exception was thrown, this was the stack:
|
||||
#0 main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:13:5\)
|
||||
<asynchronous suspension>
|
||||
#1 .+ \(package:flutter_test[/\\]src[/\\]widget_tester\.dart:[0-9]+:[0-9]+\)
|
||||
<<skip until matching line>>
|
||||
^\(elided [0-9]+ .+[^)]$
|
||||
^.+\)$
|
||||
|
||||
The test description was:
|
||||
Exception handling in test harness - FlutterError
|
||||
════════════════════════════════════════════════════════════════════════════════════════════════════
|
||||
.*(this line has more of the test framework's output)?
|
||||
Test failed\. See exception logs above\.
|
||||
*
|
||||
[^═]*(this line contains the test framework's output with the clock and so forth)?
|
||||
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
|
||||
The following message was thrown running a test:
|
||||
Who lives, who dies, who tells your story\?
|
||||
|
||||
When the exception was thrown, this was the stack:
|
||||
#[0-9]+ +main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:16:9\)
|
||||
#[0-9]+ +main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:15:105\)
|
||||
#[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]widget_tester\.dart:[0-9]+:[0-9]+\)
|
||||
<<skip until matching line>>
|
||||
^\(elided [0-9]+ .+[^)]$
|
||||
^.+\)$
|
||||
|
||||
The test description was:
|
||||
Exception handling in test harness - uncaught Future error
|
||||
════════════════════════════════════════════════════════════════════════════════════════════════════
|
||||
.*(this line has more of the test framework's output)?
|
||||
Test failed\. See exception logs above\.
|
||||
*
|
||||
.*..:.. \+0 -3: Some tests failed\. *
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2017 The Chromium 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 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Exception handling in test harness - string', (WidgetTester tester) async {
|
||||
throw 'Who lives, who dies, who tells your story?';
|
||||
});
|
||||
testWidgets('Exception handling in test harness - FlutterError', (WidgetTester tester) async {
|
||||
throw new FlutterError('Who lives, who dies, who tells your story?');
|
||||
});
|
||||
testWidgets('Exception handling in test harness - uncaught Future error', (WidgetTester tester) async {
|
||||
new Future<Null>.error('Who lives, who dies, who tells your story?');
|
||||
});
|
||||
}
|
|
@ -18,6 +18,7 @@ import 'package:meta/meta.dart';
|
|||
import 'package:quiver/testing/async.dart';
|
||||
import 'package:quiver/time.dart';
|
||||
import 'package:test/test.dart' as test_package;
|
||||
import 'package:stack_trace/stack_trace.dart' as stack_trace;
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
import 'stack_manipulation.dart';
|
||||
|
@ -353,7 +354,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
// will see them in the logs at some point.
|
||||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
stack: _unmangle(stack),
|
||||
context: 'running a test (but after the test had completed)',
|
||||
library: 'Flutter test framework'
|
||||
), forceReport: true);
|
||||
|
@ -394,7 +395,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||
final int stackLinesToOmit = reportExpectCall(stack, expectLine);
|
||||
FlutterError.reportError(new FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
stack: _unmangle(stack),
|
||||
context: 'running a test',
|
||||
library: 'Flutter test framework',
|
||||
stackFilter: (Iterable<String> frames) {
|
||||
|
@ -1021,3 +1022,11 @@ class _EmptyStack implements StackTrace {
|
|||
@override
|
||||
String toString() => '';
|
||||
}
|
||||
|
||||
StackTrace _unmangle(StackTrace stack) {
|
||||
if (stack is stack_trace.Trace)
|
||||
return stack.vmTrace;
|
||||
if (stack is stack_trace.Chain)
|
||||
return stack.toTrace().vmTrace;
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -9,3 +9,8 @@ dependencies:
|
|||
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
# We import stack_trace because the test packages uses it and we
|
||||
# need to be able to unmangle the stack traces that it passed to
|
||||
# stack_trace. See https://github.com/dart-lang/test/issues/590
|
||||
stack_trace: any # use version expected by test package
|
||||
|
|
|
@ -23,6 +23,11 @@ void main() {
|
|||
final String automatedTestsDirectory = fs.path.join('..', '..', 'dev', 'automated_tests');
|
||||
final String flutterTestDirectory = fs.path.join(automatedTestsDirectory, 'flutter_test');
|
||||
|
||||
testUsingContext('Exception handling in test harness', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
return _testFile('exception_handling', automatedTestsDirectory, flutterTestDirectory);
|
||||
});
|
||||
|
||||
testUsingContext('TestAsyncUtils guarded function test', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
return _testFile('test_async_utils_guarded', automatedTestsDirectory, flutterTestDirectory);
|
||||
|
|
Loading…
Reference in a new issue