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

Unified Diff: lib/src/testing.dart

Issue 1001563003: Fix in multi-package-resolver to support files that will be created later (graph (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/dependency_graph.dart ('k') | test/dependency_graph_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/testing.dart
diff --git a/lib/src/testing.dart b/lib/src/testing.dart
index 5bee83ed545c8b54ff982d850485af61c6bb2dff..bd1d21b8ce328e9c919039bd344c61e4c6e37566 100644
--- a/lib/src/testing.dart
+++ b/lib/src/testing.dart
@@ -269,7 +269,13 @@ class _ErrorExpectation {
class TestUriResolver extends UriResolver {
final Map<Uri, TestSource> files = <Uri, TestSource>{};
- TestUriResolver(Map<String, String> allFiles) {
+ /// Whether to represent a non-existing file with a [TestSource] (default
+ /// behavior from analyzer), or to use null (possible when overriding the
+ /// package-url-resolvers.)
+ final bool representNonExistingFiles;
+
+ TestUriResolver(Map<String, String> allFiles,
+ {this.representNonExistingFiles: true}) {
allFiles.forEach((key, value) {
var uri = key.startsWith('package:') ? Uri.parse(key) : new Uri.file(key);
files[uri] = new TestSource(uri, value);
@@ -278,6 +284,7 @@ class TestUriResolver extends UriResolver {
Source resolveAbsolute(Uri uri) {
if (uri.scheme != 'file' && uri.scheme != 'package') return null;
+ if (!representNonExistingFiles) return files[uri];
return files.putIfAbsent(uri, () => new TestSource(uri, null));
}
}
@@ -295,16 +302,14 @@ class TestSource implements Source {
TestContents contents;
final SourceFile _file;
final UriKind uriKind;
- bool _exists;
TestSource(uri, contents)
: uri = uri,
- _exists = contents != null,
contents = new TestContents(1, contents),
_file = contents != null ? new SourceFile(contents, url: uri) : null,
uriKind = uri.scheme == 'file' ? UriKind.FILE_URI : UriKind.PACKAGE_URI;
- bool exists() => _exists;
+ bool exists() => contents.data != null;
Source get source => this;
« no previous file with comments | « lib/src/dependency_graph.dart ('k') | test/dependency_graph_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698