| Index: compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java
|
| diff --git a/compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java b/compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java
|
| index 8033bc1d62918bac8cefecc52ce6de87553279fb..e10948e6b80ee7622b0777c70551673f4435d89d 100644
|
| --- a/compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java
|
| +++ b/compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java
|
| @@ -1,7 +1,6 @@
|
| // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
| -
|
| package com.google.dart.compiler.common;
|
|
|
| import com.google.dart.compiler.DartCompilationError;
|
| @@ -12,58 +11,88 @@ import junit.framework.Assert;
|
| import java.util.List;
|
|
|
| public class ErrorExpectation {
|
| + private final String sourceName;
|
| final ErrorCode errorCode;
|
| final int line;
|
| final int column;
|
| final int length;
|
|
|
| - public ErrorExpectation(ErrorCode errorCode, int line, int column, int length) {
|
| + public ErrorExpectation(String sourceName, ErrorCode errorCode, int line, int column, int length) {
|
| + this.sourceName = sourceName;
|
| this.errorCode = errorCode;
|
| this.line = line;
|
| this.column = column;
|
| this.length = length;
|
| }
|
|
|
| + public static ErrorExpectation errEx(String sourceName,
|
| + ErrorCode errorCode,
|
| + int line,
|
| + int column,
|
| + int length) {
|
| + sourceName = sourceName != null ? sourceName : "";
|
| + return new ErrorExpectation(sourceName, errorCode, line, column, length);
|
| + }
|
| +
|
| public static ErrorExpectation errEx(ErrorCode errorCode, int line, int column, int length) {
|
| - return new ErrorExpectation(errorCode, line, column, length);
|
| + return new ErrorExpectation("", errorCode, line, column, length);
|
| }
|
|
|
| - public static void formatExpectations(StringBuffer out, List<DartCompilationError> errors,
|
| - ErrorExpectation[] expectedErrors) {
|
| + public static void formatExpectations(StringBuffer out,
|
| + List<DartCompilationError> errors,
|
| + ErrorExpectation[] expectedErrors) {
|
| out.append(String.format("Expected %d errors\n", expectedErrors.length));
|
| - for (ErrorExpectation errEx : expectedErrors) {
|
| - out.append(String.format(" %s (%d,%d/%d)\n", errEx.errorCode.toString(),
|
| - errEx.line, errEx.column, errEx.length));
|
| + boolean hasExpectedSourceName = false;
|
| + for (ErrorExpectation expected : expectedErrors) {
|
| + hasExpectedSourceName |= expected.sourceName.length() != 0;
|
| + out.append(String.format(
|
| + " %s %s (%d,%d/%d)\n",
|
| + expected.sourceName,
|
| + expected.errorCode.toString(),
|
| + expected.line,
|
| + expected.column,
|
| + expected.length));
|
| }
|
| out.append(String.format("Encountered %d errors\n", errors.size()));
|
| - for (DartCompilationError error : errors) {
|
| - out.append(String.format(" %s (%d,%d/%d): %s\n", error.getErrorCode().toString(),
|
| - error.getLineNumber(), error.getColumnNumber(),
|
| - error.getLength(), error.getMessage()));
|
| + for (DartCompilationError actual : errors) {
|
| + String sourceName =
|
| + hasExpectedSourceName && actual.getSource() != null ? actual.getSource().getName() : "";
|
| + out.append(String.format(
|
| + " %s %s (%d,%d/%d): %s\n",
|
| + sourceName,
|
| + actual.getErrorCode().toString(),
|
| + actual.getLineNumber(),
|
| + actual.getColumnNumber(),
|
| + actual.getLength(),
|
| + actual.getMessage()));
|
| }
|
| }
|
| +
|
| /**
|
| * Asserts that given list of {@link DartCompilationError} is exactly same as expected.
|
| */
|
| public static void assertErrors(List<DartCompilationError> errors,
|
| - ErrorExpectation... expectedErrors) {
|
| + ErrorExpectation... expectedErrors) {
|
| StringBuffer errorMessage = new StringBuffer();
|
| // count of errors
|
| if (errors.size() != expectedErrors.length) {
|
| - errorMessage.append(String.format("Wrong number of errors encountered\n",
|
| - expectedErrors.length,
|
| - errors.size()));
|
| -
|
| + errorMessage.append(String.format(
|
| + "Wrong number of errors encountered\n",
|
| + expectedErrors.length,
|
| + errors.size()));
|
| formatExpectations(errorMessage, errors, expectedErrors);
|
| } else {
|
| // content of errors
|
| for (int i = 0; i < expectedErrors.length; i++) {
|
| - ErrorExpectation expectedError = expectedErrors[i];
|
| - DartCompilationError actualError = errors.get(i);
|
| - if (actualError.getErrorCode() != expectedError.errorCode
|
| - || actualError.getLineNumber() != expectedError.line
|
| - || actualError.getColumnNumber() != expectedError.column
|
| - || actualError.getLength() != expectedError.length) {
|
| + ErrorExpectation expected = expectedErrors[i];
|
| + DartCompilationError actual = errors.get(i);
|
| + String expectedSourceName = expected.sourceName;
|
| + String actualSourceName = actual.getSource() != null ? actual.getSource().getName() : "";
|
| + if (actual.getErrorCode() != expected.errorCode
|
| + || actual.getLineNumber() != expected.line
|
| + || actual.getColumnNumber() != expected.column
|
| + || actual.getLength() != expected.length
|
| + || !(expectedSourceName.length() == 0 || expectedSourceName.equals(actualSourceName))) {
|
| errorMessage.append(String.format("Expected errors didn't match actual\n"));
|
| formatExpectations(errorMessage, errors, expectedErrors);
|
| break;
|
|
|