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

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

Issue 426923002: Start running the analysis server integration tests by changing the name to end with _test.dart (Closed) Base URL: http://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
(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.integration.analysis.domain;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:path/path.dart';
12 import 'package:unittest/unittest.dart';
13
14 import 'integration_tests.dart';
15
16 @ReflectiveTestCase()
17 class AnalysisDomainIntegrationTest extends
18 AbstractAnalysisServerIntegrationTest {
19 test_getHover() {
20 String filename = 'test.dart';
21 String pathname = normalizePath(filename);
22 String text =
23 r'''
24 library lib.test;
25
26 List topLevelVar;
27
28 /**
29 * Documentation for func
30 */
31 void func(int param) {
32 num localVar = topLevelVar.length;
33 topLevelVar.length = param;
34 topLevelVar.add(localVar);
35 }
36
37 main() {
38 func(35);
39 }
40 ''';
41 writeFile(filename, text);
42 setAnalysisRoots(['']);
43
44 testHover(String target, int length, List<String> descriptionRegexps, String
45 kind, List<String> staticTypeRegexps, {bool isCore: false, String docReg exp:
46 null, bool isLiteral: false, List<String> parameterRegexps:
47 null, propagatedType: null}) {
48 int offset = text.indexOf(target);
49 return server.send(ANALYSIS_GET_HOVER, {
50 'file': pathname,
51 'offset': offset
52 }).then((result) {
53 expect(result, isAnalysisGetHoverResult);
54 expect(result['hovers'], hasLength(1));
55 var info = result['hovers'][0];
56 expect(info['offset'], equals(offset));
57 expect(info['length'], equals(length));
58 if (isCore) {
59 expect(basename(info['containingLibraryPath']), equals('core.dart'));
60 expect(info['containingLibraryName'], equals('dart.core'));
61 } else if (isLiteral) {
62 expect(info['containingLibraryPath'], isNull);
63 expect(info['containingLibraryName'], isNull);
64 } else {
65 expect(info['containingLibraryPath'], equals(pathname));
66 expect(info['containingLibraryName'], equals('lib.test'));
67 }
68 if (docRegexp == null) {
69 expect(info['dartdoc'], isNull);
70 } else {
71 expect(info['dartdoc'], matches(docRegexp));
72 }
73 if (descriptionRegexps == null) {
74 expect(info['elementDescription'], isNull);
75 } else {
76 expect(info['elementDescription'], isString);
77 for (String descriptionRegexp in descriptionRegexps) {
78 expect(info['elementDescription'], matches(descriptionRegexp));
79 }
80 }
81 expect(info['elementKind'], equals(kind));
82 if (parameterRegexps == null) {
83 expect(info['parameter'], isNull);
84 } else {
85 expect(info['parameter'], isString);
86 for (String parameterRegexp in parameterRegexps) {
87 expect(info['parameter'], matches(parameterRegexp));
88 }
89 }
90 expect(info['propagatedType'], equals(propagatedType));
91 if (staticTypeRegexps == null) {
92 expect(info['staticType'], isNull);
93 } else {
94 expect(info['staticType'], isString);
95 for (String staticTypeRegexp in staticTypeRegexps) {
96 expect(info['staticType'], matches(staticTypeRegexp));
97 }
98 }
99 });
100 }
101
102 // Note: analysis.getHover doesn't wait for analysis to complete--it simply
103 // returns the latest results that are available at the time that the
104 // request is made. So wait for analysis to finish before testing anything.
105 return analysisFinished.then((_) {
106 List<Future> tests = [];
107 tests.add(testHover('topLevelVar;', 11, ['List', 'topLevelVar'],
108 'top level variable', ['List']));
109 tests.add(testHover('func(', 4, ['func', 'int', 'param'], 'function',
110 ['int', 'void'], docRegexp: 'Documentation for func'));
111 tests.add(testHover('int param', 3, ['int'], 'class', ['int'], isCore:
112 true, docRegexp: '.*'));
113 tests.add(testHover('param)', 5, ['int', 'param'], 'parameter', ['int'],
114 docRegexp: 'Documentation for func'));
115 tests.add(testHover('num localVar', 3, ['num'], 'class', ['num'], isCore:
116 true, docRegexp: '.*'));
117 tests.add(testHover('localVar =', 8, ['num', 'localVar'],
118 'local variable', ['num'], propagatedType: 'int'));
119 tests.add(testHover('topLevelVar.length;', 11, ['List', 'topLevelVar'],
120 'top level variable', ['List']));
121 tests.add(testHover('length;', 6, ['get', 'length', 'int'], 'getter',
122 ['int'], isCore: true, docRegexp: '.*'));
123 tests.add(testHover('length =', 6, ['set', 'length', 'int'], 'setter',
124 ['int'], isCore: true, docRegexp: '.*'));
125 tests.add(testHover('param;', 5, ['int', 'param'], 'parameter', ['int'],
126 docRegexp: 'Documentation for func'));
127 tests.add(testHover('add(', 3, ['List', 'add'], 'method', null, isCore:
128 true, docRegexp: '.*'));
129 tests.add(testHover('localVar)', 8, ['num', 'localVar'], 'local variable',
130 ['num'], parameterRegexps: ['.*'], propagatedType: 'int'));
131 tests.add(testHover('func(35', 4, ['func', 'int', 'param'], 'function',
132 null, docRegexp: 'Documentation for func'));
133 tests.add(testHover('35', 2, null, null, ['int'], isLiteral: true,
134 parameterRegexps: ['int', 'param']));
135 return Future.wait(tests);
136 });
137 }
138
139 test_getHover_noInfo() {
140 String filename = 'test.dart';
141 String pathname = normalizePath(filename);
142 String text = r'''
143 main() {
144 // no code
145 }
146 ''';
147 writeFile(filename, text);
148 setAnalysisRoots(['']);
149
150 // Note: analysis.getHover doesn't wait for analysis to complete--it simply
151 // returns the latest results that are available at the time that the
152 // request is made. So wait for analysis to finish before testing anything.
153 return analysisFinished.then((_) {
154 return server.send(ANALYSIS_GET_HOVER, {
155 'file': pathname,
156 'offset': text.indexOf('no code')
157 }).then((result) {
158 expect(result, isAnalysisGetHoverResult);
159 expect(result['hovers'], hasLength(0));
160 });
161 });
162 }
163
164 test_getErrors_before_analysis() {
165 return getErrorsTest(false);
166 }
167
168 test_getErrors_after_analysis() {
169 debugStdio();
170 return getErrorsTest(true);
171 }
172
173 Future getErrorsTest(bool afterAnalysis) {
174 String filename = 'test.dart';
175 String pathname = normalizePath(filename);
176 String text =
177 r'''
178 main() {
179 var x // parse error: missing ';'
180 }''';
181 writeFile(filename, text);
182 setAnalysisRoots(['']);
183 Future finishTest() {
184 return server.send(ANALYSIS_GET_ERRORS, {
185 'file': pathname
186 }).then((result) {
187 expect(result, isAnalysisGetErrorsResult);
188 expect(result['errors'], equals(currentAnalysisErrors[pathname]));
189 });
190 }
191 if (afterAnalysis) {
192 return analysisFinished.then((_) => finishTest());
193 } else {
194 return finishTest();
195 }
196 }
197 }
198
199 main() {
200 runReflectiveTests(AnalysisDomainIntegrationTest);
201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698