| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask, | 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask, |
| 8 ParseDartTask, ScanDartTask; | 8 ParseDartTask, ScanDartTask; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/task/dart.dart'; | 10 import 'package:analyzer/src/task/dart.dart'; |
| 11 import 'package:analyzer/src/task/targets.dart'; | |
| 12 import 'package:analyzer/task/dart.dart'; | 11 import 'package:analyzer/task/dart.dart'; |
| 13 import 'package:analyzer/task/general.dart'; | 12 import 'package:analyzer/task/general.dart'; |
| 14 import 'package:analyzer/task/model.dart'; | 13 import 'package:analyzer/task/model.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 16 | 15 |
| 17 import '../../generated/resolver_test.dart'; | 16 import '../../generated/resolver_test.dart'; |
| 18 import '../../generated/test_support.dart'; | 17 import '../../generated/test_support.dart'; |
| 19 import '../../reflective_tests.dart'; | 18 import '../../reflective_tests.dart'; |
| 20 | 19 |
| 21 main() { | 20 main() { |
| 22 groupSep = ' | '; | 21 groupSep = ' | '; |
| 23 runReflectiveTests(BuildCompilationUnitElementTaskTest); | 22 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 24 runReflectiveTests(ParseDartTaskTest); | 23 runReflectiveTests(ParseDartTaskTest); |
| 25 runReflectiveTests(ScanDartTaskTest); | 24 runReflectiveTests(ScanDartTaskTest); |
| 26 } | 25 } |
| 27 | 26 |
| 28 @reflectiveTest | 27 @reflectiveTest |
| 29 class BuildCompilationUnitElementTaskTest extends EngineTestCase { | 28 class BuildCompilationUnitElementTaskTest extends EngineTestCase { |
| 30 test_buildInputs() { | 29 test_buildInputs() { |
| 31 SourceTarget target = new SourceTarget(new TestSource()); | 30 AnalysisTarget target = new TestSource(); |
| 32 Map<String, TaskInput> inputs = | 31 Map<String, TaskInput> inputs = |
| 33 BuildCompilationUnitElementTask.buildInputs(target); | 32 BuildCompilationUnitElementTask.buildInputs(target); |
| 34 expect(inputs, isNotNull); | 33 expect(inputs, isNotNull); |
| 35 expect(inputs, hasLength(1)); | 34 expect(inputs, hasLength(1)); |
| 36 expect( | 35 expect( |
| 37 inputs[BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME], | 36 inputs[BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME], |
| 38 isNotNull); | 37 isNotNull); |
| 39 } | 38 } |
| 40 | 39 |
| 41 test_constructor() { | 40 test_constructor() { |
| 42 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 41 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 43 SourceTarget target = new SourceTarget(new TestSource()); | 42 AnalysisTarget target = new TestSource(); |
| 44 BuildCompilationUnitElementTask task = | 43 BuildCompilationUnitElementTask task = |
| 45 new BuildCompilationUnitElementTask(context, target); | 44 new BuildCompilationUnitElementTask(context, target); |
| 46 expect(task, isNotNull); | 45 expect(task, isNotNull); |
| 47 expect(task.context, context); | 46 expect(task.context, context); |
| 48 expect(task.target, target); | 47 expect(task.target, target); |
| 49 } | 48 } |
| 50 | 49 |
| 51 test_createTask() { | 50 test_createTask() { |
| 52 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 51 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 53 SourceTarget target = new SourceTarget(new TestSource()); | 52 AnalysisTarget target = new TestSource(); |
| 54 BuildCompilationUnitElementTask task = | 53 BuildCompilationUnitElementTask task = |
| 55 BuildCompilationUnitElementTask.createTask(context, target); | 54 BuildCompilationUnitElementTask.createTask(context, target); |
| 56 expect(task, isNotNull); | 55 expect(task, isNotNull); |
| 57 expect(task.context, context); | 56 expect(task.context, context); |
| 58 expect(task.target, target); | 57 expect(task.target, target); |
| 59 } | 58 } |
| 60 | 59 |
| 61 test_description() { | 60 test_description() { |
| 62 SourceTarget target = new SourceTarget(new TestSource()); | 61 AnalysisTarget target = new TestSource(); |
| 63 BuildCompilationUnitElementTask task = | 62 BuildCompilationUnitElementTask task = |
| 64 new BuildCompilationUnitElementTask(null, target); | 63 new BuildCompilationUnitElementTask(null, target); |
| 65 expect(task.description, isNotNull); | 64 expect(task.description, isNotNull); |
| 66 } | 65 } |
| 67 | 66 |
| 68 test_descriptor() { | 67 test_descriptor() { |
| 69 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; | 68 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; |
| 70 expect(descriptor, isNotNull); | 69 expect(descriptor, isNotNull); |
| 71 } | 70 } |
| 72 | 71 |
| 73 test_perform_library() { | 72 test_perform_library() { |
| 74 BuildCompilationUnitElementTask task = _performBuildTask(r''' | 73 BuildCompilationUnitElementTask task = _performBuildTask(r''' |
| 75 library lib; | 74 library lib; |
| 76 import 'lib2.dart'; | 75 import 'lib2.dart'; |
| 77 export 'lib3.dart'; | 76 export 'lib3.dart'; |
| 78 part 'part.dart'; | 77 part 'part.dart'; |
| 79 class A {'''); | 78 class A {'''); |
| 80 | 79 |
| 81 expect(task.caughtException, isNull); | 80 expect(task.caughtException, isNull); |
| 82 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; | 81 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 83 expect(outputs, hasLength(2)); | 82 expect(outputs, hasLength(2)); |
| 84 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 83 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 85 expect(outputs[BUILT_UNIT], isNotNull); | 84 expect(outputs[BUILT_UNIT], isNotNull); |
| 86 } | 85 } |
| 87 | 86 |
| 88 BuildCompilationUnitElementTask _performBuildTask(String content) { | 87 BuildCompilationUnitElementTask _performBuildTask(String content) { |
| 89 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 88 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 90 SourceTarget target = new SourceTarget(new TestSource()); | 89 AnalysisTarget target = new TestSource(); |
| 91 | 90 |
| 92 ScanDartTask scanTask = new ScanDartTask(context, target); | 91 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 93 scanTask.inputs = { | 92 scanTask.inputs = { |
| 94 ScanDartTask.CONTENT_INPUT_NAME: content | 93 ScanDartTask.CONTENT_INPUT_NAME: content |
| 95 }; | 94 }; |
| 96 scanTask.perform(); | 95 scanTask.perform(); |
| 97 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 96 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 98 | 97 |
| 99 ParseDartTask parseTask = new ParseDartTask(context, target); | 98 ParseDartTask parseTask = new ParseDartTask(context, target); |
| 100 parseTask.inputs = { | 99 parseTask.inputs = { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 }; | 111 }; |
| 113 buildTask.perform(); | 112 buildTask.perform(); |
| 114 | 113 |
| 115 return buildTask; | 114 return buildTask; |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 | 117 |
| 119 @reflectiveTest | 118 @reflectiveTest |
| 120 class ParseDartTaskTest extends EngineTestCase { | 119 class ParseDartTaskTest extends EngineTestCase { |
| 121 test_buildInputs() { | 120 test_buildInputs() { |
| 122 SourceTarget target = new SourceTarget(new TestSource()); | 121 AnalysisTarget target = new TestSource(); |
| 123 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(target); | 122 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(target); |
| 124 expect(inputs, isNotNull); | 123 expect(inputs, isNotNull); |
| 125 expect(inputs, hasLength(2)); | 124 expect(inputs, hasLength(2)); |
| 126 expect(inputs[ParseDartTask.LINE_INFO_INPUT_NAME], isNotNull); | 125 expect(inputs[ParseDartTask.LINE_INFO_INPUT_NAME], isNotNull); |
| 127 expect(inputs[ParseDartTask.TOKEN_STREAM_INPUT_NAME], isNotNull); | 126 expect(inputs[ParseDartTask.TOKEN_STREAM_INPUT_NAME], isNotNull); |
| 128 } | 127 } |
| 129 | 128 |
| 130 test_constructor() { | 129 test_constructor() { |
| 131 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 130 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 132 SourceTarget target = new SourceTarget(new TestSource()); | 131 AnalysisTarget target = new TestSource(); |
| 133 ParseDartTask task = new ParseDartTask(context, target); | 132 ParseDartTask task = new ParseDartTask(context, target); |
| 134 expect(task, isNotNull); | 133 expect(task, isNotNull); |
| 135 expect(task.context, context); | 134 expect(task.context, context); |
| 136 expect(task.target, target); | 135 expect(task.target, target); |
| 137 } | 136 } |
| 138 | 137 |
| 139 test_createTask() { | 138 test_createTask() { |
| 140 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 139 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 141 SourceTarget target = new SourceTarget(new TestSource()); | 140 AnalysisTarget target = new TestSource(); |
| 142 ParseDartTask task = ParseDartTask.createTask(context, target); | 141 ParseDartTask task = ParseDartTask.createTask(context, target); |
| 143 expect(task, isNotNull); | 142 expect(task, isNotNull); |
| 144 expect(task.context, context); | 143 expect(task.context, context); |
| 145 expect(task.target, target); | 144 expect(task.target, target); |
| 146 } | 145 } |
| 147 | 146 |
| 148 test_description() { | 147 test_description() { |
| 149 SourceTarget target = new SourceTarget(new TestSource()); | 148 AnalysisTarget target = new TestSource(); |
| 150 ParseDartTask task = new ParseDartTask(null, target); | 149 ParseDartTask task = new ParseDartTask(null, target); |
| 151 expect(task.description, isNotNull); | 150 expect(task.description, isNotNull); |
| 152 } | 151 } |
| 153 | 152 |
| 154 test_descriptor() { | 153 test_descriptor() { |
| 155 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; | 154 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; |
| 156 expect(descriptor, isNotNull); | 155 expect(descriptor, isNotNull); |
| 157 } | 156 } |
| 158 | 157 |
| 159 test_perform() { | 158 test_perform() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 205 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 207 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); | 206 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); |
| 208 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 207 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 209 expect(outputs[PARSE_ERRORS], hasLength(1)); | 208 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 210 expect(outputs[PARSED_UNIT], isNotNull); | 209 expect(outputs[PARSED_UNIT], isNotNull); |
| 211 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 210 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 212 } | 211 } |
| 213 | 212 |
| 214 ParseDartTask _performParseTask(String content) { | 213 ParseDartTask _performParseTask(String content) { |
| 215 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 214 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 216 SourceTarget target = new SourceTarget(new TestSource()); | 215 AnalysisTarget target = new TestSource(); |
| 217 | 216 |
| 218 ScanDartTask scanTask = new ScanDartTask(context, target); | 217 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 219 scanTask.inputs = { | 218 scanTask.inputs = { |
| 220 ScanDartTask.CONTENT_INPUT_NAME: content | 219 ScanDartTask.CONTENT_INPUT_NAME: content |
| 221 }; | 220 }; |
| 222 scanTask.perform(); | 221 scanTask.perform(); |
| 223 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 222 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 224 | 223 |
| 225 ParseDartTask parseTask = new ParseDartTask(context, target); | 224 ParseDartTask parseTask = new ParseDartTask(context, target); |
| 226 parseTask.inputs = { | 225 parseTask.inputs = { |
| 227 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], | 226 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], |
| 228 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] | 227 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] |
| 229 }; | 228 }; |
| 230 parseTask.perform(); | 229 parseTask.perform(); |
| 231 return parseTask; | 230 return parseTask; |
| 232 } | 231 } |
| 233 } | 232 } |
| 234 | 233 |
| 235 @reflectiveTest | 234 @reflectiveTest |
| 236 class ScanDartTaskTest extends EngineTestCase { | 235 class ScanDartTaskTest extends EngineTestCase { |
| 237 test_buildInputs() { | 236 test_buildInputs() { |
| 238 SourceTarget target = new SourceTarget(new TestSource()); | 237 AnalysisTarget target = new TestSource(); |
| 239 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); | 238 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); |
| 240 expect(inputs, isNotNull); | 239 expect(inputs, isNotNull); |
| 241 expect(inputs, hasLength(1)); | 240 expect(inputs, hasLength(1)); |
| 242 expect(inputs[ScanDartTask.CONTENT_INPUT_NAME], isNotNull); | 241 expect(inputs[ScanDartTask.CONTENT_INPUT_NAME], isNotNull); |
| 243 } | 242 } |
| 244 | 243 |
| 245 test_constructor() { | 244 test_constructor() { |
| 246 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 245 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 247 SourceTarget target = new SourceTarget(new TestSource()); | 246 AnalysisTarget target = new TestSource(); |
| 248 ScanDartTask task = new ScanDartTask(context, target); | 247 ScanDartTask task = new ScanDartTask(context, target); |
| 249 expect(task, isNotNull); | 248 expect(task, isNotNull); |
| 250 expect(task.context, context); | 249 expect(task.context, context); |
| 251 expect(task.target, target); | 250 expect(task.target, target); |
| 252 } | 251 } |
| 253 | 252 |
| 254 test_createTask() { | 253 test_createTask() { |
| 255 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 254 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 256 SourceTarget target = new SourceTarget(new TestSource()); | 255 AnalysisTarget target = new TestSource(); |
| 257 ScanDartTask task = ScanDartTask.createTask(context, target); | 256 ScanDartTask task = ScanDartTask.createTask(context, target); |
| 258 expect(task, isNotNull); | 257 expect(task, isNotNull); |
| 259 expect(task.context, context); | 258 expect(task.context, context); |
| 260 expect(task.target, target); | 259 expect(task.target, target); |
| 261 } | 260 } |
| 262 | 261 |
| 263 test_description() { | 262 test_description() { |
| 264 SourceTarget target = new SourceTarget(new TestSource()); | 263 AnalysisTarget target = new TestSource(); |
| 265 ScanDartTask task = new ScanDartTask(null, target); | 264 ScanDartTask task = new ScanDartTask(null, target); |
| 266 expect(task.description, isNotNull); | 265 expect(task.description, isNotNull); |
| 267 } | 266 } |
| 268 | 267 |
| 269 test_descriptor() { | 268 test_descriptor() { |
| 270 TaskDescriptor descriptor = ScanDartTask.DESCRIPTOR; | 269 TaskDescriptor descriptor = ScanDartTask.DESCRIPTOR; |
| 271 expect(descriptor, isNotNull); | 270 expect(descriptor, isNotNull); |
| 272 } | 271 } |
| 273 | 272 |
| 274 test_perform_errors() { | 273 test_perform_errors() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 288 expect(scanTask.caughtException, isNull); | 287 expect(scanTask.caughtException, isNull); |
| 289 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; | 288 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 290 expect(scanOutputs, hasLength(3)); | 289 expect(scanOutputs, hasLength(3)); |
| 291 expect(scanOutputs[LINE_INFO], isNotNull); | 290 expect(scanOutputs[LINE_INFO], isNotNull); |
| 292 expect(scanOutputs[SCAN_ERRORS], hasLength(0)); | 291 expect(scanOutputs[SCAN_ERRORS], hasLength(0)); |
| 293 expect(scanOutputs[TOKEN_STREAM], isNotNull); | 292 expect(scanOutputs[TOKEN_STREAM], isNotNull); |
| 294 } | 293 } |
| 295 | 294 |
| 296 ScanDartTask _performScanTask(String content) { | 295 ScanDartTask _performScanTask(String content) { |
| 297 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 296 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 298 SourceTarget target = new SourceTarget(new TestSource()); | 297 AnalysisTarget target = new TestSource(); |
| 299 | 298 |
| 300 ScanDartTask scanTask = new ScanDartTask(context, target); | 299 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 301 scanTask.inputs = { | 300 scanTask.inputs = { |
| 302 ScanDartTask.CONTENT_INPUT_NAME: content | 301 ScanDartTask.CONTENT_INPUT_NAME: content |
| 303 }; | 302 }; |
| 304 scanTask.perform(); | 303 scanTask.perform(); |
| 305 return scanTask; | 304 return scanTask; |
| 306 } | 305 } |
| 307 } | 306 } |
| OLD | NEW |