Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.services.src.index.abstract_single_file; | 5 library test.services.src.index.abstract_single_file; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/error/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
| 11 import 'package:analyzer/src/dart/ast/utilities.dart'; | 11 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 12 import 'package:analyzer/src/dart/error/hint_codes.dart'; | |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 13 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
| 15 | 16 |
| 16 import 'abstract_context.dart'; | 17 import 'abstract_context.dart'; |
| 17 | 18 |
| 18 class AbstractSingleUnitTest extends AbstractContextTest { | 19 class AbstractSingleUnitTest extends AbstractContextTest { |
| 19 bool verifyNoTestUnitErrors = true; | 20 bool verifyNoTestUnitErrors = true; |
| 20 | 21 |
| 21 String testCode; | 22 String testCode; |
| 22 String testFile = '/test.dart'; | 23 String testFile = '/test.dart'; |
| 23 Source testSource; | 24 Source testSource; |
| 24 CompilationUnit testUnit; | 25 CompilationUnit testUnit; |
| 25 CompilationUnitElement testUnitElement; | 26 CompilationUnitElement testUnitElement; |
| 26 LibraryElement testLibraryElement; | 27 LibraryElement testLibraryElement; |
| 27 | 28 |
| 28 void addTestSource(String code, [Uri uri]) { | 29 void addTestSource(String code, [Uri uri]) { |
| 29 testCode = code; | 30 testCode = code; |
| 30 testSource = addSource(testFile, code, uri); | 31 testSource = addSource(testFile, code, uri); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void assertNoErrorsInSource(Source source) { | |
| 34 List<AnalysisError> errors = context.getErrors(source).errors; | |
| 35 expect(errors, isEmpty); | |
| 36 } | |
| 37 | |
| 38 Element findElement(String name, [ElementKind kind]) { | 34 Element findElement(String name, [ElementKind kind]) { |
| 39 return findChildElement(testUnitElement, name, kind); | 35 return findChildElement(testUnitElement, name, kind); |
| 40 } | 36 } |
| 41 | 37 |
| 42 int findEnd(String search) { | 38 int findEnd(String search) { |
| 43 return findOffset(search) + search.length; | 39 return findOffset(search) + search.length; |
| 44 } | 40 } |
| 45 | 41 |
| 46 /** | 42 /** |
| 47 * Returns the [SimpleIdentifier] at the given search pattern. | 43 * Returns the [SimpleIdentifier] at the given search pattern. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 length++; | 90 length++; |
| 95 continue; | 91 continue; |
| 96 } | 92 } |
| 97 break; | 93 break; |
| 98 } | 94 } |
| 99 return length; | 95 return length; |
| 100 } | 96 } |
| 101 | 97 |
| 102 Future<Null> resolveTestUnit(String code) async { | 98 Future<Null> resolveTestUnit(String code) async { |
| 103 addTestSource(code); | 99 addTestSource(code); |
| 104 testUnit = await resolveLibraryUnit(testSource); | 100 if (enableNewAnalysisDriver) { |
| 105 if (verifyNoTestUnitErrors) { | 101 var result = await driver.getResult(testFile); |
| 106 assertNoErrorsInSource(testSource); | 102 testUnit = (result).unit; |
| 103 if (verifyNoTestUnitErrors) { | |
| 104 expect(result.errors.where((AnalysisError error) { | |
| 105 return | |
| 106 error.errorCode != HintCode.DEAD_CODE && | |
| 107 error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && | |
| 108 error.errorCode != HintCode.UNUSED_CATCH_STACK && | |
| 109 error.errorCode != HintCode.UNUSED_ELEMENT && | |
| 110 error.errorCode != HintCode.UNUSED_FIELD && | |
| 111 error.errorCode != HintCode.UNUSED_IMPORT && | |
| 112 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; | |
|
Brian Wilkerson
2017/01/06 00:01:40
Why do we need to filter here when we don't need t
scheglov
2017/01/06 00:03:28
The old driver does not generate hints.
Brian Wilkerson
2017/01/06 00:07:37
Perhaps a comment to that effect? And it might be
| |
| 113 }), isEmpty); | |
| 114 } | |
| 115 } else { | |
| 116 testUnit = await resolveLibraryUnit(testSource); | |
| 117 if (verifyNoTestUnitErrors) { | |
| 118 expect(context.getErrors(testSource).errors, isEmpty); | |
| 119 } | |
| 107 } | 120 } |
| 108 testUnitElement = testUnit.element; | 121 testUnitElement = testUnit.element; |
| 109 testLibraryElement = testUnitElement.library; | 122 testLibraryElement = testUnitElement.library; |
| 110 } | 123 } |
| 111 } | 124 } |
| OLD | NEW |