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

Side by Side Diff: pkg/analysis_server/test/integration/analysis_domain_int_test.dart

Issue 437383003: Simplify handling of pathnames in integration tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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.integration.analysis.domain; 5 library test.integration.analysis.domain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_testing/reflective_tests.dart'; 10 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:path/path.dart'; 11 import 'package:path/path.dart';
12 import 'package:unittest/unittest.dart'; 12 import 'package:unittest/unittest.dart';
13 13
14 import 'integration_tests.dart'; 14 import 'integration_tests.dart';
15 import 'protocol_matchers.dart'; 15 import 'protocol_matchers.dart';
16 16
17 @ReflectiveTestCase() 17 @ReflectiveTestCase()
18 class AnalysisDomainIntegrationTest extends 18 class AnalysisDomainIntegrationTest extends
19 AbstractAnalysisServerIntegrationTest { 19 AbstractAnalysisServerIntegrationTest {
20 test_getHover() { 20 test_getHover() {
21 String filename = 'test.dart'; 21 String pathname = sourcePath('test.dart');
22 String pathname = normalizePath(filename);
23 String text = 22 String text =
24 r''' 23 r'''
25 library lib.test; 24 library lib.test;
26 25
27 List topLevelVar; 26 List topLevelVar;
28 27
29 /** 28 /**
30 * Documentation for func 29 * Documentation for func
31 */ 30 */
32 void func(int param) { 31 void func(int param) {
33 num localVar = topLevelVar.length; 32 num localVar = topLevelVar.length;
34 topLevelVar.length = param; 33 topLevelVar.length = param;
35 topLevelVar.add(localVar); 34 topLevelVar.add(localVar);
36 } 35 }
37 36
38 main() { 37 main() {
39 func(35); 38 func(35);
40 } 39 }
41 '''; 40 ''';
42 writeFile(filename, text); 41 writeFile(pathname, text);
43 setAnalysisRoots(['']); 42 standardAnalysisRoot();
44 43
45 testHover(String target, int length, List<String> descriptionRegexps, String 44 testHover(String target, int length, List<String> descriptionRegexps, String
46 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg exp: 45 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg exp:
47 null, bool isLiteral: false, List<String> parameterRegexps: 46 null, bool isLiteral: false, List<String> parameterRegexps:
48 null, propagatedType: null}) { 47 null, propagatedType: null}) {
49 int offset = text.indexOf(target); 48 int offset = text.indexOf(target);
50 return server.send(ANALYSIS_GET_HOVER, { 49 return server.send(ANALYSIS_GET_HOVER, {
51 'file': pathname, 50 'file': pathname,
52 'offset': offset 51 'offset': offset
53 }).then((result) { 52 }).then((result) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ['num'], parameterRegexps: ['.*'], propagatedType: 'int')); 130 ['num'], parameterRegexps: ['.*'], propagatedType: 'int'));
132 tests.add(testHover('func(35', 4, ['func', 'int', 'param'], 'function', 131 tests.add(testHover('func(35', 4, ['func', 'int', 'param'], 'function',
133 null, docRegexp: 'Documentation for func')); 132 null, docRegexp: 'Documentation for func'));
134 tests.add(testHover('35', 2, null, null, ['int'], isLiteral: true, 133 tests.add(testHover('35', 2, null, null, ['int'], isLiteral: true,
135 parameterRegexps: ['int', 'param'])); 134 parameterRegexps: ['int', 'param']));
136 return Future.wait(tests); 135 return Future.wait(tests);
137 }); 136 });
138 } 137 }
139 138
140 test_getHover_noInfo() { 139 test_getHover_noInfo() {
141 String filename = 'test.dart'; 140 String pathname = sourcePath('test.dart');
142 String pathname = normalizePath(filename);
143 String text = r''' 141 String text = r'''
144 main() { 142 main() {
145 // no code 143 // no code
146 } 144 }
147 '''; 145 ''';
148 writeFile(filename, text); 146 writeFile(pathname, text);
149 setAnalysisRoots(['']); 147 standardAnalysisRoot();
150 148
151 // Note: analysis.getHover doesn't wait for analysis to complete--it simply 149 // Note: analysis.getHover doesn't wait for analysis to complete--it simply
152 // returns the latest results that are available at the time that the 150 // returns the latest results that are available at the time that the
153 // request is made. So wait for analysis to finish before testing anything. 151 // request is made. So wait for analysis to finish before testing anything.
154 return analysisFinished.then((_) { 152 return analysisFinished.then((_) {
155 return server.send(ANALYSIS_GET_HOVER, { 153 return server.send(ANALYSIS_GET_HOVER, {
156 'file': pathname, 154 'file': pathname,
157 'offset': text.indexOf('no code') 155 'offset': text.indexOf('no code')
158 }).then((result) { 156 }).then((result) {
159 expect(result, isAnalysisGetHoverResult); 157 expect(result, isAnalysisGetHoverResult);
160 expect(result['hovers'], hasLength(0)); 158 expect(result['hovers'], hasLength(0));
161 }); 159 });
162 }); 160 });
163 } 161 }
164 162
165 test_getErrors_before_analysis() { 163 test_getErrors_before_analysis() {
166 return getErrorsTest(false); 164 return getErrorsTest(false);
167 } 165 }
168 166
169 test_getErrors_after_analysis() { 167 test_getErrors_after_analysis() {
170 return getErrorsTest(true); 168 return getErrorsTest(true);
171 } 169 }
172 170
173 Future getErrorsTest(bool afterAnalysis) { 171 Future getErrorsTest(bool afterAnalysis) {
174 String filename = 'test.dart'; 172 String pathname = sourcePath('test.dart');
175 String pathname = normalizePath(filename);
176 String text = r''' 173 String text = r'''
177 main() { 174 main() {
178 var x // parse error: missing ';' 175 var x // parse error: missing ';'
179 }'''; 176 }''';
180 writeFile(filename, text); 177 writeFile(pathname, text);
181 setAnalysisRoots(['']); 178 standardAnalysisRoot();
182 Future finishTest() { 179 Future finishTest() {
183 return server.send(ANALYSIS_GET_ERRORS, { 180 return server.send(ANALYSIS_GET_ERRORS, {
184 'file': pathname 181 'file': pathname
185 }).then((result) { 182 }).then((result) {
186 expect(result, isAnalysisGetErrorsResult); 183 expect(result, isAnalysisGetErrorsResult);
187 expect(result['errors'], equals(currentAnalysisErrors[pathname])); 184 expect(result['errors'], equals(currentAnalysisErrors[pathname]));
188 }); 185 });
189 } 186 }
190 if (afterAnalysis) { 187 if (afterAnalysis) {
191 return analysisFinished.then((_) => finishTest()); 188 return analysisFinished.then((_) => finishTest());
192 } else { 189 } else {
193 return finishTest(); 190 return finishTest();
194 } 191 }
195 } 192 }
196 193
197 test_updateContent_content_only() { 194 test_updateContent_content_only() {
198 return updateContentTest(false); 195 return updateContentTest(false);
199 } 196 }
200 197
201 test_updateContent_including_offset_and_lengths() { 198 test_updateContent_including_offset_and_lengths() {
202 return updateContentTest(true); 199 return updateContentTest(true);
203 } 200 }
204 201
205 Future updateContentTest(bool includeOffsetAndLengths) { 202 Future updateContentTest(bool includeOffsetAndLengths) {
206 String filename = 'test.dart'; 203 String pathname = sourcePath('test.dart');
207 String pathname = normalizePath(filename);
208 String goodText = r''' 204 String goodText = r'''
209 main() { 205 main() {
210 print("Hello, world!"); 206 print("Hello, world!");
211 }'''; 207 }''';
212 String badText = goodText.replaceAll(';', ''); 208 String badText = goodText.replaceAll(';', '');
213 writeFile(filename, badText); 209 writeFile(pathname, badText);
214 setAnalysisRoots(['']); 210 standardAnalysisRoot();
215 return analysisFinished.then((_) { 211 return analysisFinished.then((_) {
216 // The contents on disk (badText) are missing a semicolon. 212 // The contents on disk (badText) are missing a semicolon.
217 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); 213 expect(currentAnalysisErrors[pathname], isNot(isEmpty));
218 var contentChange = { 214 var contentChange = {
219 'content': goodText 215 'content': goodText
220 }; 216 };
221 if (includeOffsetAndLengths) { 217 if (includeOffsetAndLengths) {
222 contentChange['offset'] = goodText.indexOf(';'); 218 contentChange['offset'] = goodText.indexOf(';');
223 contentChange['oldLength'] = 0; 219 contentChange['oldLength'] = 0;
224 contentChange['newLength'] = 1; 220 contentChange['newLength'] = 1;
(...skipping 24 matching lines...) Expand all
249 // Now there should be errors again, because the contents on disk are no 245 // Now there should be errors again, because the contents on disk are no
250 // longer overridden. 246 // longer overridden.
251 expect(currentAnalysisErrors[pathname], isNot(isEmpty)); 247 expect(currentAnalysisErrors[pathname], isNot(isEmpty));
252 }); 248 });
253 } 249 }
254 } 250 }
255 251
256 main() { 252 main() {
257 runReflectiveTests(AnalysisDomainIntegrationTest); 253 runReflectiveTests(AnalysisDomainIntegrationTest);
258 } 254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698