| 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 library test.context.directory.manager; | 5 library test.context.directory.manager; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:collection'; | 8 import 'dart:collection'; |
| 8 | 9 |
| 9 import 'package:analysis_server/src/context_manager.dart'; | 10 import 'package:analysis_server/src/context_manager.dart'; |
| 10 import 'package:analysis_server/src/utilities/null_string_sink.dart'; | 11 import 'package:analysis_server/src/utilities/null_string_sink.dart'; |
| 11 import 'package:analyzer/context/context_root.dart'; | 12 import 'package:analyzer/context/context_root.dart'; |
| 12 import 'package:analyzer/error/error.dart'; | 13 import 'package:analyzer/error/error.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; | 15 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 16 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 16 import 'package:analyzer/source/error_processor.dart'; | 17 import 'package:analyzer/source/error_processor.dart'; |
| 17 import 'package:analyzer/src/context/builder.dart'; | 18 import 'package:analyzer/src/context/builder.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 19 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 19 import 'package:analyzer/src/dart/analysis/driver.dart'; | 20 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 20 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 21 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 21 import 'package:analyzer/src/error/codes.dart'; | 22 import 'package:analyzer/src/error/codes.dart'; |
| 22 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; | 23 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; |
| 23 import 'package:analyzer/src/generated/sdk.dart'; | 24 import 'package:analyzer/src/generated/sdk.dart'; |
| 24 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 25 import 'package:analyzer/src/generated/source_io.dart'; | 26 import 'package:analyzer/src/generated/source_io.dart'; |
| 26 import 'package:analyzer/src/services/lint.dart'; | 27 import 'package:analyzer/src/services/lint.dart'; |
| 27 import 'package:analyzer/src/summary/summary_file_builder.dart'; | 28 import 'package:analyzer/src/summary/summary_file_builder.dart'; |
| 28 import 'package:analyzer/src/util/glob.dart'; | 29 import 'package:analyzer/src/util/glob.dart'; |
| 29 import 'package:linter/src/rules.dart'; | 30 import 'package:linter/src/rules.dart'; |
| 30 import 'package:linter/src/rules/avoid_as.dart'; | 31 import 'package:linter/src/rules/avoid_as.dart'; |
| 31 import 'package:path/path.dart' as path; | 32 import 'package:path/path.dart' as path; |
| 32 import 'package:plugin/manager.dart'; | 33 import 'package:plugin/manager.dart'; |
| 33 import 'package:plugin/plugin.dart'; | 34 import 'package:plugin/plugin.dart'; |
| 34 import 'package:test/test.dart'; | 35 import 'package:test/test.dart'; |
| 35 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 36 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 37 import 'package:watcher/watcher.dart'; |
| 36 | 38 |
| 37 import 'mock_sdk.dart'; | 39 import 'mock_sdk.dart'; |
| 38 import 'mocks.dart'; | 40 import 'mocks.dart'; |
| 39 | 41 |
| 40 main() { | 42 main() { |
| 41 defineReflectiveSuite(() { | 43 defineReflectiveSuite(() { |
| 42 defineReflectiveTests(AbstractContextManagerTest); | 44 defineReflectiveTests(AbstractContextManagerTest); |
| 43 defineReflectiveTests(ContextManagerWithNewOptionsTest); | 45 defineReflectiveTests(ContextManagerWithNewOptionsTest); |
| 44 defineReflectiveTests(ContextManagerWithOldOptionsTest); | 46 defineReflectiveTests(ContextManagerWithOldOptionsTest); |
| 45 }); | 47 }); |
| (...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2591 analyzer: | 2593 analyzer: |
| 2592 strong-mode: true | 2594 strong-mode: true |
| 2593 '''); | 2595 '''); |
| 2594 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 2596 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
| 2595 newFile([libPath, 'main.dart']); | 2597 newFile([libPath, 'main.dart']); |
| 2596 // Setup context. | 2598 // Setup context. |
| 2597 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2599 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 2598 // Verify that analysis options was parsed and strong-mode set. | 2600 // Verify that analysis options was parsed and strong-mode set. |
| 2599 expect(analysisOptions.strongMode, true); | 2601 expect(analysisOptions.strongMode, true); |
| 2600 } | 2602 } |
| 2603 |
| 2604 test_watchEvents() async { |
| 2605 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
| 2606 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 2607 newFile([libPath, 'main.dart']); |
| 2608 await new Future.delayed(new Duration(milliseconds: 1)); |
| 2609 expect(callbacks.watchEvents, hasLength(1)); |
| 2610 } |
| 2601 } | 2611 } |
| 2602 | 2612 |
| 2603 class TestContextManagerCallbacks extends ContextManagerCallbacks { | 2613 class TestContextManagerCallbacks extends ContextManagerCallbacks { |
| 2604 /** | 2614 /** |
| 2605 * Source of timestamps stored in [currentContextFilePaths]. | 2615 * Source of timestamps stored in [currentContextFilePaths]. |
| 2606 */ | 2616 */ |
| 2607 int now = 0; | 2617 int now = 0; |
| 2608 | 2618 |
| 2609 /** | 2619 /** |
| 2610 * The analysis context that was created. | 2620 * The analysis context that was created. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2657 /** | 2667 /** |
| 2658 * The scheduler used by the driver. | 2668 * The scheduler used by the driver. |
| 2659 */ | 2669 */ |
| 2660 final AnalysisDriverScheduler scheduler; | 2670 final AnalysisDriverScheduler scheduler; |
| 2661 | 2671 |
| 2662 /** | 2672 /** |
| 2663 * The list of `flushedFiles` in the last [removeContext] invocation. | 2673 * The list of `flushedFiles` in the last [removeContext] invocation. |
| 2664 */ | 2674 */ |
| 2665 List<String> lastFlushedFiles; | 2675 List<String> lastFlushedFiles; |
| 2666 | 2676 |
| 2677 /** |
| 2678 * The watch events that have been broadcast. |
| 2679 */ |
| 2680 List<WatchEvent> watchEvents = <WatchEvent>[]; |
| 2681 |
| 2667 TestContextManagerCallbacks( | 2682 TestContextManagerCallbacks( |
| 2668 this.resourceProvider, this.sdkManager, this.logger, this.scheduler); | 2683 this.resourceProvider, this.sdkManager, this.logger, this.scheduler); |
| 2669 | 2684 |
| 2670 /** | 2685 /** |
| 2671 * Return the current set of analysis options. | 2686 * Return the current set of analysis options. |
| 2672 */ | 2687 */ |
| 2673 AnalysisOptions get analysisOptions => currentDriver == null | 2688 AnalysisOptions get analysisOptions => currentDriver == null |
| 2674 ? currentContext.analysisOptions | 2689 ? currentContext.analysisOptions |
| 2675 : currentDriver.analysisOptions; | 2690 : currentDriver.analysisOptions; |
| 2676 | 2691 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2795 | 2810 |
| 2796 void assertContextFiles(String contextPath, List<String> expectedFiles) { | 2811 void assertContextFiles(String contextPath, List<String> expectedFiles) { |
| 2797 expect(getCurrentFilePaths(contextPath), unorderedEquals(expectedFiles)); | 2812 expect(getCurrentFilePaths(contextPath), unorderedEquals(expectedFiles)); |
| 2798 } | 2813 } |
| 2799 | 2814 |
| 2800 void assertContextPaths(List<String> expected) { | 2815 void assertContextPaths(List<String> expected) { |
| 2801 expect(currentContextRoots, unorderedEquals(expected)); | 2816 expect(currentContextRoots, unorderedEquals(expected)); |
| 2802 } | 2817 } |
| 2803 | 2818 |
| 2804 @override | 2819 @override |
| 2820 void broadcastWatchEvent(WatchEvent event) { |
| 2821 watchEvents.add(event); |
| 2822 } |
| 2823 |
| 2824 @override |
| 2805 void computingPackageMap(bool computing) { | 2825 void computingPackageMap(bool computing) { |
| 2806 // Do nothing. | 2826 // Do nothing. |
| 2807 } | 2827 } |
| 2808 | 2828 |
| 2809 @override | 2829 @override |
| 2810 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options, | 2830 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options, |
| 2811 {bool useSummaries = false}) { | 2831 {bool useSummaries = false}) { |
| 2812 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); | 2832 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); |
| 2813 builderOptions.defaultOptions = options; | 2833 builderOptions.defaultOptions = options; |
| 2814 ContextBuilder builder = new ContextBuilder( | 2834 ContextBuilder builder = new ContextBuilder( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 class TestUriResolver extends UriResolver { | 2919 class TestUriResolver extends UriResolver { |
| 2900 Map<Uri, Source> uriMap; | 2920 Map<Uri, Source> uriMap; |
| 2901 | 2921 |
| 2902 TestUriResolver(this.uriMap); | 2922 TestUriResolver(this.uriMap); |
| 2903 | 2923 |
| 2904 @override | 2924 @override |
| 2905 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2925 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 2906 return uriMap[uri]; | 2926 return uriMap[uri]; |
| 2907 } | 2927 } |
| 2908 } | 2928 } |
| OLD | NEW |