| 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 Expect.isNotNull(e.osError); |
| 37 } |
| 38 await tmp.delete(recursive: true); |
| 39 } |
| 40 |
| 41 main() async { |
| 42 await testCreate(); |
| 43 await testBadCreate(); |
| 44 } |
| OLD | NEW |