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

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

Issue 1266923004: More fixes for failures on the Windows bot (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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
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/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/domain_analysis.dart'; 11 import 'package:analysis_server/src/domain_analysis.dart';
12 import 'package:analysis_server/src/plugin/server_plugin.dart'; 12 import 'package:analysis_server/src/plugin/server_plugin.dart';
13 import 'package:analysis_server/src/protocol.dart'; 13 import 'package:analysis_server/src/protocol.dart';
14 import 'package:analyzer/file_system/memory_file_system.dart'; 14 import 'package:analyzer/file_system/memory_file_system.dart';
15 import 'package:analyzer/instrumentation/instrumentation.dart'; 15 import 'package:analyzer/instrumentation/instrumentation.dart';
16 import 'package:path/path.dart'; 16 import 'package:path/path.dart';
17 import 'package:plugin/manager.dart'; 17 import 'package:plugin/manager.dart';
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; 18 import 'package:test_reflective_loader/test_reflective_loader.dart';
19 import 'package:unittest/unittest.dart'; 19 import 'package:unittest/unittest.dart';
20 20
21 import 'analysis_abstract.dart'; 21 import 'analysis_abstract.dart';
22 import 'mock_sdk.dart'; 22 import 'mock_sdk.dart';
23 import 'mocks.dart'; 23 import 'mocks.dart';
24 import 'utils.dart';
24 25
25 main() { 26 main() {
26 groupSep = ' | '; 27 initializeTestEnvironment();
27 28
28 defineReflectiveTests(AnalysisDomainTest); 29 defineReflectiveTests(AnalysisDomainTest);
29 defineReflectiveTests(SetSubscriptionsTest); 30 defineReflectiveTests(SetSubscriptionsTest);
30 31
31 MockServerChannel serverChannel; 32 MockServerChannel serverChannel;
32 MemoryResourceProvider resourceProvider; 33 MemoryResourceProvider resourceProvider;
33 AnalysisServer server; 34 AnalysisServer server;
34 AnalysisDomainHandler handler; 35 AnalysisDomainHandler handler;
35 36
36 setUp(() { 37 setUp(() {
37 serverChannel = new MockServerChannel(); 38 serverChannel = new MockServerChannel();
38 resourceProvider = new MemoryResourceProvider(); 39 resourceProvider = new MemoryResourceProvider();
39 ExtensionManager manager = new ExtensionManager(); 40 ExtensionManager manager = new ExtensionManager();
40 ServerPlugin serverPlugin = new ServerPlugin(); 41 ServerPlugin serverPlugin = new ServerPlugin();
41 manager.processPlugins([serverPlugin]); 42 manager.processPlugins([serverPlugin]);
42 server = new AnalysisServer(serverChannel, resourceProvider, 43 server = new AnalysisServer(
43 new MockPackageMapProvider(), null, serverPlugin, 44 serverChannel,
44 new AnalysisServerOptions(), new MockSdk(), 45 resourceProvider,
46 new MockPackageMapProvider(),
47 null,
48 serverPlugin,
49 new AnalysisServerOptions(),
50 new MockSdk(),
45 InstrumentationService.NULL_SERVICE); 51 InstrumentationService.NULL_SERVICE);
46 handler = new AnalysisDomainHandler(server); 52 handler = new AnalysisDomainHandler(server);
47 }); 53 });
48 54
49 group('updateContent', testUpdateContent); 55 group('updateContent', testUpdateContent);
50 56
51 group('AnalysisDomainHandler', () { 57 group('AnalysisDomainHandler', () {
52 group('setAnalysisRoots', () { 58 group('setAnalysisRoots', () {
53 Response testSetAnalysisRoots( 59 Response testSetAnalysisRoots(
54 List<String> included, List<String> excluded) { 60 List<String> included, List<String> excluded) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 131 }
126 132
127 setPriorityFiles(['/p1/a.dart', '/p2/b.dart']); 133 setPriorityFiles(['/p1/a.dart', '/p2/b.dart']);
128 setPriorityFiles(['/p2/b.dart', '/p2/c.dart']); 134 setPriorityFiles(['/p2/b.dart', '/p2/c.dart']);
129 setPriorityFiles([]); 135 setPriorityFiles([]);
130 }); 136 });
131 }); 137 });
132 138
133 group('updateOptions', () { 139 group('updateOptions', () {
134 test('invalid', () { 140 test('invalid', () {
135 var request = new Request( 141 var request = new Request('0', ANALYSIS_UPDATE_OPTIONS, {
136 '0', ANALYSIS_UPDATE_OPTIONS, {OPTIONS: {'not-an-option': true}}); 142 OPTIONS: {'not-an-option': true}
143 });
137 var response = handler.handleRequest(request); 144 var response = handler.handleRequest(request);
138 // Invalid options should be silently ignored. 145 // Invalid options should be silently ignored.
139 expect(response, isResponseSuccess('0')); 146 expect(response, isResponseSuccess('0'));
140 }); 147 });
141 148
142 test('null', () { 149 test('null', () {
143 // null is allowed as a synonym for {}. 150 // null is allowed as a synonym for {}.
144 var request = 151 var request =
145 new Request('0', ANALYSIS_UPDATE_OPTIONS, {OPTIONS: null}); 152 new Request('0', ANALYSIS_UPDATE_OPTIONS, {OPTIONS: null});
146 var response = handler.handleRequest(request); 153 var response = handler.handleRequest(request);
147 expect(response, isResponseSuccess('0')); 154 expect(response, isResponseSuccess('0'));
148 }); 155 });
149 }); 156 });
150 }); 157 });
151 } 158 }
152 159
153 testUpdateContent() { 160 testUpdateContent() {
154 test('bad type', () { 161 test('bad type', () {
155 AnalysisTestHelper helper = new AnalysisTestHelper(); 162 AnalysisTestHelper helper = new AnalysisTestHelper();
156 helper.createSingleFileProject('// empty'); 163 helper.createSingleFileProject('// empty');
157 return helper.onAnalysisComplete.then((_) { 164 return helper.onAnalysisComplete.then((_) {
158 Request request = new Request('0', ANALYSIS_UPDATE_CONTENT, { 165 Request request = new Request('0', ANALYSIS_UPDATE_CONTENT, {
159 'files': {helper.testFile: {TYPE: 'foo',}} 166 'files': {
167 helper.testFile: {TYPE: 'foo',}
168 }
160 }); 169 });
161 Response response = helper.handler.handleRequest(request); 170 Response response = helper.handler.handleRequest(request);
162 expect(response, isResponseFailure('0')); 171 expect(response, isResponseFailure('0'));
163 }); 172 });
164 }); 173 });
165 174
166 test('full content', () { 175 test('full content', () {
167 AnalysisTestHelper helper = new AnalysisTestHelper(); 176 AnalysisTestHelper helper = new AnalysisTestHelper();
168 helper.createSingleFileProject('// empty'); 177 helper.createSingleFileProject('// empty');
169 return helper.onAnalysisComplete.then((_) { 178 return helper.onAnalysisComplete.then((_) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if (notification.event == ANALYSIS_ERRORS) { 293 if (notification.event == ANALYSIS_ERRORS) {
285 var decoded = new AnalysisErrorsParams.fromNotification(notification); 294 var decoded = new AnalysisErrorsParams.fromNotification(notification);
286 filesErrors[decoded.file] = decoded.errors; 295 filesErrors[decoded.file] = decoded.errors;
287 } 296 }
288 } 297 }
289 298
290 test_packageMapDependencies() async { 299 test_packageMapDependencies() async {
291 // Prepare a source file that has errors because it refers to an unknown 300 // Prepare a source file that has errors because it refers to an unknown
292 // package. 301 // package.
293 String pkgFile = '/packages/pkgA/libA.dart'; 302 String pkgFile = '/packages/pkgA/libA.dart';
294 resourceProvider.newFile(pkgFile, ''' 303 resourceProvider.newFile(
304 pkgFile,
305 '''
295 library lib_a; 306 library lib_a;
296 class A {} 307 class A {}
297 '''); 308 ''');
298 addTestFile(''' 309 addTestFile('''
299 import 'package:pkgA/libA.dart'; 310 import 'package:pkgA/libA.dart';
300 f(A a) { 311 f(A a) {
301 } 312 }
302 '''); 313 ''');
303 String pkgDependency = posix.join(projectPath, 'package_dep'); 314 String pkgDependency = posix.join(projectPath, 'package_dep');
304 resourceProvider.newFile(pkgDependency, 'contents'); 315 resourceProvider.newFile(pkgDependency, 'contents');
(...skipping 10 matching lines...) Expand all
315 // Give the server time to notice the file has changed, then let 326 // Give the server time to notice the file has changed, then let
316 // analysis complete. There should now be no error. 327 // analysis complete. There should now be no error.
317 await pumpEventQueue(); 328 await pumpEventQueue();
318 await waitForTasksFinished(); 329 await waitForTasksFinished();
319 expect(filesErrors[testFile], isEmpty); 330 expect(filesErrors[testFile], isEmpty);
320 } 331 }
321 332
322 test_setRoots_packages() { 333 test_setRoots_packages() {
323 // prepare package 334 // prepare package
324 String pkgFile = '/packages/pkgA/libA.dart'; 335 String pkgFile = '/packages/pkgA/libA.dart';
325 resourceProvider.newFile(pkgFile, ''' 336 resourceProvider.newFile(
337 pkgFile,
338 '''
326 library lib_a; 339 library lib_a;
327 class A {} 340 class A {}
328 '''); 341 ''');
329 packageMapProvider.packageMap['pkgA'] = 342 packageMapProvider.packageMap['pkgA'] = [
330 [resourceProvider.getResource('/packages/pkgA')]; 343 resourceProvider.getResource('/packages/pkgA')
344 ];
331 addTestFile(''' 345 addTestFile('''
332 import 'package:pkgA/libA.dart'; 346 import 'package:pkgA/libA.dart';
333 main(A a) { 347 main(A a) {
334 } 348 }
335 '''); 349 ''');
336 // create project and wait for analysis 350 // create project and wait for analysis
337 createProject(); 351 createProject();
338 return waitForTasksFinished().then((_) { 352 return waitForTasksFinished().then((_) {
339 // if 'package:pkgA/libA.dart' was resolved, then there are no errors 353 // if 'package:pkgA/libA.dart' was resolved, then there are no errors
340 expect(filesErrors[testFile], isEmpty); 354 expect(filesErrors[testFile], isEmpty);
(...skipping 20 matching lines...) Expand all
361 375
362 String testFile = '/project/bin/test.dart'; 376 String testFile = '/project/bin/test.dart';
363 String testCode; 377 String testCode;
364 378
365 AnalysisTestHelper() { 379 AnalysisTestHelper() {
366 serverChannel = new MockServerChannel(); 380 serverChannel = new MockServerChannel();
367 resourceProvider = new MemoryResourceProvider(); 381 resourceProvider = new MemoryResourceProvider();
368 ExtensionManager manager = new ExtensionManager(); 382 ExtensionManager manager = new ExtensionManager();
369 ServerPlugin serverPlugin = new ServerPlugin(); 383 ServerPlugin serverPlugin = new ServerPlugin();
370 manager.processPlugins([serverPlugin]); 384 manager.processPlugins([serverPlugin]);
371 server = new AnalysisServer(serverChannel, resourceProvider, 385 server = new AnalysisServer(
372 new MockPackageMapProvider(), null, serverPlugin, 386 serverChannel,
373 new AnalysisServerOptions(), new MockSdk(), 387 resourceProvider,
388 new MockPackageMapProvider(),
389 null,
390 serverPlugin,
391 new AnalysisServerOptions(),
392 new MockSdk(),
374 InstrumentationService.NULL_SERVICE); 393 InstrumentationService.NULL_SERVICE);
375 handler = new AnalysisDomainHandler(server); 394 handler = new AnalysisDomainHandler(server);
376 // listen for notifications 395 // listen for notifications
377 Stream<Notification> notificationStream = 396 Stream<Notification> notificationStream =
378 serverChannel.notificationController.stream; 397 serverChannel.notificationController.stream;
379 notificationStream.listen((Notification notification) { 398 notificationStream.listen((Notification notification) {
380 if (notification.event == ANALYSIS_ERRORS) { 399 if (notification.event == ANALYSIS_ERRORS) {
381 var decoded = new AnalysisErrorsParams.fromNotification(notification); 400 var decoded = new AnalysisErrorsParams.fromNotification(notification);
382 filesErrors[decoded.file] = decoded.errors; 401 filesErrors[decoded.file] = decoded.errors;
383 } 402 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 expect(filesHighlights[testFile], isNull); 605 expect(filesHighlights[testFile], isNull);
587 // subscribe 606 // subscribe
588 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); 607 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
589 await server.onAnalysisComplete; 608 await server.onAnalysisComplete;
590 // there are results 609 // there are results
591 expect(filesHighlights[file], isNull); 610 expect(filesHighlights[file], isNull);
592 } 611 }
593 612
594 test_afterAnalysis_packageFile_external() async { 613 test_afterAnalysis_packageFile_external() async {
595 String pkgFile = '/packages/pkgA/lib/libA.dart'; 614 String pkgFile = '/packages/pkgA/lib/libA.dart';
596 resourceProvider.newFile(pkgFile, ''' 615 resourceProvider.newFile(
616 pkgFile,
617 '''
597 library lib_a; 618 library lib_a;
598 class A {} 619 class A {}
599 '''); 620 ''');
600 packageMapProvider.packageMap = { 621 packageMapProvider.packageMap = {
601 'pkgA': [(resourceProvider.newFolder('/packages/pkgA/lib'))] 622 'pkgA': [(resourceProvider.newFolder('/packages/pkgA/lib'))]
602 }; 623 };
603 // 624 //
604 addTestFile(''' 625 addTestFile('''
605 import 'package:pkgA/libA.dart'; 626 import 'package:pkgA/libA.dart';
606 main() { 627 main() {
607 new A(); 628 new A();
608 } 629 }
609 '''); 630 ''');
610 createProject(); 631 createProject();
611 // wait for analysis, no results initially 632 // wait for analysis, no results initially
612 await waitForTasksFinished(); 633 await waitForTasksFinished();
613 expect(filesHighlights[pkgFile], isNull); 634 expect(filesHighlights[pkgFile], isNull);
614 // subscribe 635 // subscribe
615 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile); 636 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile);
616 await server.onAnalysisComplete; 637 await server.onAnalysisComplete;
617 // there are results 638 // there are results
618 expect(filesHighlights[pkgFile], isNotEmpty); 639 expect(filesHighlights[pkgFile], isNotEmpty);
619 } 640 }
620 641
621 test_afterAnalysis_packageFile_inRoot() async { 642 test_afterAnalysis_packageFile_inRoot() async {
622 String pkgA = '/pkgA'; 643 String pkgA = '/pkgA';
623 String pkgB = '/pkgA'; 644 String pkgB = '/pkgA';
624 String pkgFileA = '$pkgA/lib/libA.dart'; 645 String pkgFileA = '$pkgA/lib/libA.dart';
625 String pkgFileB = '$pkgA/lib/libB.dart'; 646 String pkgFileB = '$pkgA/lib/libB.dart';
626 resourceProvider.newFile(pkgFileA, ''' 647 resourceProvider.newFile(
648 pkgFileA,
649 '''
627 library lib_a; 650 library lib_a;
628 class A {} 651 class A {}
629 '''); 652 ''');
630 resourceProvider.newFile(pkgFileB, ''' 653 resourceProvider.newFile(
654 pkgFileB,
655 '''
631 import 'package:pkgA/libA.dart'; 656 import 'package:pkgA/libA.dart';
632 main() { 657 main() {
633 new A(); 658 new A();
634 } 659 }
635 '''); 660 ''');
636 packageMapProvider.packageMap = { 661 packageMapProvider.packageMap = {
637 'pkgA': [ 662 'pkgA': [
638 resourceProvider.newFolder('$pkgA/lib'), 663 resourceProvider.newFolder('$pkgA/lib'),
639 resourceProvider.newFolder('$pkgB/lib') 664 resourceProvider.newFolder('$pkgB/lib')
640 ] 665 ]
641 }; 666 };
642 // add 'pkgA' and 'pkgB' as projects 667 // add 'pkgA' and 'pkgB' as projects
643 { 668 {
644 resourceProvider.newFolder(projectPath); 669 resourceProvider.newFolder(projectPath);
645 handleSuccessfulRequest( 670 handleSuccessfulRequest(
646 new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0')); 671 new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0'));
647 } 672 }
648 // wait for analysis, no results initially 673 // wait for analysis, no results initially
649 await waitForTasksFinished(); 674 await waitForTasksFinished();
650 expect(filesHighlights[pkgFileA], isNull); 675 expect(filesHighlights[pkgFileA], isNull);
651 // subscribe 676 // subscribe
652 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFileA); 677 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFileA);
653 await server.onAnalysisComplete; 678 await server.onAnalysisComplete;
654 // there are results 679 // there are results
655 expect(filesHighlights[pkgFileA], isNotEmpty); 680 expect(filesHighlights[pkgFileA], isNotEmpty);
656 } 681 }
657 682
658 test_afterAnalysis_packageFile_notUsed() async { 683 test_afterAnalysis_packageFile_notUsed() async {
659 String pkgFile = '/packages/pkgA/lib/libA.dart'; 684 String pkgFile = '/packages/pkgA/lib/libA.dart';
660 resourceProvider.newFile(pkgFile, ''' 685 resourceProvider.newFile(
686 pkgFile,
687 '''
661 library lib_a; 688 library lib_a;
662 class A {} 689 class A {}
663 '''); 690 ''');
664 packageMapProvider.packageMap = { 691 packageMapProvider.packageMap = {
665 'pkgA': [(resourceProvider.newFolder('/packages/pkgA/lib'))] 692 'pkgA': [(resourceProvider.newFolder('/packages/pkgA/lib'))]
666 }; 693 };
667 // 694 //
668 addTestFile('// no "pkgA" reference'); 695 addTestFile('// no "pkgA" reference');
669 createProject(); 696 createProject();
670 // wait for analysis, no results initially 697 // wait for analysis, no results initially
(...skipping 25 matching lines...) Expand all
696 test_beforeAnalysis() async { 723 test_beforeAnalysis() async {
697 addTestFile('int V = 42;'); 724 addTestFile('int V = 42;');
698 createProject(); 725 createProject();
699 // subscribe 726 // subscribe
700 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); 727 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile);
701 // wait for analysis 728 // wait for analysis
702 await waitForTasksFinished(); 729 await waitForTasksFinished();
703 expect(filesHighlights[testFile], isNotEmpty); 730 expect(filesHighlights[testFile], isNotEmpty);
704 } 731 }
705 } 732 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/context_manager_test.dart ('k') | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698