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

Side by Side Diff: packages/analyzer/test/src/context/abstract_context.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.src.task.abstract_context_test;
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart'
13 hide AnalysisCache, AnalysisContextImpl, AnalysisTask;
14 import 'package:analyzer/src/generated/sdk.dart';
15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/task/driver.dart';
17 import 'package:analyzer/task/model.dart';
18 import 'package:unittest/unittest.dart';
19
20 import 'mock_sdk.dart';
21
22 class AbstractContextTest {
23 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
24
25 DartSdk sdk = new MockSdk();
26 SourceFactory sourceFactory;
27 AnalysisContextImpl context;
28 AnalysisCache analysisCache;
29 AnalysisDriver analysisDriver;
30
31 AnalysisTask task;
32 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs;
33 Map<ResultDescriptor<dynamic>, dynamic> outputs;
34
35 Source addSource(String path, String contents) {
36 Source source = newSource(path, contents);
37 ChangeSet changeSet = new ChangeSet();
38 changeSet.addedSource(source);
39 context.applyChanges(changeSet);
40 return source;
41 }
42
43 /**
44 * Assert that the given [elements] has the same number of items as the number
45 * of specified [names], and that for each specified name, a corresponding
46 * element can be found in the given collection with that name.
47 */
48 void assertNamedElements(List<Element> elements, List<String> names) {
49 for (String elemName in names) {
50 bool found = false;
51 for (Element elem in elements) {
52 if (elem.name == elemName) {
53 found = true;
54 break;
55 }
56 }
57 if (!found) {
58 StringBuffer buffer = new StringBuffer();
59 buffer.write("Expected element named: ");
60 buffer.write(elemName);
61 buffer.write("\n but found: ");
62 for (Element elem in elements) {
63 buffer.write(elem.name);
64 buffer.write(", ");
65 }
66 fail(buffer.toString());
67 }
68 }
69 expect(elements, hasLength(names.length));
70 }
71
72 /**
73 * Compute the given [result] for the given [target].
74 */
75 void computeResult(AnalysisTarget target, ResultDescriptor result,
76 {isInstanceOf matcher: null}) {
77 oldOutputs = outputs;
78 task = analysisDriver.computeResult(target, result);
79 if (matcher == null) {
80 expect(task, isNotNull);
81 } else {
82 expect(task, matcher);
83 }
84 expect(task.caughtException, isNull);
85 outputs = task.outputs;
86 for (ResultDescriptor descriptor in task.descriptor.results) {
87 expect(outputs, contains(descriptor));
88 }
89 }
90
91 AnalysisContextImpl createAnalysisContext() {
92 return new AnalysisContextImpl();
93 }
94
95 Source newSource(String path, [String content = '']) {
96 File file = resourceProvider.newFile(path, content);
97 return file.createSource();
98 }
99
100 List<Source> newSources(Map<String, String> sourceMap) {
101 List<Source> sources = <Source>[];
102 sourceMap.forEach((String path, String content) {
103 Source source = newSource(path, content);
104 sources.add(source);
105 });
106 return sources;
107 }
108
109 void prepareAnalysisContext([AnalysisOptions options]) {
110 sourceFactory = new SourceFactory(<UriResolver>[
111 new DartUriResolver(sdk),
112 new ResourceUriResolver(resourceProvider)
113 ]);
114 context = createAnalysisContext();
115 if (options != null) {
116 context.analysisOptions = options;
117 }
118 context.sourceFactory = sourceFactory;
119 analysisCache = context.analysisCache;
120 analysisDriver = context.driver;
121 }
122
123 void setUp() {
124 prepareAnalysisContext();
125 }
126
127 void tearDown() {}
128 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/source/test_all.dart ('k') | packages/analyzer/test/src/context/cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698