Chromium Code Reviews| Index: pkg/analyzer/test/generated/error_suppression_test.dart |
| diff --git a/pkg/analyzer/test/generated/error_suppression_test.dart b/pkg/analyzer/test/generated/error_suppression_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..04457d92ec325fb5393763d3a6518c34583ab7ac |
| --- /dev/null |
| +++ b/pkg/analyzer/test/generated/error_suppression_test.dart |
| @@ -0,0 +1,196 @@ |
| +// Copyright (c) 2016, 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. |
| + |
| +import 'package:analyzer/src/generated/engine.dart'; |
| +import 'package:analyzer/src/generated/error.dart'; |
| +import 'package:analyzer/src/generated/java_engine_io.dart'; |
| +import 'package:analyzer/src/generated/source.dart'; |
| +import 'package:analyzer/src/generated/source_io.dart'; |
| + |
| +import '../reflective_tests.dart'; |
| +import '../utils.dart'; |
| +import 'resolver_test.dart'; |
| +import 'test_support.dart'; |
| + |
| +main() { |
| + initializeTestEnvironment(); |
| + runReflectiveTests(ErrorSuppressionTest); |
| +} |
| + |
| +@reflectiveTest |
| +class ErrorSuppressionTest extends EngineTestCase { |
|
Brian Wilkerson
2016/02/16 21:39:05
A lot of the support code in this class is already
pquitslund
2016/02/16 21:51:42
Funny. I started that way and then convinced myse
|
| + InternalAnalysisContext analysisContext; |
| + |
| + Source addNamedSource(String filePath, String contents) { |
| + Source source = cacheSource(filePath, contents); |
| + ChangeSet changeSet = new ChangeSet(); |
| + changeSet.addedSource(source); |
| + analysisContext.applyChanges(changeSet); |
| + return source; |
| + } |
| + |
| + Source addSource(String contents) => addNamedSource("/test.dart", contents); |
| + |
| + void assertErrors(Source source, |
| + [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { |
| + GatheringErrorListener errorListener = new GatheringErrorListener(); |
| + for (AnalysisError error in analysisContext.computeErrors(source)) { |
| + errorListener.onError(error); |
| + } |
| + errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| + } |
| + |
| + Source cacheSource(String filePath, String contents) { |
| + Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); |
| + analysisContext.setContents(source, contents); |
| + return source; |
| + } |
| + |
| + void computeLibrarySourceErrors(Source librarySource) { |
| + analysisContext.computeErrors(librarySource); |
| + } |
| + |
| + void reset() { |
| + analysisContext = AnalysisContextFactory.contextWithCore(); |
| + } |
| + |
| + @override |
| + void setUp() { |
| + super.setUp(); |
| + reset(); |
| + } |
| + |
| + void test_error_code_mismatch() { |
| + Source source = addSource(''' |
| +//# ignore: const_initialized_with_non_constant_value |
| +int x = ''; |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [ |
| + StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| + ]); |
| + } |
| + |
| + void test_ignore_first() { |
| + Source source = addSource(''' |
| +//# ignore: invalid_assignment |
| +int x = ''; |
| +// ... but no ignore here ... |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, |
| + [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| + } |
| + |
| + void test_ignore_second() { |
| + Source source = addSource(''' |
| +//INVALID_ASSIGNMENT |
| +int x = ''; |
| +//# ignore: const_initialized_with_non_constant_value |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| + } |
| + |
| + void test_invalid_error_code() { |
| + Source source = addSource(''' |
| +//# ignore: right_format_wrong_code |
| +int x = ''; |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [ |
| + StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| + ]); |
| + } |
| + |
| + void test_missing_error_codes() { |
| + Source source = addSource(''' |
| + int x = 3; |
| +//# ignore: |
| +const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [ |
| + StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| + ]); |
| + } |
| + |
| + void test_missing_metadata_prefix() { |
| + Source source = addSource(''' |
| +// ignore: invalid_assignment |
| +String y = 3; //INVALID_ASSIGNMENT |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| + } |
| + |
| + void test_multiple_comments() { |
| + Source source = addSource(''' |
| +int x = ''; //This is the first comment... |
| +//# ignore: const_initialized_with_non_constant_value |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| + } |
| + |
| + void test_multiple_ignores() { |
| + Source source = addSource(''' |
| +int x = 3; |
| +//# ignore: invalid_assignment, const_initialized_with_non_constant_value |
| +const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, []); |
| + } |
| + |
| + void test_multiple_ignores_whitespace_variant_1() { |
| + Source source = addSource(''' |
| +int x = 3; |
| +//#ignore:invalid_assignment,const_initialized_with_non_constant_value |
| +const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, []); |
| + } |
| + |
| + void test_multiple_ignores_whitespace_variant_2() { |
| + Source source = addSource(''' |
| +int x = 3; |
| +//#ignore: invalid_assignment,const_initialized_with_non_constant_value |
| +const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, []); |
| + } |
| + |
| + void test_multiple_ignores_whitespace_variant_3() { |
| + Source source = addSource(''' |
| +int x = 3; |
| +//# ignore: invalid_assignment,const_initialized_with_non_constant_value |
| +const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, []); |
| + } |
| + |
| + void test_no_ignores() { |
| + Source source = addSource(''' |
| +int x = ''; //INVALID_ASSIGNMENT |
| +const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| +'''); |
| + computeLibrarySourceErrors(source); |
| + assertErrors(source, [ |
| + StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| + CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| + ]); |
| + } |
| +} |