OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// Common compiler options and helper functions used for testing. | 5 /// Common compiler options and helper functions used for testing. |
6 library front_end.testing.compiler_options_common; | 6 library front_end.testing.compiler_options_common; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:front_end/front_end.dart'; | 10 import 'package:front_end/front_end.dart'; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 var fs = new MemoryFileSystem(_defaultDir); | 78 var fs = new MemoryFileSystem(_defaultDir); |
79 sources.forEach((name, data) { | 79 sources.forEach((name, data) { |
80 var entity = fs.entityForUri(toTestUri(name)); | 80 var entity = fs.entityForUri(toTestUri(name)); |
81 if (data is String) { | 81 if (data is String) { |
82 entity.writeAsStringSync(data); | 82 entity.writeAsStringSync(data); |
83 } else { | 83 } else { |
84 entity.writeAsBytesSync(data); | 84 entity.writeAsBytesSync(data); |
85 } | 85 } |
86 }); | 86 }); |
87 fs.entityForUri(toTestUri('.packages')).writeAsStringSync(''); | 87 fs.entityForUri(toTestUri('.packages')).writeAsStringSync(''); |
| 88 fs |
| 89 .entityForUri(invalidCoreLibsSpecUri) |
| 90 .writeAsStringSync(_invalidLibrariesSpec); |
88 options | 91 options |
89 ..verify = true | 92 ..verify = true |
90 ..fileSystem = new HybridFileSystem(fs) | 93 ..fileSystem = new HybridFileSystem(fs) |
91 ..inputSummaries = inputSummaries.map(toTestUri).toList() | 94 ..inputSummaries = inputSummaries.map(toTestUri).toList() |
92 ..linkedDependencies = linkedDependencies.map(toTestUri).toList() | 95 ..linkedDependencies = linkedDependencies.map(toTestUri).toList() |
93 ..packagesFileUri = toTestUri('.packages'); | 96 ..packagesFileUri = toTestUri('.packages'); |
94 | 97 |
95 if (options.sdkSummary == null) { | 98 if (options.sdkSummary == null) { |
96 options.sdkRoot = await computePatchedSdk(); | 99 options.sdkRoot = await computePatchedSdk(); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 /// A fake absolute directory used as the root of a memory-file system in the | 103 /// A fake absolute directory used as the root of a memory-file system in the |
101 /// helpers above. | 104 /// helpers above. |
102 Uri _defaultDir = Uri.parse('file:///a/b/c/'); | 105 Uri _defaultDir = Uri.parse('file:///a/b/c/'); |
103 | 106 |
104 /// Convert relative file paths into an absolute Uri as expected by the test | 107 /// Convert relative file paths into an absolute Uri as expected by the test |
105 /// helpers above. | 108 /// helpers above. |
106 Uri toTestUri(String relativePath) => _defaultDir.resolve(relativePath); | 109 Uri toTestUri(String relativePath) => _defaultDir.resolve(relativePath); |
107 | 110 |
108 /// A map defining the location of core libraries that purposely provides | 111 /// Uri to a libraries specification file that purposely provides |
109 /// invalid Uris. Used by tests that want to ensure that the sdk libraries are | 112 /// invalid Uris to dart:core and dart:async. Used by tests that want to ensure |
110 /// not loaded from sources, but read from a .dill file. | 113 /// that the sdk libraries are not loaded from sources, but read from a .dill |
111 Map<String, Uri> invalidCoreLibs = { | 114 /// file. |
112 'core': Uri.parse('file:///non_existing_file/core.dart'), | 115 Uri invalidCoreLibsSpecUri = toTestUri('invalid_sdk_libraries.json'); |
113 'async': Uri.parse('file:///non_existing_file/async.dart'), | 116 |
114 }; | 117 String _invalidLibrariesSpec = ''' |
| 118 { |
| 119 "vm": { |
| 120 "libraries": { |
| 121 "core": {"path": "/non_existing_file/core.dart"}, |
| 122 "async": {"path": "/non_existing_file/async.dart"} |
| 123 } |
| 124 } |
| 125 } |
| 126 '''; |
115 | 127 |
116 bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); | 128 bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); |
117 bool isDartCore(Uri uri) => uri.scheme == 'dart' && uri.path == 'core'; | 129 bool isDartCore(Uri uri) => uri.scheme == 'dart' && uri.path == 'core'; |
118 | 130 |
119 /// Find a library in [program] whose Uri ends with the given [suffix] | 131 /// Find a library in [program] whose Uri ends with the given [suffix] |
120 Library findLibrary(Program program, String suffix) { | 132 Library findLibrary(Program program, String suffix) { |
121 return program.libraries | 133 return program.libraries |
122 .firstWhere((lib) => lib.importUri.path.endsWith(suffix)); | 134 .firstWhere((lib) => lib.importUri.path.endsWith(suffix)); |
123 } | 135 } |
OLD | NEW |