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.analysis.get_errors; | 5 library test.analysis.get_errors; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/domain_analysis.dart'; | 10 import 'package:analysis_server/src/domain_analysis.dart'; |
(...skipping 25 matching lines...) Expand all Loading... |
36 print(42) | 36 print(42) |
37 } | 37 } |
38 '''); | 38 '''); |
39 return waitForTasksFinished().then((_) { | 39 return waitForTasksFinished().then((_) { |
40 return _getErrors(testFile).then((List<AnalysisError> errors) { | 40 return _getErrors(testFile).then((List<AnalysisError> errors) { |
41 expect(errors, hasLength(1)); | 41 expect(errors, hasLength(1)); |
42 }); | 42 }); |
43 }); | 43 }); |
44 } | 44 } |
45 | 45 |
| 46 test_errorInPart() async { |
| 47 String libPath = '$testFolder/main.dart'; |
| 48 String partPath = '$testFolder/main_part.dart'; |
| 49 addFile( |
| 50 libPath, |
| 51 r''' |
| 52 library main; |
| 53 part 'main_part.dart'; |
| 54 class A {} |
| 55 '''); |
| 56 addFile( |
| 57 partPath, |
| 58 r''' |
| 59 part of main; |
| 60 class A {} |
| 61 '''); |
| 62 await waitForTasksFinished(); |
| 63 { |
| 64 List<AnalysisError> libErrors = await _getErrors(libPath); |
| 65 expect(libErrors, isEmpty); |
| 66 } |
| 67 { |
| 68 List<AnalysisError> partErrors = await _getErrors(partPath); |
| 69 expect(partErrors, hasLength(1)); |
| 70 } |
| 71 } |
| 72 |
46 test_fileDoesNotExist() { | 73 test_fileDoesNotExist() { |
47 String file = '$projectPath/doesNotExist.dart'; | 74 String file = '$projectPath/doesNotExist.dart'; |
48 return _checkInvalid(file); | 75 return _checkInvalid(file); |
49 } | 76 } |
50 | 77 |
51 test_fileWithoutContext() { | 78 test_fileWithoutContext() { |
52 String file = '/outside.dart'; | 79 String file = '/outside.dart'; |
53 addFile( | 80 addFile( |
54 file, | 81 file, |
55 ''' | 82 ''' |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 }); | 116 }); |
90 } | 117 } |
91 | 118 |
92 test_removeContextAfterRequest() { | 119 test_removeContextAfterRequest() { |
93 addTestFile(''' | 120 addTestFile(''' |
94 main() { | 121 main() { |
95 print(42) | 122 print(42) |
96 } | 123 } |
97 '''); | 124 '''); |
98 // handle the request synchronously | 125 // handle the request synchronously |
99 Request request = _createGetErrorsRequest(); | 126 Request request = _createGetErrorsRequest(testFile); |
100 server.handleRequest(request); | 127 server.handleRequest(request); |
101 // remove context, causes sending an "invalid file" error | 128 // remove context, causes sending an "invalid file" error |
102 resourceProvider.deleteFolder(projectPath); | 129 resourceProvider.deleteFolder(projectPath); |
103 // wait for an error response | 130 // wait for an error response |
104 return serverChannel.waitForResponse(request).then((Response response) { | 131 return serverChannel.waitForResponse(request).then((Response response) { |
105 expect(response.error, isNotNull); | 132 expect(response.error, isNotNull); |
106 expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE); | 133 expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE); |
107 }); | 134 }); |
108 } | 135 } |
109 | 136 |
110 Future _checkInvalid(String file) { | 137 Future _checkInvalid(String file) { |
111 Request request = _createGetErrorsRequest(); | 138 Request request = _createGetErrorsRequest(file); |
112 return serverChannel.sendRequest(request).then((Response response) { | 139 return serverChannel.sendRequest(request).then((Response response) { |
113 expect(response.error, isNotNull); | 140 expect(response.error, isNotNull); |
114 expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE); | 141 expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE); |
115 }); | 142 }); |
116 } | 143 } |
117 | 144 |
118 Request _createGetErrorsRequest() { | 145 Request _createGetErrorsRequest(String file) { |
119 return new AnalysisGetErrorsParams(testFile).toRequest(requestId); | 146 return new AnalysisGetErrorsParams(file).toRequest(requestId); |
120 } | 147 } |
121 | 148 |
122 Future<List<AnalysisError>> _getErrors(String file) { | 149 Future<List<AnalysisError>> _getErrors(String file) { |
123 Request request = _createGetErrorsRequest(); | 150 Request request = _createGetErrorsRequest(file); |
124 return serverChannel.sendRequest(request).then((Response response) { | 151 return serverChannel.sendRequest(request).then((Response response) { |
125 return new AnalysisGetErrorsResult.fromResponse(response).errors; | 152 return new AnalysisGetErrorsResult.fromResponse(response).errors; |
126 }); | 153 }); |
127 } | 154 } |
128 } | 155 } |
OLD | NEW |