| 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 analyzer.test.src.task.driver_test; | 5 library analyzer.test.src.task.driver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/generated/java_engine.dart'; | 9 import 'package:analyzer/src/generated/java_engine.dart'; |
| 10 import 'package:analyzer/src/task/driver.dart'; | 10 import 'package:analyzer/src/task/driver.dart'; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 test_createNextWorkOrder_none() { | 118 test_createNextWorkOrder_none() { |
| 119 _configureDescriptors12(); | 119 _configureDescriptors12(); |
| 120 when(workManager1.getNextResultPriority()) | 120 when(workManager1.getNextResultPriority()) |
| 121 .thenReturn(WorkOrderPriority.NONE); | 121 .thenReturn(WorkOrderPriority.NONE); |
| 122 when(workManager2.getNextResultPriority()) | 122 when(workManager2.getNextResultPriority()) |
| 123 .thenReturn(WorkOrderPriority.NONE); | 123 .thenReturn(WorkOrderPriority.NONE); |
| 124 expect(analysisDriver.createNextWorkOrder(), isNull); | 124 expect(analysisDriver.createNextWorkOrder(), isNull); |
| 125 } | 125 } |
| 126 | 126 |
| 127 test_createWorkOrderForResult_aboutToComputeResult() { |
| 128 AnalysisTarget target = new TestSource(); |
| 129 ResultDescriptor result = new ResultDescriptor('result', null); |
| 130 TaskDescriptor descriptor = new TaskDescriptor( |
| 131 'task', |
| 132 (context, target) => new TestAnalysisTask(context, target), |
| 133 (target) => {}, |
| 134 [result]); |
| 135 taskManager.addTaskDescriptor(descriptor); |
| 136 context.getCacheEntry(target).setState(result, CacheState.INVALID); |
| 137 // has result |
| 138 { |
| 139 when(context.aboutToComputeResult(anyObject, result)).thenReturn(true); |
| 140 WorkOrder workOrder = |
| 141 analysisDriver.createWorkOrderForResult(target, result); |
| 142 expect(workOrder, isNull); |
| 143 } |
| 144 // no result |
| 145 { |
| 146 when(context.aboutToComputeResult(anyObject, result)).thenReturn(false); |
| 147 WorkOrder workOrder = |
| 148 analysisDriver.createWorkOrderForResult(target, result); |
| 149 expect(workOrder, isNotNull); |
| 150 } |
| 151 } |
| 152 |
| 127 test_createWorkOrderForResult_error() { | 153 test_createWorkOrderForResult_error() { |
| 128 AnalysisTarget target = new TestSource(); | 154 AnalysisTarget target = new TestSource(); |
| 129 ResultDescriptor result = new ResultDescriptor('result', null); | 155 ResultDescriptor result = new ResultDescriptor('result', null); |
| 130 CaughtException exception = new CaughtException(null, null); | 156 CaughtException exception = new CaughtException(null, null); |
| 131 context | 157 context |
| 132 .getCacheEntry(target) | 158 .getCacheEntry(target) |
| 133 .setErrorState(exception, <ResultDescriptor>[result]); | 159 .setErrorState(exception, <ResultDescriptor>[result]); |
| 134 | 160 |
| 135 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); | 161 expect(analysisDriver.createWorkOrderForResult(target, result), isNull); |
| 136 } | 162 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 AnalysisTarget target = new TestSource(); | 668 AnalysisTarget target = new TestSource(); |
| 643 TaskDescriptor descriptor = new TaskDescriptor( | 669 TaskDescriptor descriptor = new TaskDescriptor( |
| 644 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); | 670 'task', null, (target) => {}, [new ResultDescriptor('result', null)]); |
| 645 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); | 671 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); |
| 646 expect(item, isNotNull); | 672 expect(item, isNotNull); |
| 647 expect(item.context, context); | 673 expect(item.context, context); |
| 648 expect(item.descriptor, descriptor); | 674 expect(item.descriptor, descriptor); |
| 649 expect(item.target, target); | 675 expect(item.target, target); |
| 650 } | 676 } |
| 651 | 677 |
| 652 test_gatherInputs_complete() { | 678 test_gatherInputs_aboutToComputeResult_hasResult() { |
| 653 AnalysisTarget target = new TestSource(); | |
| 654 TaskDescriptor descriptor = new TaskDescriptor( | |
| 655 'task', | |
| 656 (context, target) => new TestAnalysisTask(context, target), | |
| 657 (target) => {}, | |
| 658 [new ResultDescriptor('output', null)]); | |
| 659 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); | |
| 660 WorkItem result = item.gatherInputs(taskManager, []); | |
| 661 expect(result, isNull); | |
| 662 expect(item.exception, isNull); | |
| 663 } | |
| 664 | |
| 665 test_gatherInputs_incomplete() { | |
| 666 AnalysisTarget target = new TestSource(); | 679 AnalysisTarget target = new TestSource(); |
| 667 ResultDescriptor resultA = new ResultDescriptor('resultA', null); | 680 ResultDescriptor resultA = new ResultDescriptor('resultA', null); |
| 668 ResultDescriptor resultB = new ResultDescriptor('resultB', null); | 681 ResultDescriptor resultB = new ResultDescriptor('resultB', null); |
| 669 // prepare tasks | 682 // prepare tasks |
| 670 TaskDescriptor task1 = new TaskDescriptor( | 683 TaskDescriptor task1 = new TaskDescriptor( |
| 671 'task', | 684 'task', |
| 672 (context, target) => | 685 (context, target) => |
| 673 new TestAnalysisTask(context, target, results: [resultA]), | 686 new TestAnalysisTask(context, target, results: [resultA]), |
| 674 (target) => {}, | 687 (target) => {}, |
| 675 [resultA]); | 688 [resultA]); |
| 676 TaskDescriptor task2 = new TaskDescriptor( | 689 TaskDescriptor task2 = new TaskDescriptor( |
| 677 'task', | 690 'task', |
| 678 (context, target) => new TestAnalysisTask(context, target), | 691 (context, target) => new TestAnalysisTask(context, target), |
| 679 (target) => {'one': resultA.of(target)}, | 692 (target) => {'one': resultA.of(target)}, |
| 680 [resultB]); | 693 [resultB]); |
| 681 taskManager.addTaskDescriptor(task1); | 694 taskManager.addTaskDescriptor(task1); |
| 682 taskManager.addTaskDescriptor(task2); | 695 taskManager.addTaskDescriptor(task2); |
| 696 // configure mocks |
| 697 when(context.aboutToComputeResult(anyObject, resultA)).thenReturn(true); |
| 683 // gather inputs | 698 // gather inputs |
| 684 WorkItem item = new WorkItem(context, target, task2, null, 0, null); | 699 WorkItem item = new WorkItem(context, target, task2, null, 0, null); |
| 685 WorkItem inputItem = item.gatherInputs(taskManager, []); | 700 WorkItem inputItem = item.gatherInputs(taskManager, []); |
| 686 expect(inputItem, isNotNull); | 701 expect(inputItem, isNull); |
| 687 } | 702 } |
| 688 | 703 |
| 689 test_gatherInputs_invalid() { | 704 test_gatherInputs_aboutToComputeResult_noResult() { |
| 690 AnalysisTarget target = new TestSource(); | |
| 691 ResultDescriptor inputResult = new ResultDescriptor('input', null); | |
| 692 TaskDescriptor descriptor = new TaskDescriptor( | |
| 693 'task', | |
| 694 (context, target) => new TestAnalysisTask(context, target), | |
| 695 (target) => {'one': inputResult.of(target)}, | |
| 696 [new ResultDescriptor('output', null)]); | |
| 697 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); | |
| 698 WorkItem result = item.gatherInputs(taskManager, []); | |
| 699 expect(result, isNull); | |
| 700 expect(item.exception, isNotNull); | |
| 701 } | |
| 702 | |
| 703 test_gatherInputs_aboutToComputeResult_hasResult() { | |
| 704 AnalysisTarget target = new TestSource(); | 705 AnalysisTarget target = new TestSource(); |
| 705 ResultDescriptor resultA = new ResultDescriptor('resultA', null); | 706 ResultDescriptor resultA = new ResultDescriptor('resultA', null); |
| 706 ResultDescriptor resultB = new ResultDescriptor('resultB', null); | 707 ResultDescriptor resultB = new ResultDescriptor('resultB', null); |
| 707 // prepare tasks | 708 // prepare tasks |
| 708 TaskDescriptor task1 = new TaskDescriptor( | 709 TaskDescriptor task1 = new TaskDescriptor( |
| 709 'task', | 710 'task', |
| 710 (context, target) => | 711 (context, target) => |
| 711 new TestAnalysisTask(context, target, results: [resultA]), | 712 new TestAnalysisTask(context, target, results: [resultA]), |
| 712 (target) => {}, | 713 (target) => {}, |
| 713 [resultA]); | 714 [resultA]); |
| 714 TaskDescriptor task2 = new TaskDescriptor( | 715 TaskDescriptor task2 = new TaskDescriptor( |
| 715 'task', | 716 'task', |
| 716 (context, target) => new TestAnalysisTask(context, target), | 717 (context, target) => new TestAnalysisTask(context, target), |
| 717 (target) => {'one': resultA.of(target)}, | 718 (target) => {'one': resultA.of(target)}, |
| 718 [resultB]); | 719 [resultB]); |
| 719 taskManager.addTaskDescriptor(task1); | 720 taskManager.addTaskDescriptor(task1); |
| 720 taskManager.addTaskDescriptor(task2); | 721 taskManager.addTaskDescriptor(task2); |
| 722 // configure ResultProvider |
| 721 // configure mocks | 723 // configure mocks |
| 722 when(context.aboutToComputeResult(anyObject, resultA)).thenReturn(true); | 724 when(context.aboutToComputeResult(anyObject, resultA)).thenReturn(false); |
| 723 // gather inputs | 725 // gather inputs |
| 724 WorkItem item = new WorkItem(context, target, task2, null, 0, null); | 726 WorkItem item = new WorkItem(context, target, task2, null, 0, null); |
| 725 WorkItem inputItem = item.gatherInputs(taskManager, []); | 727 WorkItem inputItem = item.gatherInputs(taskManager, []); |
| 726 expect(inputItem, isNull); | 728 expect(inputItem, isNotNull); |
| 729 expect(inputItem.target, target); |
| 730 expect(inputItem.descriptor, task1); |
| 727 } | 731 } |
| 728 | 732 |
| 729 test_gatherInputs_aboutToComputeResult_noResult() { | 733 test_gatherInputs_complete() { |
| 734 AnalysisTarget target = new TestSource(); |
| 735 TaskDescriptor descriptor = new TaskDescriptor( |
| 736 'task', |
| 737 (context, target) => new TestAnalysisTask(context, target), |
| 738 (target) => {}, |
| 739 [new ResultDescriptor('output', null)]); |
| 740 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); |
| 741 WorkItem result = item.gatherInputs(taskManager, []); |
| 742 expect(result, isNull); |
| 743 expect(item.exception, isNull); |
| 744 } |
| 745 |
| 746 test_gatherInputs_incomplete() { |
| 730 AnalysisTarget target = new TestSource(); | 747 AnalysisTarget target = new TestSource(); |
| 731 ResultDescriptor resultA = new ResultDescriptor('resultA', null); | 748 ResultDescriptor resultA = new ResultDescriptor('resultA', null); |
| 732 ResultDescriptor resultB = new ResultDescriptor('resultB', null); | 749 ResultDescriptor resultB = new ResultDescriptor('resultB', null); |
| 733 // prepare tasks | 750 // prepare tasks |
| 734 TaskDescriptor task1 = new TaskDescriptor( | 751 TaskDescriptor task1 = new TaskDescriptor( |
| 735 'task', | 752 'task', |
| 736 (context, target) => | 753 (context, target) => |
| 737 new TestAnalysisTask(context, target, results: [resultA]), | 754 new TestAnalysisTask(context, target, results: [resultA]), |
| 738 (target) => {}, | 755 (target) => {}, |
| 739 [resultA]); | 756 [resultA]); |
| 740 TaskDescriptor task2 = new TaskDescriptor( | 757 TaskDescriptor task2 = new TaskDescriptor( |
| 741 'task', | 758 'task', |
| 742 (context, target) => new TestAnalysisTask(context, target), | 759 (context, target) => new TestAnalysisTask(context, target), |
| 743 (target) => {'one': resultA.of(target)}, | 760 (target) => {'one': resultA.of(target)}, |
| 744 [resultB]); | 761 [resultB]); |
| 745 taskManager.addTaskDescriptor(task1); | 762 taskManager.addTaskDescriptor(task1); |
| 746 taskManager.addTaskDescriptor(task2); | 763 taskManager.addTaskDescriptor(task2); |
| 747 // configure ResultProvider | |
| 748 // configure mocks | |
| 749 when(context.aboutToComputeResult(anyObject, resultA)).thenReturn(false); | |
| 750 // gather inputs | 764 // gather inputs |
| 751 WorkItem item = new WorkItem(context, target, task2, null, 0, null); | 765 WorkItem item = new WorkItem(context, target, task2, null, 0, null); |
| 752 WorkItem inputItem = item.gatherInputs(taskManager, []); | 766 WorkItem inputItem = item.gatherInputs(taskManager, []); |
| 753 expect(inputItem, isNotNull); | 767 expect(inputItem, isNotNull); |
| 754 expect(inputItem.target, target); | 768 } |
| 755 expect(inputItem.descriptor, task1); | 769 |
| 770 test_gatherInputs_invalid() { |
| 771 AnalysisTarget target = new TestSource(); |
| 772 ResultDescriptor inputResult = new ResultDescriptor('input', null); |
| 773 TaskDescriptor descriptor = new TaskDescriptor( |
| 774 'task', |
| 775 (context, target) => new TestAnalysisTask(context, target), |
| 776 (target) => {'one': inputResult.of(target)}, |
| 777 [new ResultDescriptor('output', null)]); |
| 778 WorkItem item = new WorkItem(context, target, descriptor, null, 0, null); |
| 779 WorkItem result = item.gatherInputs(taskManager, []); |
| 780 expect(result, isNull); |
| 781 expect(item.exception, isNotNull); |
| 756 } | 782 } |
| 757 } | 783 } |
| 758 | 784 |
| 759 @reflectiveTest | 785 @reflectiveTest |
| 760 class WorkOrderTest extends EngineTestCase { | 786 class WorkOrderTest extends EngineTestCase { |
| 761 test_create() { | 787 test_create() { |
| 762 TaskManager manager = new TaskManager(); | 788 TaskManager manager = new TaskManager(); |
| 763 TaskDescriptor descriptor = new TaskDescriptor( | 789 TaskDescriptor descriptor = new TaskDescriptor( |
| 764 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); | 790 'task', null, (_) => {}, [new ResultDescriptor('result', null)]); |
| 765 WorkOrder order = new WorkOrder( | 791 WorkOrder order = new WorkOrder( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 if (!skipInputs.contains(dependency) && | 856 if (!skipInputs.contains(dependency) && |
| 831 !evaluatedNodes.contains(dependency)) { | 857 !evaluatedNodes.contains(dependency)) { |
| 832 return dependency; | 858 return dependency; |
| 833 } | 859 } |
| 834 } | 860 } |
| 835 return null; | 861 return null; |
| 836 } | 862 } |
| 837 } | 863 } |
| 838 | 864 |
| 839 class _WorkManagerMock extends TypedMock implements WorkManager {} | 865 class _WorkManagerMock extends TypedMock implements WorkManager {} |
| OLD | NEW |