| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 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'; |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 code = code.join('\n'); | 642 code = code.join('\n'); |
| 643 } | 643 } |
| 644 return code as String; | 644 return code as String; |
| 645 } | 645 } |
| 646 } | 646 } |
| 647 | 647 |
| 648 @reflectiveTest | 648 @reflectiveTest |
| 649 class SetSubscriptionsTest extends AbstractAnalysisTest { | 649 class SetSubscriptionsTest extends AbstractAnalysisTest { |
| 650 Map<String, List<HighlightRegion>> filesHighlights = {}; | 650 Map<String, List<HighlightRegion>> filesHighlights = {}; |
| 651 | 651 |
| 652 @override | 652 Completer _resultsAvailable = new Completer(); |
| 653 bool get enableNewAnalysisDriver => false; | |
| 654 | 653 |
| 655 void processNotification(Notification notification) { | 654 void processNotification(Notification notification) { |
| 656 if (notification.event == ANALYSIS_HIGHLIGHTS) { | 655 if (notification.event == ANALYSIS_HIGHLIGHTS) { |
| 657 var params = new AnalysisHighlightsParams.fromNotification(notification); | 656 var params = new AnalysisHighlightsParams.fromNotification(notification); |
| 658 filesHighlights[params.file] = params.regions; | 657 filesHighlights[params.file] = params.regions; |
| 658 _resultsAvailable.complete(null); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 test_afterAnalysis() async { | 662 test_afterAnalysis() async { |
| 663 addTestFile('int V = 42;'); | 663 addTestFile('int V = 42;'); |
| 664 createProject(); | 664 createProject(); |
| 665 // wait for analysis, no results initially | 665 // wait for analysis, no results initially |
| 666 await waitForTasksFinished(); | 666 await waitForTasksFinished(); |
| 667 expect(filesHighlights[testFile], isNull); | 667 expect(filesHighlights[testFile], isNull); |
| 668 // subscribe | 668 // subscribe |
| 669 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); | 669 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); |
| 670 await server.onAnalysisComplete; | 670 await _resultsAvailable.future; |
| 671 // there are results | 671 // there are results |
| 672 expect(filesHighlights[testFile], isNotEmpty); | 672 expect(filesHighlights[testFile], isNotEmpty); |
| 673 } | 673 } |
| 674 | 674 |
| 675 test_afterAnalysis_noSuchFile() async { | 675 test_afterAnalysis_noSuchFile() async { |
| 676 String file = '/no-such-file.dart'; | 676 String file = '/no-such-file.dart'; |
| 677 addTestFile('// no matter'); | 677 addTestFile('// no matter'); |
| 678 createProject(); | 678 createProject(); |
| 679 // wait for analysis, no results initially | 679 // wait for analysis, no results initially |
| 680 await waitForTasksFinished(); | 680 await waitForTasksFinished(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 702 main() { | 702 main() { |
| 703 new A(); | 703 new A(); |
| 704 } | 704 } |
| 705 '''); | 705 '''); |
| 706 createProject(); | 706 createProject(); |
| 707 // wait for analysis, no results initially | 707 // wait for analysis, no results initially |
| 708 await waitForTasksFinished(); | 708 await waitForTasksFinished(); |
| 709 expect(filesHighlights[pkgFile], isNull); | 709 expect(filesHighlights[pkgFile], isNull); |
| 710 // subscribe | 710 // subscribe |
| 711 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile); | 711 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile); |
| 712 await server.onAnalysisComplete; | 712 await _resultsAvailable.future; |
| 713 // there are results | 713 // there are results |
| 714 expect(filesHighlights[pkgFile], isNotEmpty); | 714 expect(filesHighlights[pkgFile], isNotEmpty); |
| 715 } | 715 } |
| 716 | 716 |
| 717 test_afterAnalysis_packageFile_inRoot() async { | 717 test_afterAnalysis_packageFile_inRoot() async { |
| 718 String pkgA = '/pkgA'; | 718 String pkgA = '/pkgA'; |
| 719 String pkgB = '/pkgA'; | 719 String pkgB = '/pkgA'; |
| 720 String pkgFileA = '$pkgA/lib/libA.dart'; | 720 String pkgFileA = '$pkgA/lib/libA.dart'; |
| 721 String pkgFileB = '$pkgA/lib/libB.dart'; | 721 String pkgFileB = '$pkgA/lib/libB.dart'; |
| 722 resourceProvider.newFile( | 722 resourceProvider.newFile( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 743 { | 743 { |
| 744 resourceProvider.newFolder(projectPath); | 744 resourceProvider.newFolder(projectPath); |
| 745 handleSuccessfulRequest( | 745 handleSuccessfulRequest( |
| 746 new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0')); | 746 new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0')); |
| 747 } | 747 } |
| 748 // wait for analysis, no results initially | 748 // wait for analysis, no results initially |
| 749 await waitForTasksFinished(); | 749 await waitForTasksFinished(); |
| 750 expect(filesHighlights[pkgFileA], isNull); | 750 expect(filesHighlights[pkgFileA], isNull); |
| 751 // subscribe | 751 // subscribe |
| 752 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFileA); | 752 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFileA); |
| 753 await server.onAnalysisComplete; | 753 await _resultsAvailable.future; |
| 754 // there are results | 754 // there are results |
| 755 expect(filesHighlights[pkgFileA], isNotEmpty); | 755 expect(filesHighlights[pkgFileA], isNotEmpty); |
| 756 } | 756 } |
| 757 | 757 |
| 758 test_afterAnalysis_packageFile_notUsed() async { | 758 test_afterAnalysis_packageFile_notUsed() async { |
| 759 String pkgFile = '/packages/pkgA/lib/libA.dart'; | 759 String pkgFile = '/packages/pkgA/lib/libA.dart'; |
| 760 resourceProvider.newFile( | 760 resourceProvider.newFile( |
| 761 pkgFile, | 761 pkgFile, |
| 762 ''' | 762 ''' |
| 763 library lib_a; | 763 library lib_a; |
| 764 class A {} | 764 class A {} |
| 765 '''); | 765 '''); |
| 766 resourceProvider.newFile('/project/.packages', 'pkgA:/packages/pkgA/lib'); | 766 resourceProvider.newFile('/project/.packages', 'pkgA:/packages/pkgA/lib'); |
| 767 // | 767 // |
| 768 addTestFile('// no "pkgA" reference'); | 768 addTestFile('// no "pkgA" reference'); |
| 769 createProject(); | 769 createProject(); |
| 770 // wait for analysis, no results initially | 770 // wait for analysis, no results initially |
| 771 await waitForTasksFinished(); | 771 await waitForTasksFinished(); |
| 772 expect(filesHighlights[pkgFile], isNull); | 772 expect(filesHighlights[pkgFile], isNull); |
| 773 // make it a priority file, so make analyzable | 773 // make it a priority file, so make analyzable |
| 774 server.setPriorityFiles('0', [pkgFile]); | 774 server.setPriorityFiles('0', [pkgFile]); |
| 775 // subscribe | 775 // subscribe |
| 776 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile); | 776 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile); |
| 777 await server.onAnalysisComplete; | 777 await _resultsAvailable.future; |
| 778 // there are results | 778 // there are results |
| 779 expect(filesHighlights[pkgFile], isNotEmpty); | 779 expect(filesHighlights[pkgFile], isNotEmpty); |
| 780 } | 780 } |
| 781 | 781 |
| 782 test_afterAnalysis_sdkFile() async { | 782 test_afterAnalysis_sdkFile() async { |
| 783 String file = '/lib/core/core.dart'; | 783 String file = '/lib/core/core.dart'; |
| 784 addTestFile('// no matter'); | 784 addTestFile('// no matter'); |
| 785 createProject(); | 785 createProject(); |
| 786 // wait for analysis, no results initially | 786 // wait for analysis, no results initially |
| 787 await waitForTasksFinished(); | 787 await waitForTasksFinished(); |
| 788 expect(filesHighlights[file], isNull); | 788 expect(filesHighlights[file], isNull); |
| 789 // subscribe | 789 // subscribe |
| 790 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); | 790 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file); |
| 791 await server.onAnalysisComplete; | 791 await _resultsAvailable.future; |
| 792 // there are results | 792 // there are results |
| 793 expect(filesHighlights[file], isNotEmpty); | 793 expect(filesHighlights[file], isNotEmpty); |
| 794 } | 794 } |
| 795 | 795 |
| 796 test_beforeAnalysis() async { | 796 test_beforeAnalysis() async { |
| 797 addTestFile('int V = 42;'); | 797 addTestFile('int V = 42;'); |
| 798 createProject(); | 798 createProject(); |
| 799 // subscribe | 799 // subscribe |
| 800 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); | 800 addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile); |
| 801 // wait for analysis | 801 // wait for analysis |
| (...skipping 11 matching lines...) Expand all Loading... |
| 813 plugin.AnalysisSetSubscriptionsParams params = | 813 plugin.AnalysisSetSubscriptionsParams params = |
| 814 pluginManager.analysisSetSubscriptionsParams; | 814 pluginManager.analysisSetSubscriptionsParams; |
| 815 expect(params, isNotNull); | 815 expect(params, isNotNull); |
| 816 Map<plugin.AnalysisService, List<String>> subscriptions = | 816 Map<plugin.AnalysisService, List<String>> subscriptions = |
| 817 params.subscriptions; | 817 params.subscriptions; |
| 818 expect(subscriptions, hasLength(1)); | 818 expect(subscriptions, hasLength(1)); |
| 819 List<String> files = subscriptions[plugin.AnalysisService.HIGHLIGHTS]; | 819 List<String> files = subscriptions[plugin.AnalysisService.HIGHLIGHTS]; |
| 820 expect(files, [testFile]); | 820 expect(files, [testFile]); |
| 821 } | 821 } |
| 822 } | 822 } |
| OLD | NEW |