Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/driver_test.dart

Issue 2657533004: Update MockSdk to be more consistent with the actual SDK, switch x_Driver tests to it. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.driver; 5 library analyzer.test.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
11 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 11 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
12 import 'package:analyzer/dart/element/element.dart'; 12 import 'package:analyzer/dart/element/element.dart';
13 import 'package:analyzer/dart/element/type.dart'; 13 import 'package:analyzer/dart/element/type.dart';
14 import 'package:analyzer/error/error.dart'; 14 import 'package:analyzer/error/error.dart';
15 import 'package:analyzer/file_system/file_system.dart'; 15 import 'package:analyzer/file_system/file_system.dart';
16 import 'package:analyzer/file_system/memory_file_system.dart'; 16 import 'package:analyzer/file_system/memory_file_system.dart';
17 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 17 import 'package:analyzer/src/dart/analysis/byte_store.dart';
18 import 'package:analyzer/src/dart/analysis/driver.dart'; 18 import 'package:analyzer/src/dart/analysis/driver.dart';
19 import 'package:analyzer/src/dart/analysis/file_state.dart'; 19 import 'package:analyzer/src/dart/analysis/file_state.dart';
20 import 'package:analyzer/src/dart/analysis/status.dart'; 20 import 'package:analyzer/src/dart/analysis/status.dart';
21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
22 import 'package:analyzer/src/error/codes.dart'; 22 import 'package:analyzer/src/error/codes.dart';
23 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; 23 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
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/summary/idl.dart'; 26 import 'package:analyzer/src/summary/idl.dart';
26 import 'package:convert/convert.dart'; 27 import 'package:convert/convert.dart';
27 import 'package:crypto/crypto.dart'; 28 import 'package:crypto/crypto.dart';
28 import 'package:test/test.dart'; 29 import 'package:test/test.dart';
29 import 'package:test_reflective_loader/test_reflective_loader.dart'; 30 import 'package:test_reflective_loader/test_reflective_loader.dart';
30 31
32 import '../../context/mock_sdk.dart';
31 import 'base.dart'; 33 import 'base.dart';
32 import 'physical_sdk.dart';
33 34
34 main() { 35 main() {
35 defineReflectiveSuite(() { 36 defineReflectiveSuite(() {
36 defineReflectiveTests(AnalysisDriverTest); 37 defineReflectiveTests(AnalysisDriverTest);
37 defineReflectiveTests(AnalysisDriverSchedulerTest); 38 defineReflectiveTests(AnalysisDriverSchedulerTest);
38 }); 39 });
39 } 40 }
40 41
41 /** 42 /**
42 * Returns a [Future] that completes after pumping the event queue [times] 43 * Returns a [Future] that completes after pumping the event queue [times]
43 * times. By default, this should pump the event queue enough times to allow 44 * times. By default, this should pump the event queue enough times to allow
44 * any code to run, as long as it's not waiting on some external event. 45 * any code to run, as long as it's not waiting on some external event.
45 */ 46 */
46 Future pumpEventQueue([int times = 5000]) { 47 Future pumpEventQueue([int times = 5000]) {
47 if (times == 0) return new Future.value(); 48 if (times == 0) return new Future.value();
48 // We use a delayed future to allow microtask events to finish. The 49 // We use a delayed future to allow microtask events to finish. The
49 // Future.value or Future() constructors use scheduleMicrotask themselves and 50 // Future.value or Future() constructors use scheduleMicrotask themselves and
50 // would therefore not wait for microtask callbacks that are scheduled after 51 // would therefore not wait for microtask callbacks that are scheduled after
51 // invoking this method. 52 // invoking this method.
52 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); 53 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1));
53 } 54 }
54 55
55 @reflectiveTest 56 @reflectiveTest
56 class AnalysisDriverSchedulerTest { 57 class AnalysisDriverSchedulerTest {
57 final MemoryResourceProvider provider = new MemoryResourceProvider(); 58 final MemoryResourceProvider provider = new MemoryResourceProvider();
59 DartSdk sdk;
58 final ByteStore byteStore = new MemoryByteStore(); 60 final ByteStore byteStore = new MemoryByteStore();
59 final FileContentOverlay contentOverlay = new FileContentOverlay(); 61 final FileContentOverlay contentOverlay = new FileContentOverlay();
60 62
61 final StringBuffer logBuffer = new StringBuffer(); 63 final StringBuffer logBuffer = new StringBuffer();
62 PerformanceLog logger; 64 PerformanceLog logger;
63 65
64 AnalysisDriverScheduler scheduler; 66 AnalysisDriverScheduler scheduler;
65 67
66 List<AnalysisResult> allResults = []; 68 List<AnalysisResult> allResults = [];
67 69
68 AnalysisDriver newDriver() { 70 AnalysisDriver newDriver() {
69 AnalysisDriver driver = new AnalysisDriver( 71 AnalysisDriver driver = new AnalysisDriver(
70 scheduler, 72 scheduler,
71 logger, 73 logger,
72 provider, 74 provider,
73 byteStore, 75 byteStore,
74 contentOverlay, 76 contentOverlay,
75 'test', 77 'test',
76 new SourceFactory( 78 new SourceFactory(
77 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], 79 [new DartUriResolver(sdk), new ResourceUriResolver(provider)],
78 null, 80 null,
79 provider), 81 provider),
80 new AnalysisOptionsImpl()..strongMode = true); 82 new AnalysisOptionsImpl()..strongMode = true);
81 driver.results.forEach(allResults.add); 83 driver.results.forEach(allResults.add);
82 return driver; 84 return driver;
83 } 85 }
84 86
85 void setUp() { 87 void setUp() {
88 sdk = new MockSdk(resourceProvider: provider);
86 logger = new PerformanceLog(logBuffer); 89 logger = new PerformanceLog(logBuffer);
87 scheduler = new AnalysisDriverScheduler(logger); 90 scheduler = new AnalysisDriverScheduler(logger);
88 scheduler.start(); 91 scheduler.start();
89 } 92 }
90 93
91 test_priorities_getResult_beforePriority() async { 94 test_priorities_getResult_beforePriority() async {
92 AnalysisDriver driver1 = newDriver(); 95 AnalysisDriver driver1 = newDriver();
93 AnalysisDriver driver2 = newDriver(); 96 AnalysisDriver driver2 = newDriver();
94 97
95 String a = _p('/a.dart'); 98 String a = _p('/a.dart');
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 1824
1822 /** 1825 /**
1823 * Return the [provider] specific path for the given Posix [path]. 1826 * Return the [provider] specific path for the given Posix [path].
1824 */ 1827 */
1825 String _p(String path) => provider.convertPath(path); 1828 String _p(String path) => provider.convertPath(path);
1826 1829
1827 static String _md5(String content) { 1830 static String _md5(String content) {
1828 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 1831 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
1829 } 1832 }
1830 } 1833 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/analysis/base.dart ('k') | pkg/analyzer/test/src/dart/analysis/physical_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698