| 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.model_test; | 5 library test.src.task.model_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; | 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
| 8 import 'package:analyzer/src/generated/java_engine.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 8 import 'package:analyzer/src/task/model.dart'; | 10 import 'package:analyzer/src/task/model.dart'; |
| 9 import 'package:analyzer/src/task/targets.dart'; | 11 import 'package:analyzer/src/task/targets.dart'; |
| 10 import 'package:analyzer/task/model.dart'; | 12 import 'package:analyzer/task/model.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 12 | 14 |
| 13 import '../../generated/test_support.dart'; | 15 import '../../generated/test_support.dart'; |
| 14 import '../../reflective_tests.dart'; | 16 import '../../reflective_tests.dart'; |
| 15 import 'test_support.dart'; | 17 import 'test_support.dart'; |
| 16 | 18 |
| 17 main() { | 19 main() { |
| 18 groupSep = ' | '; | 20 groupSep = ' | '; |
| 21 runReflectiveTests(AnalysisTaskTest); |
| 19 runReflectiveTests(ContributionPointImplTest); | 22 runReflectiveTests(ContributionPointImplTest); |
| 20 runReflectiveTests(ResultDescriptorImplTest); | 23 runReflectiveTests(ResultDescriptorImplTest); |
| 21 runReflectiveTests(TaskDescriptorImplTest); | 24 runReflectiveTests(TaskDescriptorImplTest); |
| 22 } | 25 } |
| 23 | 26 |
| 24 @reflectiveTest | 27 @reflectiveTest |
| 28 class AnalysisTaskTest extends EngineTestCase { |
| 29 test_getRequiredInput_missingKey() { |
| 30 SourceTarget target = new SourceTarget(new TestSource()); |
| 31 AnalysisTask task = new TestAnalysisTask(null, target); |
| 32 task.inputs = { |
| 33 'a': 'b' |
| 34 }; |
| 35 expect( |
| 36 () => task.getRequiredInput('c'), |
| 37 throwsA(new isInstanceOf<AnalysisException>())); |
| 38 } |
| 39 |
| 40 test_getRequiredInput_noInputs() { |
| 41 SourceTarget target = new SourceTarget(new TestSource()); |
| 42 AnalysisTask task = new TestAnalysisTask(null, target); |
| 43 expect( |
| 44 () => task.getRequiredInput('x'), |
| 45 throwsA(new isInstanceOf<AnalysisException>())); |
| 46 } |
| 47 |
| 48 test_getRequiredInput_valid() { |
| 49 SourceTarget target = new SourceTarget(new TestSource()); |
| 50 AnalysisTask task = new TestAnalysisTask(null, target); |
| 51 String key = 'a'; |
| 52 String value = 'b'; |
| 53 task.inputs = { |
| 54 key: value |
| 55 }; |
| 56 expect(task.getRequiredInput(key), value); |
| 57 } |
| 58 |
| 59 test_getRequiredSource() { |
| 60 Source source = new TestSource(); |
| 61 SourceTarget target = new SourceTarget(source); |
| 62 AnalysisTask task = new TestAnalysisTask(null, target); |
| 63 expect(task.getRequiredSource(), source); |
| 64 } |
| 65 } |
| 66 |
| 67 @reflectiveTest |
| 25 class ContributionPointImplTest extends EngineTestCase { | 68 class ContributionPointImplTest extends EngineTestCase { |
| 26 test_contributors_empty() { | 69 test_contributors_empty() { |
| 27 ContributionPointImpl point = new ContributionPointImpl('point'); | 70 ContributionPointImpl point = new ContributionPointImpl('point', null); |
| 28 List<ResultDescriptor> contributors = point.contributors; | 71 List<ResultDescriptor> contributors = point.contributors; |
| 29 expect(contributors, isEmpty); | 72 expect(contributors, isEmpty); |
| 30 } | 73 } |
| 31 | 74 |
| 32 test_contributors_nonEmpty() { | 75 test_contributors_nonEmpty() { |
| 33 ResultDescriptorImpl result1 = new ResultDescriptorImpl('result1'); | 76 ResultDescriptorImpl result1 = new ResultDescriptorImpl('result1', null); |
| 34 ResultDescriptorImpl result2 = new ResultDescriptorImpl('result2'); | 77 ResultDescriptorImpl result2 = new ResultDescriptorImpl('result2', null); |
| 35 ContributionPointImpl point = new ContributionPointImpl('point'); | 78 ContributionPointImpl point = new ContributionPointImpl('point', null); |
| 36 point.recordContributor(result1); | 79 point.recordContributor(result1); |
| 37 point.recordContributor(result2); | 80 point.recordContributor(result2); |
| 38 List<ResultDescriptor> contributors = point.contributors; | 81 List<ResultDescriptor> contributors = point.contributors; |
| 39 expect(contributors, isNotNull); | 82 expect(contributors, isNotNull); |
| 40 expect(contributors, hasLength(2)); | 83 expect(contributors, hasLength(2)); |
| 41 if (!(contributors[0] == result1 && contributors[1] == result2) || | 84 if (!(contributors[0] == result1 && contributors[1] == result2) || |
| 42 (contributors[0] == result2 && contributors[1] == result1)) { | 85 (contributors[0] == result2 && contributors[1] == result1)) { |
| 43 fail("Invalid contributors: $contributors"); | 86 fail("Invalid contributors: $contributors"); |
| 44 } | 87 } |
| 45 } | 88 } |
| 46 | 89 |
| 47 test_create() { | 90 test_create() { |
| 48 expect(new ContributionPointImpl('name'), isNotNull); | 91 expect(new ContributionPointImpl('name', null), isNotNull); |
| 49 } | 92 } |
| 50 | 93 |
| 51 test_name() { | 94 test_name() { |
| 52 String name = 'point'; | 95 String name = 'point'; |
| 53 ContributionPointImpl point = new ContributionPointImpl(name); | 96 ContributionPointImpl point = new ContributionPointImpl(name, null); |
| 54 expect(point.name, name); | 97 expect(point.name, name); |
| 55 } | 98 } |
| 56 } | 99 } |
| 57 | 100 |
| 58 @reflectiveTest | 101 @reflectiveTest |
| 59 class ResultDescriptorImplTest extends EngineTestCase { | 102 class ResultDescriptorImplTest extends EngineTestCase { |
| 60 test_create_withContribution() { | 103 test_create_withContribution() { |
| 61 ContributionPointImpl point = new ContributionPointImpl('point'); | 104 ContributionPointImpl point = new ContributionPointImpl('point', null); |
| 62 ResultDescriptorImpl result = | 105 ResultDescriptorImpl result = |
| 63 new ResultDescriptorImpl('result', contributesTo: point); | 106 new ResultDescriptorImpl('result', null, contributesTo: point); |
| 64 expect(result, isNotNull); | 107 expect(result, isNotNull); |
| 65 List<ResultDescriptor> contributors = point.contributors; | 108 List<ResultDescriptor> contributors = point.contributors; |
| 66 expect(contributors, unorderedEquals([result])); | 109 expect(contributors, unorderedEquals([result])); |
| 67 } | 110 } |
| 68 | 111 |
| 69 test_create_withoutContribution() { | 112 test_create_withoutContribution() { |
| 70 expect(new ResultDescriptorImpl('name'), isNotNull); | 113 expect(new ResultDescriptorImpl('name', null), isNotNull); |
| 71 } | 114 } |
| 72 | 115 |
| 73 test_inputFor() { | 116 test_inputFor() { |
| 74 SourceTarget target = new SourceTarget(null); | 117 SourceTarget target = new SourceTarget(null); |
| 75 ResultDescriptorImpl result = new ResultDescriptorImpl('result'); | 118 ResultDescriptorImpl result = new ResultDescriptorImpl('result', null); |
| 76 TaskInput input = result.inputFor(target); | 119 TaskInput input = result.inputFor(target); |
| 77 expect(input, isNotNull); | 120 expect(input, isNotNull); |
| 78 } | 121 } |
| 79 | 122 |
| 80 test_name() { | 123 test_name() { |
| 81 String name = 'result'; | 124 String name = 'result'; |
| 82 ResultDescriptorImpl result = new ResultDescriptorImpl(name); | 125 ResultDescriptorImpl result = new ResultDescriptorImpl(name, null); |
| 83 expect(result.name, name); | 126 expect(result.name, name); |
| 84 } | 127 } |
| 85 } | 128 } |
| 86 | 129 |
| 87 @reflectiveTest | 130 @reflectiveTest |
| 88 class TaskDescriptorImplTest extends EngineTestCase { | 131 class TaskDescriptorImplTest extends EngineTestCase { |
| 89 test_create() { | 132 test_create() { |
| 90 String name = 'name'; | 133 String name = 'name'; |
| 91 BuildTask buildTask = (context, target) {}; | 134 BuildTask buildTask = (context, target) {}; |
| 92 CreateTaskInputs createTaskInputs = (target) {}; | 135 CreateTaskInputs createTaskInputs = (target) {}; |
| 93 List<ResultDescriptor> results = <ResultDescriptor>[]; | 136 List<ResultDescriptor> results = <ResultDescriptor>[]; |
| 94 TaskDescriptorImpl descriptor = new TaskDescriptorImpl(name, buildTask, crea
teTaskInputs, results); | 137 TaskDescriptorImpl descriptor = |
| 138 new TaskDescriptorImpl(name, buildTask, createTaskInputs, results); |
| 95 expect(descriptor, isNotNull); | 139 expect(descriptor, isNotNull); |
| 96 expect(descriptor.name, name); | 140 expect(descriptor.name, name); |
| 97 expect(descriptor.buildTask, equals(buildTask)); | 141 expect(descriptor.buildTask, equals(buildTask)); |
| 98 expect(descriptor.createTaskInputs, equals(createTaskInputs)); | 142 expect(descriptor.createTaskInputs, equals(createTaskInputs)); |
| 99 expect(descriptor.results, results); | 143 expect(descriptor.results, results); |
| 100 } | 144 } |
| 101 | 145 |
| 102 test_createTask() { | 146 test_createTask() { |
| 103 BuildTask buildTask = (context, target) => new TestAnalysisTask(context, tar
get); | 147 BuildTask buildTask = |
| 148 (context, target) => new TestAnalysisTask(context, target); |
| 104 CreateTaskInputs createTaskInputs = (target) {}; | 149 CreateTaskInputs createTaskInputs = (target) {}; |
| 105 List<ResultDescriptor> results = <ResultDescriptor>[]; | 150 List<ResultDescriptor> results = <ResultDescriptor>[]; |
| 106 TaskDescriptorImpl descriptor = new TaskDescriptorImpl('name', buildTask, cr
eateTaskInputs, results); | 151 TaskDescriptorImpl descriptor = |
| 152 new TaskDescriptorImpl('name', buildTask, createTaskInputs, results); |
| 107 AnalysisContext context = null; | 153 AnalysisContext context = null; |
| 108 SourceTarget target = new SourceTarget(null); | 154 SourceTarget target = new SourceTarget(null); |
| 109 Map<String, dynamic> inputs = {}; | 155 Map<String, dynamic> inputs = {}; |
| 110 AnalysisTask createTask = descriptor.createTask(context, target, inputs); | 156 AnalysisTask createTask = descriptor.createTask(context, target, inputs); |
| 111 expect(createTask, isNotNull); | 157 expect(createTask, isNotNull); |
| 112 expect(createTask.context, context); | 158 expect(createTask.context, context); |
| 113 expect(createTask.inputs, inputs); | 159 expect(createTask.inputs, inputs); |
| 114 expect(createTask.target, target); | 160 expect(createTask.target, target); |
| 115 } | 161 } |
| 116 } | 162 } |
| OLD | NEW |