| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // TODO(jmesserly): this file needs to be refactored, it's a port from | 5 // TODO(jmesserly): this file needs to be refactored, it's a port from |
| 6 // package:dev_compiler's tests | 6 // package:dev_compiler's tests |
| 7 library test.src.task.strong.strong_test_helper; | 7 library test.src.task.strong.strong_test_helper; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 11 import 'package:analyzer/src/context/context.dart' show SdkAnalysisContext; | 11 import 'package:analyzer/src/context/context.dart' show SdkAnalysisContext; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' hide SdkAnalysisContext; | 14 import 'package:analyzer/src/generated/engine.dart' hide SdkAnalysisContext; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; | 16 import 'package:analyzer/src/generated/sdk.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/generated/type_system.dart'; |
| 18 import 'package:analyzer/src/task/strong/checker.dart'; | 19 import 'package:analyzer/src/task/strong/checker.dart'; |
| 19 import 'package:analyzer/src/task/strong/rules.dart'; | |
| 20 import 'package:logging/logging.dart'; // TODO(jmesserly): remove | 20 import 'package:logging/logging.dart'; // TODO(jmesserly): remove |
| 21 import 'package:source_span/source_span.dart'; // TODO(jmesserly): remove | 21 import 'package:source_span/source_span.dart'; // TODO(jmesserly): remove |
| 22 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
| 23 | 23 |
| 24 /// Run the checker on a program with files contents as indicated in | 24 /// Run the checker on a program with files contents as indicated in |
| 25 /// [testFiles]. | 25 /// [testFiles]. |
| 26 /// | 26 /// |
| 27 /// This function makes several assumptions to make it easier to describe error | 27 /// This function makes several assumptions to make it easier to describe error |
| 28 /// expectations: | 28 /// expectations: |
| 29 /// | 29 /// |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 new MockDartSdk(mockSdkSources, reportMissing: true).resolver, | 69 new MockDartSdk(mockSdkSources, reportMissing: true).resolver, |
| 70 uriResolver | 70 uriResolver |
| 71 ]); | 71 ]); |
| 72 | 72 |
| 73 // Run the checker on /main.dart. | 73 // Run the checker on /main.dart. |
| 74 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 74 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); |
| 75 var initialLibrary = | 75 var initialLibrary = |
| 76 context.resolveCompilationUnit2(mainSource, mainSource); | 76 context.resolveCompilationUnit2(mainSource, mainSource); |
| 77 | 77 |
| 78 var collector = new _ErrorCollector(); | 78 var collector = new _ErrorCollector(); |
| 79 var checker = new CodeChecker( | 79 var checker = new CodeChecker(context.typeProvider, |
| 80 new TypeRules(context.typeProvider), collector, | 80 new StrongTypeSystemImpl(), collector, |
| 81 hints: true); | 81 hints: true); |
| 82 | 82 |
| 83 // Extract expectations from the comments in the test files, and | 83 // Extract expectations from the comments in the test files, and |
| 84 // check that all errors we emit are included in the expected map. | 84 // check that all errors we emit are included in the expected map. |
| 85 var allLibraries = reachableLibraries(initialLibrary.element.library); | 85 var allLibraries = reachableLibraries(initialLibrary.element.library); |
| 86 for (var lib in allLibraries) { | 86 for (var lib in allLibraries) { |
| 87 for (var unit in lib.units) { | 87 for (var unit in lib.units) { |
| 88 var errors = <AnalysisError>[]; | 88 var errors = <AnalysisError>[]; |
| 89 collector.errors = errors; | 89 collector.errors = errors; |
| 90 | 90 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (levelName == 'warning') return _MAGENTA_COLOR; | 504 if (levelName == 'warning') return _MAGENTA_COLOR; |
| 505 if (levelName == 'info') return _CYAN_COLOR; | 505 if (levelName == 'info') return _CYAN_COLOR; |
| 506 return null; | 506 return null; |
| 507 } | 507 } |
| 508 | 508 |
| 509 const String _RED_COLOR = '\u001b[31m'; | 509 const String _RED_COLOR = '\u001b[31m'; |
| 510 const String _MAGENTA_COLOR = '\u001b[35m'; | 510 const String _MAGENTA_COLOR = '\u001b[35m'; |
| 511 const String _CYAN_COLOR = '\u001b[36m'; | 511 const String _CYAN_COLOR = '\u001b[36m'; |
| 512 const String GREEN_COLOR = '\u001b[32m'; | 512 const String GREEN_COLOR = '\u001b[32m'; |
| 513 const String NO_COLOR = '\u001b[0m'; | 513 const String NO_COLOR = '\u001b[0m'; |
| OLD | NEW |