| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.analysis.notification_errors; |
| 6 |
| 7 import 'package:analysis_server/src/computer/error.dart'; |
| 8 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analysis_server/src/domain_analysis.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; |
| 11 import 'package:analysis_services/constants.dart'; |
| 12 import 'package:analysis_testing/reflective_tests.dart'; |
| 13 import 'package:unittest/unittest.dart'; |
| 14 |
| 15 import '../analysis_abstract.dart'; |
| 16 |
| 17 |
| 18 main() { |
| 19 groupSep = ' | '; |
| 20 runReflectiveTests(NotificationErrorsTest); |
| 21 } |
| 22 |
| 23 |
| 24 @ReflectiveTestCase() |
| 25 class NotificationErrorsTest extends AbstractAnalysisTest { |
| 26 Map<String, List<AnalysisError>> filesErrors = {}; |
| 27 |
| 28 void processNotification(Notification notification) { |
| 29 if (notification.event == ANALYSIS_ERRORS) { |
| 30 String file = notification.getParameter(FILE); |
| 31 List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS); |
| 32 filesErrors[file] = errorMaps.map(AnalysisError.fromJson).toList(); |
| 33 } |
| 34 } |
| 35 |
| 36 @override |
| 37 void setUp() { |
| 38 super.setUp(); |
| 39 server.handlers = [new AnalysisDomainHandler(server),]; |
| 40 } |
| 41 |
| 42 test_ParserError() { |
| 43 createProject(); |
| 44 addTestFile('library lib'); |
| 45 return waitForTasksFinished().then((_) { |
| 46 List<AnalysisError> errors = filesErrors[testFile]; |
| 47 expect(errors, hasLength(1)); |
| 48 AnalysisError error = errors[0]; |
| 49 expect(error.location.file, '/project/bin/test.dart'); |
| 50 expect(error.location.offset, isPositive); |
| 51 expect(error.location.length, isNonNegative); |
| 52 expect(error.severity, 'ERROR'); |
| 53 expect(error.type, 'SYNTACTIC_ERROR'); |
| 54 expect(error.message, isNotNull); |
| 55 }); |
| 56 } |
| 57 |
| 58 test_StaticWarning() { |
| 59 createProject(); |
| 60 addTestFile(''' |
| 61 main() { |
| 62 print(UNKNOWN); |
| 63 } |
| 64 '''); |
| 65 return waitForTasksFinished().then((_) { |
| 66 List<AnalysisError> errors = filesErrors[testFile]; |
| 67 expect(errors, hasLength(1)); |
| 68 AnalysisError error = errors[0]; |
| 69 expect(error.severity, 'WARNING'); |
| 70 expect(error.type, 'STATIC_WARNING'); |
| 71 }); |
| 72 } |
| 73 |
| 74 test_notInAnalysisRoot() { |
| 75 createProject(); |
| 76 String otherFile = '/other.dart'; |
| 77 addFile(otherFile, 'UnknownType V;'); |
| 78 addTestFile(''' |
| 79 import '/other.dart'; |
| 80 |
| 81 main() { |
| 82 print(V); |
| 83 } |
| 84 '''); |
| 85 return waitForTasksFinished().then((_) { |
| 86 expect(filesErrors[otherFile], isNull); |
| 87 }); |
| 88 } |
| 89 } |
| OLD | NEW |