Chromium Code Reviews| 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 ef533db58d02d933b37b462b2d348dd3f53184e6..7312a0d0d0c7ebe43f109ea723fa8b98bc460361 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,20 +11,30 @@ 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) { |
| + 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(null, errorCode, line, column, length); |
|
codefu
2012/01/19 21:48:54
Nit: could be "", which makes the code in assertEr
scheglov
2012/01/20 15:59:24
Done.
|
| } |
| /** |
| @@ -46,23 +55,36 @@ public class ErrorExpectation { |
| } 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 error = errors.get(i); |
| + String actualSourceName = error.getSource() != null ? error.getSource().getName() : ""; |
| + if (error.getErrorCode() != expected.errorCode |
| + || error.getLineNumber() != expected.line |
| + || error.getColumnNumber() != expected.column |
| + || error.getLength() != expected.length |
| + || !(expected.sourceName == null || expected.sourceName.equals(actualSourceName))) { |
| + // Prepare names of sources. |
| + String expectedSourceName; |
| + if (expected.sourceName != null) { |
| + expectedSourceName = expected.sourceName; |
| + } else { |
| + expectedSourceName = ""; |
| + actualSourceName = ""; |
| + } |
| + // Add error mismatch. |
| String out = |
| String.format( |
| - "Expected %s:%d:%d/%d, but got %s:%d:%d/%d", |
| - expectedError.errorCode, |
| - expectedError.line, |
| - expectedError.column, |
| - expectedError.length, |
| - actualError.getErrorCode(), |
| - actualError.getLineNumber(), |
| - actualError.getColumnNumber(), |
| - actualError.getLength()); |
| + "Expected %s %s:%d:%d/%d, but got %s %s:%d:%d/%d", |
| + expectedSourceName, |
| + expected.errorCode, |
| + expected.line, |
| + expected.column, |
| + expected.length, |
| + actualSourceName, |
| + error.getErrorCode(), |
| + error.getLineNumber(), |
| + error.getColumnNumber(), |
| + error.getLength()); |
| errorMessage.append(out + "\n"); |
| } |
| } |