| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library descriptor_test; | 5 library descriptor_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 }); | 981 }); |
| 982 | 982 |
| 983 expectTestsPass("async().read() fails", () { | 983 expectTestsPass("async().read() fails", () { |
| 984 test('test', () { | 984 test('test', () { |
| 985 scheduleSandbox(); | 985 scheduleSandbox(); |
| 986 | 986 |
| 987 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), | 987 expect(d.async(new Future.immediate(d.file('name.txt'))).read().toList(), |
| 988 throwsA(equals("Async descriptors don't support read()."))); | 988 throwsA(equals("Async descriptors don't support read()."))); |
| 989 }); | 989 }); |
| 990 }); | 990 }); |
| 991 |
| 992 expectTestsPass("nothing().create() does nothing", () { |
| 993 test('test', () { |
| 994 scheduleSandbox(); |
| 995 |
| 996 d.nothing('foo').create(); |
| 997 |
| 998 schedule(() { |
| 999 expect(new File(path.join(sandbox, 'foo')).exists(), |
| 1000 completion(isFalse)); |
| 1001 }); |
| 1002 |
| 1003 schedule(() { |
| 1004 expect(new Directory(path.join(sandbox, 'foo')).exists(), |
| 1005 completion(isFalse)); |
| 1006 }); |
| 1007 }); |
| 1008 }); |
| 1009 |
| 1010 expectTestsPass("nothing().validate() succeeds if nothing's there", () { |
| 1011 test('test', () { |
| 1012 scheduleSandbox(); |
| 1013 |
| 1014 d.nothing('foo').validate(); |
| 1015 }); |
| 1016 }); |
| 1017 |
| 1018 expectTestsPass("nothing().validate() with a RegExp succeeds if nothing's " |
| 1019 "there", () { |
| 1020 test('test', () { |
| 1021 scheduleSandbox(); |
| 1022 |
| 1023 d.nothing(new RegExp('f.o')).validate(); |
| 1024 }); |
| 1025 }); |
| 1026 |
| 1027 expectTestsPass("nothing().validate() fails if there's a file", () { |
| 1028 var errors; |
| 1029 test('test 1', () { |
| 1030 scheduleSandbox(); |
| 1031 |
| 1032 currentSchedule.onException.schedule(() { |
| 1033 errors = currentSchedule.errors; |
| 1034 }); |
| 1035 |
| 1036 d.file('name.txt', 'contents').create(); |
| 1037 d.nothing('name.txt').validate(); |
| 1038 }); |
| 1039 |
| 1040 test('test 2', () { |
| 1041 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 1042 expect(errors.length, equals(1)); |
| 1043 expect(errors.first.error, |
| 1044 matches(r"^Expected nothing to exist at '[^']+[\\/]name.txt', but " |
| 1045 r"found a file\.$")); |
| 1046 }); |
| 1047 }, passing: ['test 2']); |
| 1048 |
| 1049 expectTestsPass("nothing().validate() fails if there's a directory", () { |
| 1050 var errors; |
| 1051 test('test 1', () { |
| 1052 scheduleSandbox(); |
| 1053 |
| 1054 currentSchedule.onException.schedule(() { |
| 1055 errors = currentSchedule.errors; |
| 1056 }); |
| 1057 |
| 1058 d.dir('dir').create(); |
| 1059 d.nothing('dir').validate(); |
| 1060 }); |
| 1061 |
| 1062 test('test 2', () { |
| 1063 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 1064 expect(errors.length, equals(1)); |
| 1065 expect(errors.first.error, |
| 1066 matches(r"^Expected nothing to exist at '[^']+[\\/]dir', but found a " |
| 1067 r"directory\.$")); |
| 1068 }); |
| 1069 }, passing: ['test 2']); |
| 1070 |
| 1071 expectTestsPass("nothing().validate() with a RegExp fails if there are " |
| 1072 "multiple entries", () { |
| 1073 var errors; |
| 1074 test('test 1', () { |
| 1075 scheduleSandbox(); |
| 1076 |
| 1077 currentSchedule.onException.schedule(() { |
| 1078 errors = currentSchedule.errors; |
| 1079 }); |
| 1080 |
| 1081 d.dir('foo').create(); |
| 1082 d.file('faa', 'contents').create(); |
| 1083 d.file('not-foo', 'contents').create(); |
| 1084 d.nothing(new RegExp(r'^f..$')).validate(); |
| 1085 }); |
| 1086 |
| 1087 test('test 2', () { |
| 1088 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); |
| 1089 expect(errors.length, equals(1)); |
| 1090 expect(errors.first.error, |
| 1091 matches(r"^Expected nothing to exist in '[^']+' matching " |
| 1092 r"/\^f\.\.\$/, but found:\n" |
| 1093 r"\* .*[\\/]faa\n" |
| 1094 r"\* .*[\\/]foo$")); |
| 1095 }); |
| 1096 }, passing: ['test 2']); |
| 1097 |
| 1098 expectTestsPass("nothing().load() fails", () { |
| 1099 test('test', () { |
| 1100 scheduleSandbox(); |
| 1101 |
| 1102 expect(d.nothing('name.txt').load('path').toList(), |
| 1103 throwsA(equals("Nothing descriptors don't support load()."))); |
| 1104 }); |
| 1105 }); |
| 1106 |
| 1107 expectTestsPass("nothing().read() fails", () { |
| 1108 test('test', () { |
| 1109 scheduleSandbox(); |
| 1110 |
| 1111 expect(d.nothing('name.txt').read().toList(), |
| 1112 throwsA(equals("Nothing descriptors don't support read()."))); |
| 1113 }); |
| 1114 }); |
| 991 } | 1115 } |
| 992 | 1116 |
| 993 void scheduleSandbox() { | 1117 void scheduleSandbox() { |
| 994 schedule(() { | 1118 schedule(() { |
| 995 return new Directory('').createTemp().then((dir) { | 1119 return new Directory('').createTemp().then((dir) { |
| 996 sandbox = dir.path; | 1120 sandbox = dir.path; |
| 997 d.defaultRoot = sandbox; | 1121 d.defaultRoot = sandbox; |
| 998 }); | 1122 }); |
| 999 }); | 1123 }); |
| 1000 | 1124 |
| 1001 currentSchedule.onComplete.schedule(() { | 1125 currentSchedule.onComplete.schedule(() { |
| 1002 d.defaultRoot = null; | 1126 d.defaultRoot = null; |
| 1003 if (sandbox == null) return; | 1127 if (sandbox == null) return; |
| 1004 var oldSandbox = sandbox; | 1128 var oldSandbox = sandbox; |
| 1005 sandbox = null; | 1129 sandbox = null; |
| 1006 return new Directory(oldSandbox).delete(recursive: true); | 1130 return new Directory(oldSandbox).delete(recursive: true); |
| 1007 }); | 1131 }); |
| 1008 } | 1132 } |
| 1009 | 1133 |
| 1010 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { | 1134 Future<List<int>> byteStreamToList(Stream<List<int>> stream) { |
| 1011 return stream.reduce(<int>[], (buffer, chunk) { | 1135 return stream.reduce(<int>[], (buffer, chunk) { |
| 1012 buffer.addAll(chunk); | 1136 buffer.addAll(chunk); |
| 1013 return buffer; | 1137 return buffer; |
| 1014 }); | 1138 }); |
| 1015 } | 1139 } |
| 1016 | 1140 |
| 1017 Future<String> byteStreamToString(Stream<List<int>> stream) => | 1141 Future<String> byteStreamToString(Stream<List<int>> stream) => |
| 1018 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); | 1142 byteStreamToList(stream).then((bytes) => new String.fromCharCodes(bytes)); |
| OLD | NEW |