| 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as path; | 7 import 'package:path/path.dart' as path; |
| 8 import 'package:scheduled_test/descriptor.dart' as d; | 8 import 'package:scheduled_test/descriptor.dart' as d; |
| 9 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 schedule(() { | 69 schedule(() { |
| 70 return new File(path.join(sandbox, 'name.txt')) | 70 return new File(path.join(sandbox, 'name.txt')) |
| 71 .writeAsString('wrongtents'); | 71 .writeAsString('wrongtents'); |
| 72 }); | 72 }); |
| 73 | 73 |
| 74 d.file('name.txt', 'contents').validate(); | 74 d.file('name.txt', 'contents').validate(); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 test('test 2', () { | 77 test('test 2', () { |
| 78 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 78 expect(errors.single, new isInstanceOf<ScheduleError>()); |
| 79 expect(errors.map((e) => e.error), equals([ | 79 expect(errors.single.error.toString(), equals( |
| 80 "File 'name.txt' should contain:\n" | 80 "File 'name.txt' should contain:\n" |
| 81 "| contents\n" | 81 "| contents\n" |
| 82 "but actually contained:\n" | 82 "but actually contained:\n" |
| 83 "X wrongtents" | 83 "X wrongtents")); |
| 84 ]), verbose: true); | |
| 85 }); | 84 }); |
| 86 }, passing: ['test 2']); | 85 }, passing: ['test 2']); |
| 87 | 86 |
| 88 expectTestsPass("file().validate() fails if there's no file", () { | 87 expectTestsPass("file().validate() fails if there's no file", () { |
| 89 var errors; | 88 var errors; |
| 90 test('test 1', () { | 89 test('test 1', () { |
| 91 scheduleSandbox(); | 90 scheduleSandbox(); |
| 92 | 91 |
| 93 currentSchedule.onException.schedule(() { | 92 currentSchedule.onException.schedule(() { |
| 94 errors = currentSchedule.errors; | 93 errors = currentSchedule.errors; |
| 95 }); | 94 }); |
| 96 | 95 |
| 97 d.file('name.txt', 'contents').validate(); | 96 d.file('name.txt', 'contents').validate(); |
| 98 }); | 97 }); |
| 99 | 98 |
| 100 test('test 2', () { | 99 test('test 2', () { |
| 101 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 100 expect(errors.single, new isInstanceOf<ScheduleError>()); |
| 102 expect(errors.length, equals(1)); | 101 expect(errors.single.error.toString(), |
| 103 expect(errors.first.error, | |
| 104 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); | 102 matches(r"^File not found: '[^']+[\\/]name\.txt'\.$")); |
| 105 }); | 103 }); |
| 106 }, passing: ['test 2']); | 104 }, passing: ['test 2']); |
| 107 | 105 |
| 108 expectTestsPass("file().read() returns the contents of the file as a stream", | 106 expectTestsPass("file().read() returns the contents of the file as a stream", |
| 109 () { | 107 () { |
| 110 test('test', () { | 108 test('test', () { |
| 111 expect(byteStreamToString(d.file('name.txt', 'contents').read()), | 109 expect(byteStreamToString(d.file('name.txt', 'contents').read()), |
| 112 completion(equals('contents'))); | 110 completion(equals('contents'))); |
| 113 }); | 111 }); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 156 |
| 159 schedule(() { | 157 schedule(() { |
| 160 return new File(path.join(sandbox, 'name.bin')) | 158 return new File(path.join(sandbox, 'name.bin')) |
| 161 .writeAsBytes([2, 4, 6, 8, 10]); | 159 .writeAsBytes([2, 4, 6, 8, 10]); |
| 162 }); | 160 }); |
| 163 | 161 |
| 164 d.binaryFile('name.bin', [1, 2, 3, 4, 5]).validate(); | 162 d.binaryFile('name.bin', [1, 2, 3, 4, 5]).validate(); |
| 165 }); | 163 }); |
| 166 | 164 |
| 167 test('test 2', () { | 165 test('test 2', () { |
| 168 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 166 expect(errors.single, new isInstanceOf<ScheduleError>()); |
| 169 expect(errors.map((e) => e.error), equals([ | 167 expect(errors.single.error.toString(), equals( |
| 170 "File 'name.bin' didn't contain the expected binary data." | 168 "File 'name.bin' didn't contain the expected binary data.")); |
| 171 ]), verbose: true); | |
| 172 }); | 169 }); |
| 173 }, passing: ['test 2']); | 170 }, passing: ['test 2']); |
| 174 | 171 |
| 175 expectTestsPass('matcherFile().create() creates an empty file', () { | 172 expectTestsPass('matcherFile().create() creates an empty file', () { |
| 176 test('test', () { | 173 test('test', () { |
| 177 scheduleSandbox(); | 174 scheduleSandbox(); |
| 178 | 175 |
| 179 d.matcherFile('name.txt', isNot(isEmpty)).create(); | 176 d.matcherFile('name.txt', isNot(isEmpty)).create(); |
| 180 | 177 |
| 181 schedule(() { | 178 schedule(() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 211 | 208 |
| 212 schedule(() { | 209 schedule(() { |
| 213 return new File(path.join(sandbox, 'name.txt')) | 210 return new File(path.join(sandbox, 'name.txt')) |
| 214 .writeAsString('barfoobaz'); | 211 .writeAsString('barfoobaz'); |
| 215 }); | 212 }); |
| 216 | 213 |
| 217 d.matcherFile('name.txt', contains('baaz')).validate(); | 214 d.matcherFile('name.txt', contains('baaz')).validate(); |
| 218 }); | 215 }); |
| 219 | 216 |
| 220 test('test 2', () { | 217 test('test 2', () { |
| 221 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 218 expect(errors.single, new isInstanceOf<ScheduleError>()); |
| 222 expect(errors.map((e) => e.error.message), equals([ | 219 expect(errors.single.error.toString(), equals( |
| 223 "Expected: contains 'baaz'\n" | 220 "Expected: contains 'baaz'\n" |
| 224 " Actual: 'barfoobaz'\n" | 221 " Actual: 'barfoobaz'\n")); |
| 225 ]), verbose: true); | |
| 226 }); | 222 }); |
| 227 }, passing: ['test 2']); | 223 }, passing: ['test 2']); |
| 228 | 224 |
| 229 expectTestsPass('binaryMatcherFile().validate() completes successfully if ' | 225 expectTestsPass('binaryMatcherFile().validate() completes successfully if ' |
| 230 'the string contents of the file matches the matcher', () { | 226 'the string contents of the file matches the matcher', () { |
| 231 test('test', () { | 227 test('test', () { |
| 232 scheduleSandbox(); | 228 scheduleSandbox(); |
| 233 | 229 |
| 234 schedule(() { | 230 schedule(() { |
| 235 return new File(path.join(sandbox, 'name.txt')) | 231 return new File(path.join(sandbox, 'name.txt')) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 252 | 248 |
| 253 schedule(() { | 249 schedule(() { |
| 254 return new File(path.join(sandbox, 'name.txt')) | 250 return new File(path.join(sandbox, 'name.txt')) |
| 255 .writeAsString('barfoobaz'); | 251 .writeAsString('barfoobaz'); |
| 256 }); | 252 }); |
| 257 | 253 |
| 258 d.binaryMatcherFile('name.txt', contains(12)).validate(); | 254 d.binaryMatcherFile('name.txt', contains(12)).validate(); |
| 259 }); | 255 }); |
| 260 | 256 |
| 261 test('test 2', () { | 257 test('test 2', () { |
| 262 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); | 258 expect(errors.single, new isInstanceOf<ScheduleError>()); |
| 263 expect(errors.map((e) => e.error.message), equals([ | 259 expect(errors.single.error.toString(), equals( |
| 264 "Expected: contains <12>\n" | 260 "Expected: contains <12>\n" |
| 265 " Actual: [98, 97, 114, 102, 111, 111, 98, 97, 122]\n" | 261 " Actual: [98, 97, 114, 102, 111, 111, 98, 97, 122]\n")); |
| 266 ]), verbose: true); | |
| 267 }); | 262 }); |
| 268 }, passing: ['test 2']); | 263 }, passing: ['test 2']); |
| 269 } | 264 } |
| OLD | NEW |