| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, 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.descriptor.utils; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'package:scheduled_test/descriptor.dart' as d; | |
| 11 import 'package:scheduled_test/scheduled_test.dart'; | |
| 12 | |
| 13 export '../utils.dart'; | |
| 14 | |
| 15 String sandbox; | |
| 16 | |
| 17 void scheduleSandbox() { | |
| 18 schedule(() { | |
| 19 return Directory.systemTemp.createTemp('descriptor_sandbox_').then((dir) { | |
| 20 sandbox = dir.path; | |
| 21 d.defaultRoot = sandbox; | |
| 22 }); | |
| 23 }); | |
| 24 | |
| 25 currentSchedule.onComplete.schedule(() { | |
| 26 d.defaultRoot = null; | |
| 27 if (sandbox == null) return null; | |
| 28 var oldSandbox = sandbox; | |
| 29 sandbox = null; | |
| 30 return new Directory(oldSandbox).delete(recursive: true); | |
| 31 }); | |
| 32 } | |
| 33 | |
| 34 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { | |
| 35 return stream.fold(<int>[], (buffer, chunk) { | |
| 36 buffer.addAll(chunk); | |
| 37 return buffer; | |
| 38 }); | |
| 39 } | |
| 40 | |
| 41 Future<String> byteStreamToString(Stream<List<int>> stream) => | |
| 42 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); | |
| 43 | |
| 44 Matcher isDirectoryDescriptor(String name, List contents) { | |
| 45 return predicate((object) { | |
| 46 try { | |
| 47 expect(object, new isInstanceOf<d.DirectoryDescriptor>()); | |
| 48 expect(object.name, equals(name)); | |
| 49 expect(object.contents, unorderedMatches(contents)); | |
| 50 return true; | |
| 51 } on TestFailure catch (_) { | |
| 52 return false; | |
| 53 } | |
| 54 }, "a directory descriptor named $name containing $contents"); | |
| 55 } | |
| 56 | |
| 57 Matcher isFileDescriptor(String name, contents) { | |
| 58 return predicate((object) { | |
| 59 try { | |
| 60 expect(object, new isInstanceOf<d.FileDescriptor>()); | |
| 61 expect(object.name, equals(name)); | |
| 62 expect(object.textContents, contents); | |
| 63 return true; | |
| 64 } on TestFailure catch (_) { | |
| 65 return false; | |
| 66 } | |
| 67 }, "a file descriptor named $name containing $contents"); | |
| 68 } | |
| 69 | |
| OLD | NEW |