| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 import "dart:isolate"; | 7 import "dart:isolate"; |
| 8 | 8 |
| 9 void testFailingList(Directory d, var recursive) { | 9 void testFailingList(Directory d, var recursive) { |
| 10 var port = new ReceivePort(); | 10 var port = new ReceivePort(); |
| 11 int errors = 0; | 11 int errors = 0; |
| 12 d.list(recursive: recursive).listen( | 12 d.list(recursive: recursive).listen( |
| 13 () => Expect.fail("Unexpected listing result"), | 13 () => Expect.fail("Unexpected listing result"), |
| 14 onError: (error) { | 14 onError: (error) { |
| 15 errors += 1; | 15 errors += 1; |
| 16 }, | 16 }, |
| 17 onDone: () { | 17 onDone: () { |
| 18 port.close(); | 18 port.close(); |
| 19 Expect.equals(1, errors); | 19 Expect.equals(1, errors); |
| 20 }); | 20 }); |
| 21 Expect.equals(0, errors); | 21 Expect.equals(0, errors); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void testInvalidArguments() { | 24 void testInvalidArguments() { |
| 25 Directory d = new Directory(12); | |
| 26 try { | 25 try { |
| 27 d.existsSync(); | 26 Directory d = new Directory(12); |
| 28 Expect.fail("No exception thrown"); | 27 Expect.fail("No exception thrown"); |
| 29 } catch (e) { | 28 } catch (e) { |
| 30 Expect.isTrue(e is ArgumentError); | 29 Expect.isTrue(e is ArgumentError); |
| 31 } | 30 } |
| 32 try { | 31 Directory d = new Directory("."); |
| 33 d.deleteSync(); | |
| 34 Expect.fail("No exception thrown"); | |
| 35 } catch (e) { | |
| 36 Expect.isTrue(e is ArgumentError); | |
| 37 } | |
| 38 try { | |
| 39 d.createSync(); | |
| 40 Expect.fail("No exception thrown"); | |
| 41 } catch (e) { | |
| 42 Expect.isTrue(e is ArgumentError); | |
| 43 } | |
| 44 testFailingList(d, false); | |
| 45 Expect.throws(() => d.listSync(recursive: true), | |
| 46 (e) => e is ArgumentError); | |
| 47 d = new Directory("."); | |
| 48 testFailingList(d, 1); | 32 testFailingList(d, 1); |
| 49 Expect.throws(() => d.listSync(recursive: 1), | 33 Expect.throws(() => d.listSync(recursive: 1), |
| 50 (e) => e is ArgumentError); | 34 (e) => e is ArgumentError); |
| 51 } | 35 } |
| 52 | 36 |
| 53 main() { | 37 main() { |
| 54 testInvalidArguments(); | 38 testInvalidArguments(); |
| 55 } | 39 } |
| OLD | NEW |