Chromium Code Reviews| 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 'package:analysis_server/protocol/protocol.dart'; | 5 import 'package:analysis_server/protocol/protocol.dart'; |
| 6 import 'package:analysis_server/protocol/protocol_generated.dart'; | 6 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 7 import 'package:analysis_server/src/domain_analysis.dart'; | 7 import 'package:analysis_server/src/domain_analysis.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart' | 8 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 9 show InternalAnalysisContext; | |
| 10 import 'package:analyzer/src/generated/source.dart'; | |
| 11 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 9 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| 12 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 | 12 |
| 15 import '../analysis_abstract.dart'; | 13 import '../analysis_abstract.dart'; |
| 16 import '../mocks.dart'; | 14 import '../mocks.dart'; |
| 17 | 15 |
| 18 main() { | 16 main() { |
| 19 defineReflectiveSuite(() { | 17 defineReflectiveSuite(() { |
| 20 defineReflectiveTests(SetPriorityFilesTest); | 18 defineReflectiveTests(SetPriorityFilesTest); |
| 21 }); | 19 }); |
| 22 } | 20 } |
| 23 | 21 |
| 24 @reflectiveTest | 22 @reflectiveTest |
| 25 class SetPriorityFilesTest extends AbstractAnalysisTest { | 23 class SetPriorityFilesTest extends AbstractAnalysisTest { |
| 26 @override | 24 @override |
| 27 bool get enableNewAnalysisDriver => false; | |
| 28 | |
| 29 @override | |
| 30 void setUp() { | 25 void setUp() { |
| 31 super.setUp(); | 26 super.setUp(); |
| 32 server.handlers = [ | 27 server.handlers = [ |
| 33 new AnalysisDomainHandler(server), | 28 new AnalysisDomainHandler(server), |
| 34 ]; | 29 ]; |
| 35 createProject(); | 30 createProject(); |
| 36 } | 31 } |
| 37 | 32 |
| 38 test_fileDoesNotExist() async { | 33 test_fileDoesNotExist() async { |
| 39 String file = '$projectPath/doesNotExist.dart'; | 34 String file = '$projectPath/doesNotExist.dart'; |
| 40 Response response = await _setPriorityFile(file); | 35 Response response = await _setPriorityFile(file); |
| 41 expect(response, isResponseSuccess('0')); | 36 expect(response, isResponseSuccess('0')); |
| 42 } | 37 } |
| 43 | 38 |
| 44 test_fileInAnalysisRoot() async { | 39 test_fileInAnalysisRoot() async { |
| 45 addTestFile(''); | 40 addTestFile(''); |
| 46 // wait for analysis to ensure that the file is known to the context | |
| 47 await server.onAnalysisComplete; | |
| 48 // set priority files | 41 // set priority files |
| 49 Response response = await _setPriorityFile(testFile); | 42 Response response = await _setPriorityFile(testFile); |
| 50 expect(response, isResponseSuccess('0')); | 43 expect(response, isResponseSuccess('0')); |
| 51 // verify | 44 // verify |
| 52 InternalAnalysisContext context = server.getContainingContext(testFile); | 45 _verifyPriorityFiles(testFile); |
| 53 List<Source> prioritySources = context.prioritySources; | |
| 54 expect(prioritySources, hasLength(1)); | |
| 55 expect(prioritySources.first.fullName, testFile); | |
| 56 } | 46 } |
| 57 | 47 |
| 58 test_fileInSdk() async { | 48 test_fileInSdk() async { |
| 59 addTestFile(''); | 49 addTestFile(''); |
| 60 await server.onAnalysisComplete; | |
| 61 // set priority files | 50 // set priority files |
| 62 String filePath = '/lib/convert/convert.dart'; | 51 String filePath = '/lib/convert/convert.dart'; |
| 63 Response response = await _setPriorityFile(filePath); | 52 Response response = await _setPriorityFile(filePath); |
| 64 expect(response, isResponseSuccess('0')); | 53 expect(response, isResponseSuccess('0')); |
| 65 // verify | 54 // verify |
| 66 InternalAnalysisContext sdkContext = server.findSdk().context; | 55 _verifyPriorityFiles(filePath); |
| 67 List<Source> prioritySources = sdkContext.prioritySources; | |
| 68 expect(prioritySources, hasLength(1)); | |
| 69 expect(prioritySources.first.fullName, filePath); | |
| 70 } | 56 } |
| 71 | 57 |
| 72 test_fileNotInAnalysisRoot() async { | 58 test_fileNotInAnalysisRoot() async { |
| 73 String path = '/other/file.dart'; | 59 String path = '/other/file.dart'; |
| 74 addFile(path, ''); | 60 addFile(path, ''); |
| 75 Response response = await _setPriorityFile(path); | 61 await _setPriorityFile(path); |
| 76 expect(response.error, isNotNull); | 62 _verifyPriorityFiles(path); |
| 77 expect(response.error.code, RequestErrorCode.UNANALYZED_PRIORITY_FILES); | |
| 78 } | 63 } |
| 79 | 64 |
| 80 test_ignoredInAnalysisOptions() async { | 65 test_ignoredInAnalysisOptions() async { |
| 81 String sampleFile = '$projectPath/samples/sample.dart'; | 66 String sampleFile = '$projectPath/samples/sample.dart'; |
| 82 addFile( | 67 addFile( |
| 83 '$projectPath/.analysis_options', | 68 '$projectPath/.analysis_options', |
| 84 r''' | 69 r''' |
| 85 analyzer: | 70 analyzer: |
| 86 exclude: | 71 exclude: |
| 87 - 'samples/**' | 72 - 'samples/**' |
| 88 '''); | 73 '''); |
| 89 addFile(sampleFile, ''); | 74 addFile(sampleFile, ''); |
| 90 // attempt to set priority file | 75 // attempt to set priority file |
| 91 Response response = await _setPriorityFile(sampleFile); | 76 await _setPriorityFile(sampleFile); |
| 92 expect(response.error, isNotNull); | 77 _verifyPriorityFiles(sampleFile); |
| 93 expect(response.error.code, RequestErrorCode.UNANALYZED_PRIORITY_FILES); | |
| 94 } | 78 } |
| 95 | 79 |
| 96 test_ignoredInAnalysisOptions_inChildContext() async { | 80 test_ignoredInAnalysisOptions_inChildContext() async { |
| 97 addFile('$projectPath/.packages', ''); | 81 addFile('$projectPath/.packages', ''); |
| 98 addFile('$projectPath/child/.packages', ''); | 82 addFile('$projectPath/child/.packages', ''); |
| 99 String sampleFile = '$projectPath/child/samples/sample.dart'; | 83 String sampleFile = '$projectPath/child/samples/sample.dart'; |
| 100 addFile( | 84 addFile( |
| 101 '$projectPath/child/.analysis_options', | 85 '$projectPath/child/.analysis_options', |
| 102 r''' | 86 r''' |
| 103 analyzer: | 87 analyzer: |
| 104 exclude: | 88 exclude: |
| 105 - 'samples/**' | 89 - 'samples/**' |
| 106 '''); | 90 '''); |
| 107 addFile(sampleFile, ''); | 91 addFile(sampleFile, ''); |
| 108 // attempt to set priority file | 92 // attempt to set priority file |
| 109 Response response = await _setPriorityFile(sampleFile); | 93 await _setPriorityFile(sampleFile); |
| 110 expect(response.error, isNotNull); | 94 _verifyPriorityFiles(sampleFile); |
| 111 expect(response.error.code, RequestErrorCode.UNANALYZED_PRIORITY_FILES); | |
| 112 } | 95 } |
| 113 | 96 |
| 114 test_ignoredInAnalysisOptions_inRootContext() async { | 97 test_ignoredInAnalysisOptions_inRootContext() async { |
| 115 addFile('$projectPath/.packages', ''); | 98 addFile('$projectPath/.packages', ''); |
| 116 addFile('$projectPath/child/.packages', ''); | 99 addFile('$projectPath/child/.packages', ''); |
| 117 String sampleFile = '$projectPath/child/samples/sample.dart'; | 100 String sampleFile = '$projectPath/child/samples/sample.dart'; |
| 118 addFile( | 101 addFile( |
| 119 '$projectPath/.analysis_options', | 102 '$projectPath/.analysis_options', |
| 120 r''' | 103 r''' |
| 121 analyzer: | 104 analyzer: |
| 122 exclude: | 105 exclude: |
| 123 - 'child/samples/**' | 106 - 'child/samples/**' |
| 124 '''); | 107 '''); |
| 125 addFile(sampleFile, ''); | 108 addFile(sampleFile, ''); |
| 126 // attempt to set priority file | 109 // attempt to set priority file |
| 127 Response response = await _setPriorityFile(sampleFile); | 110 await _setPriorityFile(sampleFile); |
| 128 expect(response.error, isNotNull); | 111 _verifyPriorityFiles(sampleFile); |
| 129 expect(response.error.code, RequestErrorCode.UNANALYZED_PRIORITY_FILES); | |
| 130 } | 112 } |
| 131 | 113 |
| 132 test_sentToPlugins() async { | 114 test_sentToPlugins() async { |
| 133 addTestFile(''); | 115 addTestFile(''); |
| 134 // wait for analysis to ensure that the file is known to the context | |
| 135 await server.onAnalysisComplete; | |
| 136 // set priority files | 116 // set priority files |
| 137 Response response = await _setPriorityFile(testFile); | 117 Response response = await _setPriorityFile(testFile); |
| 138 expect(response, isResponseSuccess('0')); | 118 expect(response, isResponseSuccess('0')); |
| 139 // verify | 119 // verify |
| 140 plugin.AnalysisSetPriorityFilesParams params = | 120 plugin.AnalysisSetPriorityFilesParams params = |
| 141 pluginManager.analysisSetPriorityFilesParams; | 121 pluginManager.analysisSetPriorityFilesParams; |
| 142 expect(params, isNotNull); | 122 expect(params, isNotNull); |
| 143 expect(params.files, <String>[testFile]); | 123 expect(params.files, <String>[testFile]); |
| 144 } | 124 } |
| 145 | 125 |
| 146 _setPriorityFile(String file) async { | 126 _setPriorityFile(String file) async { |
| 147 Request request = | 127 Request request = |
| 148 new AnalysisSetPriorityFilesParams(<String>[file]).toRequest('0'); | 128 new AnalysisSetPriorityFilesParams(<String>[file]).toRequest('0'); |
| 149 return await serverChannel.sendRequest(request); | 129 return await serverChannel.sendRequest(request); |
| 150 } | 130 } |
| 131 | |
| 132 void _verifyPriorityFiles(String path) { | |
| 133 AnalysisDriver driver = server.getAnalysisDriver(path); | |
| 134 List<String> prioritySources = driver.priorityFiles; | |
| 135 expect(prioritySources, hasLength(1)); | |
|
scheglov
2017/06/12 21:07:40
It could be just expect(driver.priorityFiles, [pat
Brian Wilkerson
2017/06/12 21:09:49
Done
| |
| 136 expect(prioritySources.first, path); | |
| 137 } | |
| 151 } | 138 } |
| OLD | NEW |