mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Escape path separator in regexps (#14122)
* Escape path separator in regexps * Update platform_helper.dart * Update stack_trace_test.dart * Update stack_trace_test.dart
This commit is contained in:
parent
2908997b0e
commit
b0d5d2d928
|
@ -3,11 +3,12 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'platform_helper.dart';
|
||||
|
||||
dynamic getAssertionErrorWithMessage() {
|
||||
try {
|
||||
assert(false, 'Message goes here.');
|
||||
|
@ -44,7 +45,7 @@ Future<Null> main() async {
|
|||
|
||||
final StackTrace sampleStack = await getSampleStack();
|
||||
|
||||
final String divider = Platform.pathSeparator;
|
||||
final String dividerRegExp = pathSeparatorForRegExp;
|
||||
|
||||
test('Error reporting - pretest', () async {
|
||||
expect(debugPrint, equals(debugPrintThrottled));
|
||||
|
@ -65,11 +66,11 @@ Future<Null> main() async {
|
|||
information.writeln('line 2 of extra information\n'); // the double trailing newlines here are intentional
|
||||
},
|
||||
));
|
||||
expect(console.join('\n'), matches(new RegExp(
|
||||
expect(console.join('\n'), matches(
|
||||
'^══╡ EXCEPTION CAUGHT BY ERROR HANDLING TEST ╞═══════════════════════════════════════════════════════\n'
|
||||
'The following assertion was thrown testing the error handling logic:\n'
|
||||
'Message goes here\\.\n'
|
||||
'\'[^\']+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\'\n'
|
||||
'\'[^\']+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\'\n'
|
||||
'\n'
|
||||
'Either the assertion indicates an error in the framework itself, or we should provide substantially '
|
||||
'more information in this error message to help you determine and fix the underlying cause\\.\n'
|
||||
|
@ -77,17 +78,17 @@ Future<Null> main() async {
|
|||
' https://github\\.com/flutter/flutter/issues/new\n'
|
||||
'\n'
|
||||
'When the exception was thrown, this was the stack:\n'
|
||||
'#0 getSampleStack\\.<anonymous closure> \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#2 getSampleStack \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#0 getSampleStack\\.<anonymous closure> \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#2 getSampleStack \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'<asynchronous suspension>\n' // TODO(ianh): https://github.com/flutter/flutter/issues/4021
|
||||
'#3 main \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#3 main \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'(.+\n)+' // TODO(ianh): when fixing #4021, also filter out frames from the test infrastructure below the first call to our main()
|
||||
'\\(elided [0-9]+ frames from package dart:async\\)\n'
|
||||
'\n'
|
||||
'line 1 of extra information\n'
|
||||
'line 2 of extra information\n'
|
||||
'════════════════════════════════════════════════════════════════════════════════════════════════════\$',
|
||||
)));
|
||||
));
|
||||
console.clear();
|
||||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: getAssertionErrorWithMessage(),
|
||||
|
@ -102,7 +103,7 @@ Future<Null> main() async {
|
|||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: getAssertionErrorWithLongMessage(),
|
||||
));
|
||||
expect(console.join('\n'), matches(new RegExp(
|
||||
expect(console.join('\n'), matches(
|
||||
'^══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════\n'
|
||||
'The following assertion was thrown:\n'
|
||||
'word word word word word word word word word word word word word word word word word word word word '
|
||||
|
@ -110,14 +111,14 @@ Future<Null> main() async {
|
|||
'word word word word word word word word word word word word word word word word word word word word '
|
||||
'word word word word word word word word word word word word word word word word word word word word '
|
||||
'word word word word word word word word word word word word word word word word word word word word\n'
|
||||
'\'[^\']+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\'\n'
|
||||
'\'[^\']+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\'\n'
|
||||
'\n'
|
||||
'Either the assertion indicates an error in the framework itself, or we should provide substantially '
|
||||
'more information in this error message to help you determine and fix the underlying cause\\.\n'
|
||||
'In either case, please report this assertion by filing a bug on GitHub:\n'
|
||||
' https://github\\.com/flutter/flutter/issues/new\n'
|
||||
'════════════════════════════════════════════════════════════════════════════════════════════════════\$',
|
||||
)));
|
||||
));
|
||||
console.clear();
|
||||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: getAssertionErrorWithLongMessage(),
|
||||
|
@ -147,10 +148,10 @@ Future<Null> main() async {
|
|||
information.writeln('line 2 of extra information\n'); // the double trailing newlines here are intentional
|
||||
},
|
||||
));
|
||||
expect(console.join('\n'), matches(new RegExp(
|
||||
expect(console.join('\n'), matches(
|
||||
'^══╡ EXCEPTION CAUGHT BY ERROR HANDLING TEST ╞═══════════════════════════════════════════════════════\n'
|
||||
'The following assertion was thrown testing the error handling logic:\n'
|
||||
'\'[^\']+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\': is not true\\.\n'
|
||||
'\'[^\']+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\': is not true\\.\n'
|
||||
'\n'
|
||||
'Either the assertion indicates an error in the framework itself, or we should provide substantially '
|
||||
'more information in this error message to help you determine and fix the underlying cause\\.\n'
|
||||
|
@ -158,22 +159,22 @@ Future<Null> main() async {
|
|||
' https://github\\.com/flutter/flutter/issues/new\n'
|
||||
'\n'
|
||||
'When the exception was thrown, this was the stack:\n'
|
||||
'#0 getSampleStack\\.<anonymous closure> \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#2 getSampleStack \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#0 getSampleStack\\.<anonymous closure> \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#2 getSampleStack \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'<asynchronous suspension>\n' // TODO(ianh): https://github.com/flutter/flutter/issues/4021
|
||||
'#3 main \\([^)]+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'#3 main \\([^)]+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart:[0-9]+:[0-9]+\\)\n'
|
||||
'(.+\n)+' // TODO(ianh): when fixing #4021, also filter out frames from the test infrastructure below the first call to our main()
|
||||
'\\(elided [0-9]+ frames from package dart:async\\)\n'
|
||||
'\n'
|
||||
'line 1 of extra information\n'
|
||||
'line 2 of extra information\n'
|
||||
'════════════════════════════════════════════════════════════════════════════════════════════════════\$',
|
||||
)));
|
||||
));
|
||||
console.clear();
|
||||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: getAssertionErrorWithoutMessage(),
|
||||
));
|
||||
expect(console.join('\n'), matches('Another exception was thrown: \'[^\']+flutter${divider}test${divider}foundation${divider}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\': is not true\\.'));
|
||||
expect(console.join('\n'), matches('Another exception was thrown: \'[^\']+flutter${dividerRegExp}test${dividerRegExp}foundation${dividerRegExp}error_reporting_test\\.dart\': Failed assertion: line [0-9]+ pos [0-9]+: \'false\': is not true\\.'));
|
||||
console.clear();
|
||||
FlutterError.resetErrorCount();
|
||||
});
|
||||
|
@ -184,13 +185,13 @@ Future<Null> main() async {
|
|||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: exception,
|
||||
));
|
||||
expect(console.join('\n'), matches(new RegExp(
|
||||
expect(console.join('\n'), matches(
|
||||
'^══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════\n'
|
||||
'The following NoSuchMethodError was thrown:\n'
|
||||
'Receiver: 5\n'
|
||||
'Tried calling: foo = 2, 4\n'
|
||||
'════════════════════════════════════════════════════════════════════════════════════════════════════\$',
|
||||
)));
|
||||
));
|
||||
console.clear();
|
||||
FlutterError.dumpErrorToConsole(new FlutterErrorDetails(
|
||||
exception: exception,
|
||||
|
@ -205,12 +206,12 @@ Future<Null> main() async {
|
|||
FlutterError.dumpErrorToConsole(const FlutterErrorDetails(
|
||||
exception: 'hello',
|
||||
));
|
||||
expect(console.join('\n'), matches(new RegExp(
|
||||
expect(console.join('\n'), matches(
|
||||
'^══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════\n'
|
||||
'The following message was thrown:\n'
|
||||
'hello\n'
|
||||
'════════════════════════════════════════════════════════════════════════════════════════════════════\$',
|
||||
)));
|
||||
));
|
||||
console.clear();
|
||||
FlutterError.dumpErrorToConsole(const FlutterErrorDetails(
|
||||
exception: 'hello again',
|
||||
|
|
18
packages/flutter/test/foundation/platform_helper.dart
Normal file
18
packages/flutter/test/foundation/platform_helper.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2018 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 'dart:io' show Platform;
|
||||
|
||||
/// Returns [Platform.pathSeparator], suitably escaped so as to be usable in a
|
||||
/// regular expression.
|
||||
String get pathSeparatorForRegExp {
|
||||
switch (Platform.pathSeparator) {
|
||||
case r'/':
|
||||
return r'/';
|
||||
case r'\':
|
||||
return r'\\'; // because dividerRegExp gets inserted into regexps
|
||||
default:
|
||||
throw 'Unsupported platform.';
|
||||
}
|
||||
}
|
|
@ -2,21 +2,21 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'platform_helper.dart';
|
||||
|
||||
void main() {
|
||||
// TODO(8128): These tests and the filtering mechanism should be revisited to account for causal async stack traces.
|
||||
|
||||
final String divider = Platform.pathSeparator;
|
||||
final String dividerRegExp = pathSeparatorForRegExp;
|
||||
|
||||
test('FlutterError.defaultStackFilter', () {
|
||||
final List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
|
||||
expect(filtered.length, greaterThanOrEqualTo(4));
|
||||
expect(filtered[0], matches(r'^#0 +main\.<anonymous closure> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
|
||||
expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>.<anonymous closure> \(package:test' + divider + r'.+:[0-9]+:[0-9]+\)$'));
|
||||
expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>.<anonymous closure> \(package:test' + dividerRegExp + r'.+:[0-9]+:[0-9]+\)$'));
|
||||
expect(filtered[2], equals('<asynchronous suspension>'));
|
||||
expect(filtered.last, matches(r'^\(elided [1-9][0-9]+ frames from package dart:async, package dart:async-patch, and package stack_trace\)$'));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue