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