| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub | 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub |
| 7 * tests are integration tests that stage some stuff on the file system, run | 7 * tests are integration tests that stage some stuff on the file system, run |
| 8 * pub, and then validate the results. This library provides an API to build | 8 * pub, and then validate the results. This library provides an API to build |
| 9 * tests like that. | 9 * tests like that. |
| 10 */ | 10 */ |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 Expect.fail('File $file should contain:\n\n$contents\n\n' | 865 Expect.fail('File $file should contain:\n\n$contents\n\n' |
| 866 'but contained:\n\n$text'); | 866 'but contained:\n\n$text'); |
| 867 }); | 867 }); |
| 868 }); | 868 }); |
| 869 } | 869 } |
| 870 | 870 |
| 871 /** | 871 /** |
| 872 * Loads the contents of the file. | 872 * Loads the contents of the file. |
| 873 */ | 873 */ |
| 874 InputStream load(List<String> path) { | 874 InputStream load(List<String> path) { |
| 875 if (!path.isEmpty()) { | 875 if (!path.isEmpty) { |
| 876 var joinedPath = Strings.join(path, '/'); | 876 var joinedPath = Strings.join(path, '/'); |
| 877 throw "Can't load $joinedPath from within $name: not a directory."; | 877 throw "Can't load $joinedPath from within $name: not a directory."; |
| 878 } | 878 } |
| 879 | 879 |
| 880 var stream = new ListInputStream(); | 880 var stream = new ListInputStream(); |
| 881 stream.write(contents.charCodes()); | 881 stream.write(contents.charCodes()); |
| 882 stream.markEndOfStream(); | 882 stream.markEndOfStream(); |
| 883 return stream; | 883 return stream; |
| 884 } | 884 } |
| 885 } | 885 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 | 936 |
| 937 // If they are all valid, the directory is valid. | 937 // If they are all valid, the directory is valid. |
| 938 return Futures.wait(entryFutures).transform((entries) => null); | 938 return Futures.wait(entryFutures).transform((entries) => null); |
| 939 }); | 939 }); |
| 940 } | 940 } |
| 941 | 941 |
| 942 /** | 942 /** |
| 943 * Loads [path] from within this directory. | 943 * Loads [path] from within this directory. |
| 944 */ | 944 */ |
| 945 InputStream load(List<String> path) { | 945 InputStream load(List<String> path) { |
| 946 if (path.isEmpty()) { | 946 if (path.isEmpty) { |
| 947 throw "Can't load the contents of $name: is a directory."; | 947 throw "Can't load the contents of $name: is a directory."; |
| 948 } | 948 } |
| 949 | 949 |
| 950 for (var descriptor in contents) { | 950 for (var descriptor in contents) { |
| 951 if (descriptor.name == path[0]) { | 951 if (descriptor.name == path[0]) { |
| 952 return descriptor.load(path.getRange(1, path.length - 1)); | 952 return descriptor.load(path.getRange(1, path.length - 1)); |
| 953 } | 953 } |
| 954 } | 954 } |
| 955 | 955 |
| 956 throw "Directory $name doesn't contain ${Strings.join(path, '/')}."; | 956 throw "Directory $name doesn't contain ${Strings.join(path, '/')}."; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 Future delete(dir) { | 1118 Future delete(dir) { |
| 1119 throw new UnsupportedError(''); | 1119 throw new UnsupportedError(''); |
| 1120 } | 1120 } |
| 1121 | 1121 |
| 1122 /** | 1122 /** |
| 1123 * Loads the contents of this tar file. | 1123 * Loads the contents of this tar file. |
| 1124 */ | 1124 */ |
| 1125 InputStream load(List<String> path) { | 1125 InputStream load(List<String> path) { |
| 1126 if (!path.isEmpty()) { | 1126 if (!path.isEmpty) { |
| 1127 var joinedPath = Strings.join(path, '/'); | 1127 var joinedPath = Strings.join(path, '/'); |
| 1128 throw "Can't load $joinedPath from within $name: not a directory."; | 1128 throw "Can't load $joinedPath from within $name: not a directory."; |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 var sinkStream = new ListInputStream(); | 1131 var sinkStream = new ListInputStream(); |
| 1132 var tempDir; | 1132 var tempDir; |
| 1133 // TODO(nweiz): propagate any errors to the return value. See issue 3657. | 1133 // TODO(nweiz): propagate any errors to the return value. See issue 3657. |
| 1134 createTempDir().chain((_tempDir) { | 1134 createTempDir().chain((_tempDir) { |
| 1135 tempDir = _tempDir; | 1135 tempDir = _tempDir; |
| 1136 return create(tempDir); | 1136 return create(tempDir); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1151 Future create(dir) => new Future.immediate(null); | 1151 Future create(dir) => new Future.immediate(null); |
| 1152 Future delete(dir) => new Future.immediate(null); | 1152 Future delete(dir) => new Future.immediate(null); |
| 1153 | 1153 |
| 1154 Future validate(String dir) { | 1154 Future validate(String dir) { |
| 1155 return exists(join(dir, name)).transform((exists) { | 1155 return exists(join(dir, name)).transform((exists) { |
| 1156 if (exists) Expect.fail('File $name in $dir should not exist.'); | 1156 if (exists) Expect.fail('File $name in $dir should not exist.'); |
| 1157 }); | 1157 }); |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 InputStream load(List<String> path) { | 1160 InputStream load(List<String> path) { |
| 1161 if (path.isEmpty()) { | 1161 if (path.isEmpty) { |
| 1162 throw "Can't load the contents of $name: it doesn't exist."; | 1162 throw "Can't load the contents of $name: it doesn't exist."; |
| 1163 } else { | 1163 } else { |
| 1164 throw "Can't load ${Strings.join(path, '/')} from within $name: $name " | 1164 throw "Can't load ${Strings.join(path, '/')} from within $name: $name " |
| 1165 "doesn't exist."; | 1165 "doesn't exist."; |
| 1166 } | 1166 } |
| 1167 } | 1167 } |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 /** | 1170 /** |
| 1171 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, | 1171 * Takes a simple data structure (composed of [Map]s, [List]s, scalar objects, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 /** | 1203 /** |
| 1204 * Schedules a callback to be called after Pub is run with [runPub], even if it | 1204 * Schedules a callback to be called after Pub is run with [runPub], even if it |
| 1205 * fails. | 1205 * fails. |
| 1206 */ | 1206 */ |
| 1207 void _scheduleCleanup(_ScheduledEvent event) { | 1207 void _scheduleCleanup(_ScheduledEvent event) { |
| 1208 if (_scheduledCleanup == null) _scheduledCleanup = []; | 1208 if (_scheduledCleanup == null) _scheduledCleanup = []; |
| 1209 _scheduledCleanup.add(event); | 1209 _scheduledCleanup.add(event); |
| 1210 } | 1210 } |
| OLD | NEW |