| 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/task/strong/checker.dart'; | 18 import 'package:analyzer/src/task/strong/checker.dart'; |
| 19 import 'package:analyzer/src/task/strong/rules.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 import 'package:plugin/manager.dart'; |
| 23 | 24 |
| 24 /// Run the checker on a program with files contents as indicated in | 25 /// Run the checker on a program with files contents as indicated in |
| 25 /// [testFiles]. | 26 /// [testFiles]. |
| 26 /// | 27 /// |
| 27 /// This function makes several assumptions to make it easier to describe error | 28 /// This function makes several assumptions to make it easier to describe error |
| 28 /// expectations: | 29 /// expectations: |
| 29 /// | 30 /// |
| 30 /// * a file named `/main.dart` exists in [testFiles]. | 31 /// * a file named `/main.dart` exists in [testFiles]. |
| 31 /// * all expected failures are listed in the source code using comments | 32 /// * all expected failures are listed in the source code using comments |
| 32 /// immediately in front of the AST node that should contain the error. | 33 /// immediately in front of the AST node that should contain the error. |
| 33 /// * errors are formatted as a token `level:Type`, where `level` is the | 34 /// * errors are formatted as a token `level:Type`, where `level` is the |
| 34 /// logging level were the error would be reported at, and `Type` is the | 35 /// logging level were the error would be reported at, and `Type` is the |
| 35 /// concrete subclass of [StaticInfo] that denotes the error. | 36 /// concrete subclass of [StaticInfo] that denotes the error. |
| 36 /// | 37 /// |
| 37 /// For example, to check that an assignment produces a warning about a boxing | 38 /// For example, to check that an assignment produces a warning about a boxing |
| 38 /// conversion, you can describe the test as follows: | 39 /// conversion, you can describe the test as follows: |
| 39 /// | 40 /// |
| 40 /// testChecker({ | 41 /// testChecker({ |
| 41 /// '/main.dart': ''' | 42 /// '/main.dart': ''' |
| 42 /// testMethod() { | 43 /// testMethod() { |
| 43 /// dynamic x = /*warning:Box*/3; | 44 /// dynamic x = /*warning:Box*/3; |
| 44 /// } | 45 /// } |
| 45 /// ''' | 46 /// ''' |
| 46 /// }); | 47 /// }); |
| 47 /// | 48 /// |
| 48 void testChecker(String name, Map<String, String> testFiles) { | 49 void testChecker(String name, Map<String, String> testFiles) { |
| 49 test(name, () { | 50 test(name, () { |
| 51 ExtensionManager extensionManager = new ExtensionManager(); |
| 52 extensionManager.processPlugins(AnalysisEngine.instance.supportedPlugins); |
| 53 |
| 50 expect(testFiles.containsKey('/main.dart'), isTrue, | 54 expect(testFiles.containsKey('/main.dart'), isTrue, |
| 51 reason: '`/main.dart` is missing in testFiles'); | 55 reason: '`/main.dart` is missing in testFiles'); |
| 52 | 56 |
| 53 var provider = new MemoryResourceProvider(); | 57 var provider = new MemoryResourceProvider(); |
| 54 testFiles.forEach((key, value) { | 58 testFiles.forEach((key, value) { |
| 55 var scheme = 'package:'; | 59 var scheme = 'package:'; |
| 56 if (key.startsWith(scheme)) { | 60 if (key.startsWith(scheme)) { |
| 57 key = '/packages/${key.substring(scheme.length)}'; | 61 key = '/packages/${key.substring(scheme.length)}'; |
| 58 } | 62 } |
| 59 provider.newFile(key, value); | 63 provider.newFile(key, value); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 if (levelName == 'warning') return _MAGENTA_COLOR; | 495 if (levelName == 'warning') return _MAGENTA_COLOR; |
| 492 if (levelName == 'info') return _CYAN_COLOR; | 496 if (levelName == 'info') return _CYAN_COLOR; |
| 493 return null; | 497 return null; |
| 494 } | 498 } |
| 495 | 499 |
| 496 const String _RED_COLOR = '\u001b[31m'; | 500 const String _RED_COLOR = '\u001b[31m'; |
| 497 const String _MAGENTA_COLOR = '\u001b[35m'; | 501 const String _MAGENTA_COLOR = '\u001b[35m'; |
| 498 const String _CYAN_COLOR = '\u001b[36m'; | 502 const String _CYAN_COLOR = '\u001b[36m'; |
| 499 const String GREEN_COLOR = '\u001b[32m'; | 503 const String GREEN_COLOR = '\u001b[32m'; |
| 500 const String NO_COLOR = '\u001b[0m'; | 504 const String NO_COLOR = '\u001b[0m'; |
| OLD | NEW |