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

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

Issue 1511833004: Validate that root paths are absolute and normalized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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.domain.analysis; 5 library test.domain.analysis;
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/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 var response = testSetAnalysisRoots(['/project'], ['/project/bbb']); 112 var response = testSetAnalysisRoots(['/project'], ['/project/bbb']);
113 var serverRef = server; 113 var serverRef = server;
114 expect(response, isResponseSuccess('0')); 114 expect(response, isResponseSuccess('0'));
115 // unit "a" is resolved eventually 115 // unit "a" is resolved eventually
116 // unit "b" is not resolved 116 // unit "b" is not resolved
117 return server.onAnalysisComplete.then((_) { 117 return server.onAnalysisComplete.then((_) {
118 expect(serverRef.getResolvedCompilationUnits(fileA), hasLength(1)); 118 expect(serverRef.getResolvedCompilationUnits(fileA), hasLength(1));
119 expect(serverRef.getResolvedCompilationUnits(fileB), isEmpty); 119 expect(serverRef.getResolvedCompilationUnits(fileB), isEmpty);
120 }); 120 });
121 }); 121 });
122
123 test('not absolute', () async {
124 var response = testSetAnalysisRoots([], ['foo/bar']);
125 expect(
126 response,
127 isResponseFailure(
128 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT));
129 });
130
131 test('not normalized', () async {
132 var response = testSetAnalysisRoots([], ['/foo/../bar']);
133 expect(
134 response,
135 isResponseFailure(
136 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT));
137 });
122 }); 138 });
123 139
124 group('included', () { 140 group('included', () {
125 test('new folder', () { 141 test('new folder', () {
126 String file = '/project/bin/test.dart'; 142 String file = '/project/bin/test.dart';
127 resourceProvider.newFile('/project/pubspec.yaml', 'name: project'); 143 resourceProvider.newFile('/project/pubspec.yaml', 'name: project');
128 resourceProvider.newFile(file, 'main() {}'); 144 resourceProvider.newFile(file, 'main() {}');
129 var response = testSetAnalysisRoots(['/project'], []); 145 var response = testSetAnalysisRoots(['/project'], []);
130 var serverRef = server; 146 var serverRef = server;
131 expect(response, isResponseSuccess('0')); 147 expect(response, isResponseSuccess('0'));
132 // verify that unit is resolved eventually 148 // verify that unit is resolved eventually
133 return server.onAnalysisComplete.then((_) { 149 return server.onAnalysisComplete.then((_) {
134 var units = serverRef.getResolvedCompilationUnits(file); 150 var units = serverRef.getResolvedCompilationUnits(file);
135 expect(units, hasLength(1)); 151 expect(units, hasLength(1));
136 }); 152 });
137 }); 153 });
138 154
139 test('nonexistent folder', () async { 155 test('nonexistent folder', () async {
140 String fileB = '/project_b/b.dart'; 156 String fileB = '/project_b/b.dart';
141 resourceProvider.newFile(fileB, '// b'); 157 resourceProvider.newFile(fileB, '// b');
142 var response = testSetAnalysisRoots(['/project_a', '/project_b'], []); 158 var response = testSetAnalysisRoots(['/project_a', '/project_b'], []);
143 var serverRef = server; 159 var serverRef = server;
144 expect(response, isResponseSuccess('0')); 160 expect(response, isResponseSuccess('0'));
145 // Non-existence of /project_a should not prevent files in /project_b 161 // Non-existence of /project_a should not prevent files in /project_b
146 // from being analyzed. 162 // from being analyzed.
147 await server.onAnalysisComplete; 163 await server.onAnalysisComplete;
148 expect(serverRef.getResolvedCompilationUnits(fileB), hasLength(1)); 164 expect(serverRef.getResolvedCompilationUnits(fileB), hasLength(1));
149 }); 165 });
166
167 test('not absolute', () async {
168 var response = testSetAnalysisRoots(['foo/bar'], []);
169 expect(
170 response,
171 isResponseFailure(
172 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT));
173 });
174
175 test('not normalized', () async {
176 var response = testSetAnalysisRoots(['/foo/../bar'], []);
177 expect(
178 response,
179 isResponseFailure(
180 '0', RequestErrorCode.INVALID_FILE_PATH_FORMAT));
181 });
150 }); 182 });
151 }); 183 });
152 184
153 group('setPriorityFiles', () { 185 group('setPriorityFiles', () {
154 test('invalid', () { 186 test('invalid', () {
155 // TODO(paulberry): under the "eventual consistency" model this request 187 // TODO(paulberry): under the "eventual consistency" model this request
156 // should not be invalid. 188 // should not be invalid.
157 var request = new AnalysisSetPriorityFilesParams(['/project/lib.dart']) 189 var request = new AnalysisSetPriorityFilesParams(['/project/lib.dart'])
158 .toRequest('0'); 190 .toRequest('0');
159 var response = handler.handleRequest(request); 191 var response = handler.handleRequest(request);
160 expect(response, isResponseFailure('0')); 192 expect(response, isResponseFailure('0'));
161 }); 193 });
162 194
163 test('valid', () { 195 test('valid', () {
164 resourceProvider.newFolder('/p1'); 196 resourceProvider.newFolder('/p1');
165 resourceProvider.newFile('/p1/a.dart', 'library a;'); 197 resourceProvider.newFile('/p1/a.dart', 'library a;');
166 resourceProvider.newFolder('/p2'); 198 resourceProvider.newFolder('/p2');
167 resourceProvider.newFile('/p2/b.dart', 'library b;'); 199 resourceProvider.newFile('/p2/b.dart', 'library b;');
168 resourceProvider.newFile('/p2/c.dart', 'library c;'); 200 resourceProvider.newFile('/p2/c.dart', 'library c;');
169 201
170 var setRootsRequest = new AnalysisSetAnalysisRootsParams( 202 var setRootsRequest =
171 ['/p1', '/p2'], []).toRequest('0'); 203 new AnalysisSetAnalysisRootsParams(['/p1', '/p2'], [])
204 .toRequest('0');
172 var setRootsResponse = handler.handleRequest(setRootsRequest); 205 var setRootsResponse = handler.handleRequest(setRootsRequest);
173 expect(setRootsResponse, isResponseSuccess('0')); 206 expect(setRootsResponse, isResponseSuccess('0'));
174 207
175 void setPriorityFiles(List<String> fileList) { 208 void setPriorityFiles(List<String> fileList) {
176 var request = 209 var request =
177 new AnalysisSetPriorityFilesParams(fileList).toRequest('0'); 210 new AnalysisSetPriorityFilesParams(fileList).toRequest('0');
178 var response = handler.handleRequest(request); 211 var response = handler.handleRequest(request);
179 expect(response, isResponseSuccess('0')); 212 expect(response, isResponseSuccess('0'));
180 // TODO(brianwilkerson) Enable the line below after getPriorityFiles 213 // TODO(brianwilkerson) Enable the line below after getPriorityFiles
181 // has been implemented. 214 // has been implemented.
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 test_beforeAnalysis() async { 808 test_beforeAnalysis() async {
776 addTestFile('int V = 42;'); 809 addTestFile('int V = 42;');
777 createProject(); 810 createProject();
778 // subscribe 811 // subscribe
779 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); 812 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile);
780 // wait for analysis 813 // wait for analysis
781 await waitForTasksFinished(); 814 await waitForTasksFinished();
782 expect(filesHighlights[testFile], isNotEmpty); 815 expect(filesHighlights[testFile], isNotEmpty);
783 } 816 }
784 } 817 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698