| 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_constants.dart'; | 8 import 'package:analysis_server/protocol/protocol_constants.dart'; |
| 9 import 'package:analysis_server/protocol/protocol_generated.dart'; | 9 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 | 13 |
| 13 import '../analysis_abstract.dart'; | 14 import '../analysis_abstract.dart'; |
| 14 import '../mocks.dart'; | 15 import '../mocks.dart'; |
| 15 | 16 |
| 16 main() { | 17 main() { |
| 17 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
| 18 defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest); | 19 defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest); |
| 19 }); | 20 }); |
| 20 } | 21 } |
| 21 | 22 |
| 22 @reflectiveTest | 23 @reflectiveTest |
| 23 class AnalysisNotificationAnalyzedFilesTest extends AbstractAnalysisTest { | 24 class AnalysisNotificationAnalyzedFilesTest extends AbstractAnalysisTest { |
| 24 List<String> analyzedFiles; | 25 List<String> analyzedFiles; |
| 25 bool analyzedFilesReceived = false; | 26 bool analyzedFilesReceived = false; |
| 26 | 27 |
| 27 void assertHasFile(String filePath) { | 28 void assertHasFile(String filePath) { |
| 28 expect(analyzedFilesReceived, isTrue); | 29 expect(analyzedFilesReceived, isTrue); |
| 29 expect(analyzedFiles, contains(filePath)); | 30 expect(analyzedFiles, contains(filePath)); |
| 30 } | 31 } |
| 31 | 32 |
| 33 void assertHasNoFile(String filePath) { |
| 34 expect(analyzedFilesReceived, isTrue); |
| 35 expect(analyzedFiles, isNot(contains(filePath))); |
| 36 } |
| 37 |
| 32 Future<Null> prepareAnalyzedFiles() async { | 38 Future<Null> prepareAnalyzedFiles() async { |
| 33 addGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); | 39 addGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); |
| 34 await pumpEventQueue(); | 40 await pumpEventQueue(); |
| 35 } | 41 } |
| 36 | 42 |
| 37 void processNotification(Notification notification) { | 43 void processNotification(Notification notification) { |
| 38 if (notification.event == ANALYSIS_NOTIFICATION_ANALYZED_FILES) { | 44 if (notification.event == ANALYSIS_NOTIFICATION_ANALYZED_FILES) { |
| 39 AnalysisAnalyzedFilesParams params = | 45 AnalysisAnalyzedFilesParams params = |
| 40 new AnalysisAnalyzedFilesParams.fromNotification(notification); | 46 new AnalysisAnalyzedFilesParams.fromNotification(notification); |
| 41 analyzedFilesReceived = true; | 47 analyzedFilesReceived = true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 } | 65 } |
| 60 | 66 |
| 61 test_beforeAnalysis() async { | 67 test_beforeAnalysis() async { |
| 62 addTestFile(''' | 68 addTestFile(''' |
| 63 class A {} | 69 class A {} |
| 64 '''); | 70 '''); |
| 65 await prepareAnalyzedFiles(); | 71 await prepareAnalyzedFiles(); |
| 66 assertHasFile(testFile); | 72 assertHasFile(testFile); |
| 67 } | 73 } |
| 68 | 74 |
| 75 test_beforeAnalysis_excludeYamlFiles() async { |
| 76 File yamlFile = resourceProvider |
| 77 .getFolder(projectPath) |
| 78 .getChildAssumingFile('sample.yaml'); |
| 79 yamlFile.writeAsStringSync(''); |
| 80 addTestFile(''' |
| 81 class A {} |
| 82 '''); |
| 83 await prepareAnalyzedFiles(); |
| 84 assertHasFile(testFile); |
| 85 assertHasNoFile(yamlFile.path); |
| 86 } |
| 87 |
| 69 test_insignificant_change() async { | 88 test_insignificant_change() async { |
| 70 // Making a change that doesn't affect the set of reachable files should | 89 // Making a change that doesn't affect the set of reachable files should |
| 71 // not trigger the notification to be re-sent. | 90 // not trigger the notification to be re-sent. |
| 72 addTestFile('class A {}'); | 91 addTestFile('class A {}'); |
| 73 await prepareAnalyzedFiles(); | 92 await prepareAnalyzedFiles(); |
| 74 expect(analyzedFilesReceived, isTrue); | 93 expect(analyzedFilesReceived, isTrue); |
| 75 | 94 |
| 76 analyzedFilesReceived = false; | 95 analyzedFilesReceived = false; |
| 77 modifyTestFile('class B {}'); | 96 modifyTestFile('class B {}'); |
| 78 await prepareAnalyzedFiles(); | 97 await prepareAnalyzedFiles(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 analyzedFilesReceived = false; | 124 analyzedFilesReceived = false; |
| 106 modifyTestFile('import "/foo.dart";'); | 125 modifyTestFile('import "/foo.dart";'); |
| 107 await prepareAnalyzedFiles(); | 126 await prepareAnalyzedFiles(); |
| 108 assertHasFile('/foo.dart'); | 127 assertHasFile('/foo.dart'); |
| 109 } | 128 } |
| 110 | 129 |
| 111 void unsubscribeAnalyzedFiles() { | 130 void unsubscribeAnalyzedFiles() { |
| 112 removeGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); | 131 removeGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES); |
| 113 } | 132 } |
| 114 } | 133 } |
| OLD | NEW |