| 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 library test.analysis.notification.analyzedDirectories; | 5 library test.analysis.notification.analyzedDirectories; |
| 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/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| 11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 13 | 13 |
| 14 import '../analysis_abstract.dart'; | 14 import '../analysis_abstract.dart'; |
| 15 import '../mocks.dart'; | 15 import '../mocks.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
| 19 defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest); | 19 defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest); |
| 20 defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest_Driver); |
| 20 }); | 21 }); |
| 21 } | 22 } |
| 22 | 23 |
| 23 @reflectiveTest | 24 @reflectiveTest |
| 24 class AnalysisNotificationAnalyzedFilesTest extends AbstractAnalysisTest { | 25 class AnalysisNotificationAnalyzedFilesTest extends AbstractAnalysisTest { |
| 25 List<String> analyzedFiles; | 26 List<String> analyzedFiles; |
| 26 bool analyzedFilesReceived = false; | 27 bool analyzedFilesReceived = false; |
| 27 | 28 |
| 28 void assertHasFile(String filePath) { | 29 void assertHasFile(String filePath) { |
| 29 expect(analyzedFilesReceived, isTrue); | 30 expect(analyzedFilesReceived, isTrue); |
| 30 expect(analyzedFiles, contains(filePath)); | 31 expect(analyzedFiles, contains(filePath)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 Future prepareAnalyzedFiles() { | 34 Future<Null> prepareAnalyzedFiles() async { |
| 34 addGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); | 35 addGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); |
| 35 return waitForTasksFinished(); | 36 await pumpEventQueue(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void processNotification(Notification notification) { | 39 void processNotification(Notification notification) { |
| 39 if (notification.event == ANALYSIS_ANALYZED_FILES) { | 40 if (notification.event == ANALYSIS_ANALYZED_FILES) { |
| 40 AnalysisAnalyzedFilesParams params = | 41 AnalysisAnalyzedFilesParams params = |
| 41 new AnalysisAnalyzedFilesParams.fromNotification(notification); | 42 new AnalysisAnalyzedFilesParams.fromNotification(notification); |
| 42 analyzedFilesReceived = true; | 43 analyzedFilesReceived = true; |
| 43 analyzedFiles = params.directories; | 44 analyzedFiles = params.directories; |
| 44 } | 45 } |
| 45 } | 46 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 '''); | 65 '''); |
| 65 await prepareAnalyzedFiles(); | 66 await prepareAnalyzedFiles(); |
| 66 assertHasFile(testFile); | 67 assertHasFile(testFile); |
| 67 } | 68 } |
| 68 | 69 |
| 69 test_insignificant_change() async { | 70 test_insignificant_change() async { |
| 70 // Making a change that doesn't affect the set of reachable files should | 71 // Making a change that doesn't affect the set of reachable files should |
| 71 // not trigger the notification to be re-sent. | 72 // not trigger the notification to be re-sent. |
| 72 addTestFile('class A {}'); | 73 addTestFile('class A {}'); |
| 73 await prepareAnalyzedFiles(); | 74 await prepareAnalyzedFiles(); |
| 74 await waitForTasksFinished(); | |
| 75 expect(analyzedFilesReceived, isTrue); | 75 expect(analyzedFilesReceived, isTrue); |
| 76 |
| 76 analyzedFilesReceived = false; | 77 analyzedFilesReceived = false; |
| 77 modifyTestFile('class B {}'); | 78 modifyTestFile('class B {}'); |
| 78 await pumpEventQueue(); | 79 await prepareAnalyzedFiles(); |
| 79 await waitForTasksFinished(); | |
| 80 expect(analyzedFilesReceived, isFalse); | 80 expect(analyzedFilesReceived, isFalse); |
| 81 } | 81 } |
| 82 | 82 |
| 83 test_resubscribe_no_changes() async { | 83 test_resubscribe_no_changes() async { |
| 84 // Unsubscribing and resubscribing should cause the notification to be | 84 // Unsubscribing and resubscribing should cause the notification to be |
| 85 // re-sent, even if nothing has changed. | 85 // re-sent, even if nothing has changed. |
| 86 addTestFile('class A {}'); | 86 addTestFile('class A {}'); |
| 87 await prepareAnalyzedFiles(); | 87 await prepareAnalyzedFiles(); |
| 88 await waitForTasksFinished(); | |
| 89 expect(analyzedFilesReceived, isTrue); | 88 expect(analyzedFilesReceived, isTrue); |
| 89 |
| 90 unsubscribeAnalyzedFiles(); | 90 unsubscribeAnalyzedFiles(); |
| 91 analyzedFilesReceived = false; | 91 analyzedFilesReceived = false; |
| 92 |
| 92 await prepareAnalyzedFiles(); | 93 await prepareAnalyzedFiles(); |
| 93 expect(analyzedFilesReceived, isTrue); | 94 expect(analyzedFilesReceived, isTrue); |
| 94 assertHasFile(testFile); | 95 assertHasFile(testFile); |
| 95 } | 96 } |
| 96 | 97 |
| 97 test_significant_change() async { | 98 test_significant_change() async { |
| 98 // Making a change that *does* affect the set of reachable files should | 99 // Making a change that *does* affect the set of reachable files should |
| 99 // trigger the notification to be re-sent. | 100 // trigger the notification to be re-sent. |
| 100 addTestFile('class A {}'); | 101 addTestFile('class A {}'); |
| 101 addFile('/foo.dart', 'library foo'); | 102 addFile('/foo.dart', 'library foo;'); |
| 102 await prepareAnalyzedFiles(); | 103 await prepareAnalyzedFiles(); |
| 103 await waitForTasksFinished(); | |
| 104 expect(analyzedFilesReceived, isTrue); | 104 expect(analyzedFilesReceived, isTrue); |
| 105 |
| 105 analyzedFilesReceived = false; | 106 analyzedFilesReceived = false; |
| 106 modifyTestFile('import "/foo.dart";'); | 107 modifyTestFile('import "/foo.dart";'); |
| 107 await pumpEventQueue(); | 108 await prepareAnalyzedFiles(); |
| 108 await waitForTasksFinished(); | |
| 109 expect(analyzedFilesReceived, isTrue); | |
| 110 assertHasFile('/foo.dart'); | 109 assertHasFile('/foo.dart'); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void unsubscribeAnalyzedFiles() { | 112 void unsubscribeAnalyzedFiles() { |
| 114 removeGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); | 113 removeGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); |
| 115 } | 114 } |
| 116 } | 115 } |
| 116 |
| 117 @reflectiveTest |
| 118 class AnalysisNotificationAnalyzedFilesTest_Driver |
| 119 extends AnalysisNotificationAnalyzedFilesTest { |
| 120 @override |
| 121 void setUp() { |
| 122 enableNewAnalysisDriver = true; |
| 123 generateSummaryFiles = true; |
| 124 super.setUp(); |
| 125 } |
| 126 } |
| OLD | NEW |