| 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); | |
| 91 options | 88 options |
| 92 ..verify = true | 89 ..verify = true |
| 93 ..fileSystem = new HybridFileSystem(fs) | 90 ..fileSystem = new HybridFileSystem(fs) |
| 94 ..inputSummaries = inputSummaries.map(toTestUri).toList() | 91 ..inputSummaries = inputSummaries.map(toTestUri).toList() |
| 95 ..linkedDependencies = linkedDependencies.map(toTestUri).toList() | 92 ..linkedDependencies = linkedDependencies.map(toTestUri).toList() |
| 96 ..packagesFileUri = toTestUri('.packages'); | 93 ..packagesFileUri = toTestUri('.packages'); |
| 97 | 94 |
| 98 if (options.sdkSummary == null) { | 95 if (options.sdkSummary == null) { |
| 99 options.sdkRoot = await computePatchedSdk(); | 96 options.sdkRoot = await computePatchedSdk(); |
| 100 } | 97 } |
| 101 } | 98 } |
| 102 | 99 |
| 103 /// A fake absolute directory used as the root of a memory-file system in the | 100 /// A fake absolute directory used as the root of a memory-file system in the |
| 104 /// helpers above. | 101 /// helpers above. |
| 105 Uri _defaultDir = Uri.parse('file:///a/b/c/'); | 102 Uri _defaultDir = Uri.parse('file:///a/b/c/'); |
| 106 | 103 |
| 107 /// Convert relative file paths into an absolute Uri as expected by the test | 104 /// Convert relative file paths into an absolute Uri as expected by the test |
| 108 /// helpers above. | 105 /// helpers above. |
| 109 Uri toTestUri(String relativePath) => _defaultDir.resolve(relativePath); | 106 Uri toTestUri(String relativePath) => _defaultDir.resolve(relativePath); |
| 110 | 107 |
| 111 /// Uri to a libraries specification file that purposely provides | 108 /// A map defining the location of core libraries that purposely provides |
| 112 /// invalid Uris to dart:core and dart:async. Used by tests that want to ensure | 109 /// invalid Uris. Used by tests that want to ensure that the sdk libraries are |
| 113 /// that the sdk libraries are not loaded from sources, but read from a .dill | 110 /// not loaded from sources, but read from a .dill file. |
| 114 /// file. | 111 Map<String, Uri> invalidCoreLibs = { |
| 115 Uri invalidCoreLibsSpecUri = toTestUri('invalid_sdk_libraries.json'); | 112 'core': Uri.parse('file:///non_existing_file/core.dart'), |
| 116 | 113 'async': Uri.parse('file:///non_existing_file/async.dart'), |
| 117 String _invalidLibrariesSpec = ''' | 114 }; |
| 118 { | |
| 119 "vm": { | |
| 120 "libraries": { | |
| 121 "core": {"uri": "/non_existing_file/core.dart"}, | |
| 122 "async": {"uri": "/non_existing_file/async.dart"} | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 '''; | |
| 127 | 115 |
| 128 bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); | 116 bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); |
| 129 bool isDartCore(Uri uri) => uri.scheme == 'dart' && uri.path == 'core'; | 117 bool isDartCore(Uri uri) => uri.scheme == 'dart' && uri.path == 'core'; |
| 130 | 118 |
| 131 /// Find a library in [program] whose Uri ends with the given [suffix] | 119 /// Find a library in [program] whose Uri ends with the given [suffix] |
| 132 Library findLibrary(Program program, String suffix) { | 120 Library findLibrary(Program program, String suffix) { |
| 133 return program.libraries | 121 return program.libraries |
| 134 .firstWhere((lib) => lib.importUri.path.endsWith(suffix)); | 122 .firstWhere((lib) => lib.importUri.path.endsWith(suffix)); |
| 135 } | 123 } |
| OLD | NEW |