OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, 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 // Dart test program for testing file creation. | |
6 | |
7 import 'dart:async'; | |
8 import 'dart:io'; | |
9 | |
10 import "package:expect/expect.dart"; | |
11 import "package:path/path.dart"; | |
12 | |
13 testCreate() async { | |
14 Directory tmp = await Directory.systemTemp.createTemp('file_test_create'); | |
15 Expect.isTrue(await tmp.exists()); | |
16 String filePath = "${tmp.path}/foo"; | |
17 File file = new File(filePath); | |
18 File createdFile = await file.create(); | |
19 Expect.equals(file, createdFile); | |
20 Expect.isTrue(await createdFile.exists()); | |
21 await tmp.delete(recursive: true); | |
22 } | |
23 | |
24 testBadCreate() async { | |
25 Directory tmp = await Directory.systemTemp.createTemp('file_test_create'); | |
26 Expect.isTrue(await tmp.exists()); | |
27 Directory tmp2 = await tmp.createTemp('file_test_create'); | |
28 Expect.isTrue(await tmp2.exists()); | |
29 String badFilePath = tmp2.path; | |
30 File badFile = new File(badFilePath); | |
31 try { | |
32 await badFile.create(); | |
33 Expect.fail('Should be unreachable'); | |
34 } catch(e) { | |
35 Expect.isTrue(e is FileSystemException); | |
36 if (Platform.isWindows) { | |
37 Expect.isTrue(e.toString().contains('Access is denied')); | |
kasperl
2016/12/22 08:24:40
This is going to fail in non-English locales.
| |
38 } else { | |
39 Expect.isTrue(e.toString().contains('Is a directory')); | |
40 } | |
41 } | |
42 await tmp.delete(recursive: true); | |
43 } | |
44 | |
45 main() async { | |
46 await testCreate(); | |
47 await testBadCreate(); | |
48 } | |
OLD | NEW |