Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: pkg/analysis_server/test/analysis_server_test.dart

Issue 247893004: Serialize AnalysisErrors to JSON in the analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_server; 5 library test.analysis_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 10 matching lines...) Expand all
21 group('AnalysisServer', () { 21 group('AnalysisServer', () {
22 setUp(AnalysisServerTest.setUp); 22 setUp(AnalysisServerTest.setUp);
23 test('addContextToWorkQueue_twice', 23 test('addContextToWorkQueue_twice',
24 AnalysisServerTest.addContextToWorkQueue_twice); 24 AnalysisServerTest.addContextToWorkQueue_twice);
25 test('addContextToWorkQueue_whenNotRunning', 25 test('addContextToWorkQueue_whenNotRunning',
26 AnalysisServerTest.addContextToWorkQueue_whenNotRunning); 26 AnalysisServerTest.addContextToWorkQueue_whenNotRunning);
27 test('addContextToWorkQueue_whenRunning', 27 test('addContextToWorkQueue_whenRunning',
28 AnalysisServerTest.addContextToWorkQueue_whenRunning); 28 AnalysisServerTest.addContextToWorkQueue_whenRunning);
29 test('createContext', AnalysisServerTest.createContext); 29 test('createContext', AnalysisServerTest.createContext);
30 test('echo', AnalysisServerTest.echo); 30 test('echo', AnalysisServerTest.echo);
31 test('errorToJson_formattingApplied',
32 AnalysisServerTest.errorToJson_formattingApplied);
33 test('errorToJson_noCorrection',
34 AnalysisServerTest.errorToJson_noCorrection);
35 test('errorToJson_withCorrection',
36 AnalysisServerTest.errorToJson_withCorrection);
31 test('performTask_whenNotRunning', 37 test('performTask_whenNotRunning',
32 AnalysisServerTest.performTask_whenNotRunning); 38 AnalysisServerTest.performTask_whenNotRunning);
33 test('shutdown', AnalysisServerTest.shutdown); 39 test('shutdown', AnalysisServerTest.shutdown);
34 test('unknownRequest', AnalysisServerTest.unknownRequest); 40 test('unknownRequest', AnalysisServerTest.unknownRequest);
35 }); 41 });
36 } 42 }
37 43
38 class MockAnalysisContext_withPerformAnalysisTask extends MockAnalysisContext { 44 class MockAnalysisContext_withPerformAnalysisTask extends MockAnalysisContext {
39 List<AnalysisResult> results = []; 45 List<AnalysisResult> results = [];
40 46
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 expect(context.results, isEmpty); 88 expect(context.results, isEmpty);
83 expect(channel.notificationsReceived, hasLength(2)); 89 expect(channel.notificationsReceived, hasLength(2));
84 expect(channel.notificationsReceived[0].event, equals('server.connected') 90 expect(channel.notificationsReceived[0].event, equals('server.connected')
85 ); 91 );
86 expect(channel.notificationsReceived[1].event, equals('context.errors')); 92 expect(channel.notificationsReceived[1].event, equals('context.errors'));
87 expect(channel.notificationsReceived[1].params['source'], equals( 93 expect(channel.notificationsReceived[1].params['source'], equals(
88 '102file:///foo.dart')); // Issue 18739 94 '102file:///foo.dart')); // Issue 18739
89 List<AnalysisError> errors = 95 List<AnalysisError> errors =
90 channel.notificationsReceived[1].params['errors']; 96 channel.notificationsReceived[1].params['errors'];
91 expect(errors, hasLength(1)); 97 expect(errors, hasLength(1));
92 expect(errors[0], equals(analysisError)); 98 expect(errors[0], equals(AnalysisServer.errorToJson(analysisError)));
93 }); 99 });
94 } 100 }
95 101
96 static Future addContextToWorkQueue_twice() { 102 static Future addContextToWorkQueue_twice() {
97 // The context should only be asked to perform its analysis task once. 103 // The context should only be asked to perform its analysis task once.
98 MockAnalysisContext_withPerformAnalysisTask context = 104 MockAnalysisContext_withPerformAnalysisTask context =
99 new MockAnalysisContext_withPerformAnalysisTask(); 105 new MockAnalysisContext_withPerformAnalysisTask();
100 server.addContextToWorkQueue(context); 106 server.addContextToWorkQueue(context);
101 server.addContextToWorkQueue(context); 107 server.addContextToWorkQueue(context);
102 context.results.add(new AnalysisResult(null, 0, null, 0)); 108 context.results.add(new AnalysisResult(null, 0, null, 0));
(...skipping 15 matching lines...) Expand all
118 static Future echo() { 124 static Future echo() {
119 server.handlers = [new EchoHandler()]; 125 server.handlers = [new EchoHandler()];
120 var request = new Request('my22', 'echo'); 126 var request = new Request('my22', 'echo');
121 return channel.sendRequest(request) 127 return channel.sendRequest(request)
122 .then((Response response) { 128 .then((Response response) {
123 expect(response.id, equals('my22')); 129 expect(response.id, equals('my22'));
124 expect(response.error, isNull); 130 expect(response.error, isNull);
125 }); 131 });
126 } 132 }
127 133
134 static void errorToJson_formattingApplied() {
135 Source source = new FileBasedSource.con1(new JavaFile('/foo.dart'));
scheglov 2014/04/23 19:20:56 I think we need to learn how to use mocks in Dart.
Brian Wilkerson 2014/04/24 15:44:05 I disagree :-) I prefer to only use mocks for case
136 CompileTimeErrorCode errorCode = CompileTimeErrorCode.AMBIGUOUS_EXPORT;
137 AnalysisError analysisError =
138 new AnalysisError.con1(source, errorCode, ['foo', 'bar', 'baz']);
139 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
140
141 expect(json['message'],
142 equals("The element 'foo' is defined in the libraries 'bar' and 'baz'")) ;
143 }
144
145 static void errorToJson_noCorrection() {
146 Source source = new FileBasedSource.con1(new JavaFile('/foo.dart'));
147 CompileTimeErrorCode errorCode =
148 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER;
149 AnalysisError analysisError =
150 new AnalysisError.con2(source, 10, 5, errorCode, []);
151 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
152 expect(json, hasLength(5));
153
154 // TODO(paulberry): should be 'ffile:///foo.dart'. See dartbug.com/18739
155 expect(json['source'], equals('102file:///foo.dart'));
scheglov 2014/04/23 19:20:56 Yes, here is an example of an accidental complexit
Paul Berry 2014/04/23 20:36:26 Agreed. I also found out that this doesn't work o
156
157 expect(json['errorCode'], equals(errorCode.ordinal));
158 expect(json['offset'], equals(analysisError.offset));
159 expect(json['length'], equals(analysisError.length));
160 expect(json['message'], equals(errorCode.message));
161 }
162
163 static void errorToJson_withCorrection() {
164 Source source = new FileBasedSource.con1(new JavaFile('/foo.dart'));
165
166 // TODO(paulberry): in principle we should test an error or hint that uses
167 // %s formatting in its correction string. But no such errors or hints
168 // currently exist!
Brian Wilkerson 2014/04/24 15:44:05 I'm not sure I know what you're referring to. Are
Paul Berry 2014/04/24 16:19:26 To clarify, I'm talking about the correction text
Brian Wilkerson 2014/04/24 16:47:45 Yes, I expect that we will want to use %s in corre
169 HintCode errorCode = HintCode.MISSING_RETURN;
170
171 AnalysisError analysisError =
172 new AnalysisError.con2(source, 10, 5, errorCode, ['int']);
173 Map<String, Object> json = AnalysisServer.errorToJson(analysisError);
174 expect(json['correction'], equals(errorCode.correction));
175 }
176
128 static Future performTask_whenNotRunning() { 177 static Future performTask_whenNotRunning() {
129 // If the server is shut down while there is analysis still pending, 178 // If the server is shut down while there is analysis still pending,
130 // performTask() should notice that the server is no longer running and 179 // performTask() should notice that the server is no longer running and
131 // do no analysis. 180 // do no analysis.
132 MockAnalysisContext context = new MockAnalysisContext(); 181 MockAnalysisContext context = new MockAnalysisContext();
133 server.addContextToWorkQueue(context); 182 server.addContextToWorkQueue(context);
134 server.running = false; 183 server.running = false;
135 // Pump the event queue to make sure the server doesn't try to do any 184 // Pump the event queue to make sure the server doesn't try to do any
136 // analysis. 185 // analysis.
137 return pumpEventQueue(); 186 return pumpEventQueue();
(...skipping 26 matching lines...) Expand all
164 @override 213 @override
165 Response handleRequest(Request request) { 214 Response handleRequest(Request request) {
166 if (request.method == 'echo') { 215 if (request.method == 'echo') {
167 var response = new Response(request.id); 216 var response = new Response(request.id);
168 response.setResult('echo', true); 217 response.setResult('echo', true);
169 return response; 218 return response;
170 } 219 }
171 return null; 220 return null;
172 } 221 }
173 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698