Skip to content

Commit 9c3e1a1

Browse files
munificentCommit Queue
authored andcommitted
Remove support for multi-line error messages in static error tests.
The static error test format allows an expected error message to contain newlines like: ```dart some bad code; // [cfe] The error message // is two lines long. ``` Here, the expected error is "The error message\nistwo lines long." This has an unfortunate side effect in that if you have a comment immediately after a static error expectation, it will be treated as part of the expected error: ```dart some bad code; // [cfe] Error. // Unrelated comment. ``` This will expect the CFE to report "Error.\nUnrelated comment." I looked at every static error test and there are no intentional uses of multi-line expectations. The only two I found were both bugs. Since this functionality is unused and error-prone, this CL removes it. Error expectations can only be one line. Fix #60137. Change-Id: I7edb1f60a0c87d4160b93810806de49bc8f55b15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412185 Auto-Submit: Bob Nystrom <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 13d11b4 commit 9c3e1a1

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

pkg/test_runner/lib/src/static_error.dart

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,6 @@ class _ErrorExpectationParser {
504504
/// "unspecified".
505505
static final _errorCodeRegExp = RegExp(r"^(?:\w+\.\w+|unspecified)$");
506506

507-
/// Any line-comment-only lines after the first line of a CFE error message
508-
/// are part of it.
509-
static final _errorMessageRestRegExp = RegExp(r"^\s*//\s*(.*)");
510-
511507
final String path;
512508
final List<String> _lines;
513509
final List<StaticError> _errors = [];
@@ -602,27 +598,6 @@ class _ErrorExpectationParser {
602598
_advance();
603599
var sourceLines = {locationLine, _currentLine};
604600

605-
// Consume as many additional error message lines as we find.
606-
while (_canPeek(1)) {
607-
var nextLine = _peek(1);
608-
609-
// A location line shouldn't be treated as part of the message.
610-
if (_caretLocationRegExp.hasMatch(nextLine)) break;
611-
if (_explicitLocationRegExp.hasMatch(nextLine)) break;
612-
613-
// The next source should not be treated as part of the message.
614-
if (_errorMessageRegExp.hasMatch(nextLine)) break;
615-
616-
var messageMatch = _errorMessageRestRegExp.firstMatch(nextLine);
617-
if (messageMatch == null) break;
618-
619-
message
620-
..write("\n")
621-
..write(messageMatch[1]!);
622-
_advance();
623-
sourceLines.add(_currentLine);
624-
}
625-
626601
if (source == ErrorSource.analyzer &&
627602
!_errorCodeRegExp.hasMatch(message.toString())) {
628603
_fail("An analyzer error expectation should be a dotted identifier.");

pkg/test_runner/test/test_file_test.dart

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -336,35 +336,20 @@ num j = "str";
336336
makeError(line: 10, column: 9, cfeError: "No length.")
337337
]);
338338

339-
// Multi-line error message.
339+
// Comment after error message.
340340
expectParseErrorExpectations("""
341341
int i = "s";
342342
/\/ ^^^
343343
/\/ [analyzer] CompileTimeErrorCode.WRONG_TYPE
344-
/\/ [cfe] First line.
345-
/\/Second line.
346-
/\/ Third line.
347-
/\/ [web] Web first line.
348-
/\/Web second line.
349-
/\/ Web third line.
350-
351-
/\/ The preceding blank line ends the message.
344+
/\/ [cfe] Error message.
345+
/\/ Unrelated comment.
352346
""", [
353347
makeError(
354348
line: 1,
355349
column: 9,
356350
length: 3,
357351
analyzerError: "CompileTimeErrorCode.WRONG_TYPE"),
358-
makeError(
359-
line: 1,
360-
column: 9,
361-
length: 3,
362-
cfeError: "First line.\nSecond line.\nThird line."),
363-
makeError(
364-
line: 1,
365-
column: 9,
366-
length: 3,
367-
webError: "Web first line.\nWeb second line.\nWeb third line.")
352+
makeError(line: 1, column: 9, length: 3, cfeError: "Error message."),
368353
]);
369354

370355
// Multiple errors attached to same line.
@@ -425,16 +410,14 @@ int n = "s";
425410
int i = "s";
426411
/\/ ^^^ /\/# 0: ok
427412
/\/ [analyzer] ErrorCode.BAD_THING /\/# 123: continued
428-
/\/ [cfe] Message. /\/# named: compile-time error
429-
/\/ More message. /\/# another: ok
413+
/\/ [cfe] Message 1. /\/# named: compile-time error
430414
/\/ [error line 12, column 34, length 56] /\/# 3: continued
431-
/\/ [cfe] Message.
415+
/\/ [cfe] Message 2.
432416
""", [
433417
makeError(
434418
line: 1, column: 9, length: 3, analyzerError: "ErrorCode.BAD_THING"),
435-
makeError(
436-
line: 1, column: 9, length: 3, cfeError: "Message.\nMore message."),
437-
makeError(line: 12, column: 34, length: 56, cfeError: "Message."),
419+
makeError(line: 1, column: 9, length: 3, cfeError: "Message 1."),
420+
makeError(line: 12, column: 34, length: 56, cfeError: "Message 2."),
438421
]);
439422

440423
// Allow front ends in any order.

0 commit comments

Comments
 (0)