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 // Directory listing test that tests listSync on a missing directory. | 5 // Directory listing test that tests listSync on a missing directory. |
6 // | 6 // |
7 // TODO(7157): Merge this test into directory_test.dart testListNonExistent() | 7 // TODO(7157): Merge this test into directory_test.dart testListNonExistent() |
8 // when it no longer crashes on Windows, when issue 7157 is resolved. | 8 // when it no longer crashes on Windows, when issue 7157 is resolved. |
9 | 9 |
10 import "dart:io"; | 10 import "dart:io"; |
11 | 11 |
12 import "package:async_helper/async_helper.dart"; | 12 import "package:async_helper/async_helper.dart"; |
13 import "package:expect/expect.dart"; | 13 import "package:expect/expect.dart"; |
14 | 14 |
15 void testListNonExistent() { | 15 void testListNonExistent() { |
16 asyncStart(); | 16 asyncStart(); |
17 Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) { | 17 Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) { |
18 d.delete().then((ignore) { | 18 d.delete().then((ignore) { |
19 Expect.throws(() => d.listSync(), (e) => e is DirectoryException); | 19 Expect.throws(() => d.listSync(), (e) => e is FileSystemException); |
20 Expect.throws(() => d.listSync(recursive: true), | 20 Expect.throws(() => d.listSync(recursive: true), |
21 (e) => e is DirectoryException); | 21 (e) => e is FileSystemException); |
22 asyncEnd(); | 22 asyncEnd(); |
23 }); | 23 }); |
24 }); | 24 }); |
25 } | 25 } |
26 | 26 |
27 void testListTooLongName() { | 27 void testListTooLongName() { |
28 asyncStart(); | 28 asyncStart(); |
29 Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) { | 29 Directory.systemTemp.createTemp('dart_directory_list_nonexistent').then((d) { |
30 var subDirName = 'subdir'; | 30 var subDirName = 'subdir'; |
31 var subDir = new Directory("${d.path}/$subDirName"); | 31 var subDir = new Directory("${d.path}/$subDirName"); |
32 subDir.create().then((ignore) { | 32 subDir.create().then((ignore) { |
33 // Construct a long string of the form | 33 // Construct a long string of the form |
34 // 'tempdir/subdir/../subdir/../subdir'. | 34 // 'tempdir/subdir/../subdir/../subdir'. |
35 var buffer = new StringBuffer(); | 35 var buffer = new StringBuffer(); |
36 buffer.write(subDir.path); | 36 buffer.write(subDir.path); |
37 for (var i = 0; i < 1000; i++) { | 37 for (var i = 0; i < 1000; i++) { |
38 buffer.write("/../${subDirName}"); | 38 buffer.write("/../${subDirName}"); |
39 } | 39 } |
40 var long = new Directory("${buffer.toString()}"); | 40 var long = new Directory("${buffer.toString()}"); |
41 Expect.throws(() => long.listSync(), | 41 Expect.throws(() => long.listSync(), |
42 (e) => e is DirectoryException); | 42 (e) => e is FileSystemException); |
43 Expect.throws(() => long.listSync(recursive: true), | 43 Expect.throws(() => long.listSync(recursive: true), |
44 (e) => e is DirectoryException); | 44 (e) => e is FileSystemException); |
45 d.deleteSync(recursive: true); | 45 d.deleteSync(recursive: true); |
46 asyncEnd(); | 46 asyncEnd(); |
47 }); | 47 }); |
48 }); | 48 }); |
49 } | 49 } |
50 | 50 |
51 void main() { | 51 void main() { |
52 testListNonExistent(); | 52 testListNonExistent(); |
53 testListTooLongName(); | 53 testListTooLongName(); |
54 } | 54 } |
OLD | NEW |