| 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 // Dart test program for testing dart:io FileSystemEntity.Stat(). | 5 // Dart test program for testing dart:io FileSystemEntity.Stat(). |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| 11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
| 12 import "package:path/path.dart"; | 12 import "package:path/path.dart"; |
| 13 | 13 |
| 14 void testStat() { | 14 void testStat() { |
| 15 Directory directory = new Directory("").createTempSync(); | 15 Directory directory = Directory.systemTemp.createTempSync('dart_file_stat'); |
| 16 File file = new File(join(directory.path, "file")); | 16 File file = new File(join(directory.path, "file")); |
| 17 Expect.throws(file.statSync); | 17 Expect.throws(file.statSync); |
| 18 Expect.throws(() => FileStat.statSync(file.path)); | 18 Expect.throws(() => FileStat.statSync(file.path)); |
| 19 file.writeAsStringSync("Dart IO library test of FileStat"); | 19 file.writeAsStringSync("Dart IO library test of FileStat"); |
| 20 new Timer(const Duration(seconds: 2), () { | 20 new Timer(const Duration(seconds: 2), () { |
| 21 file.readAsStringSync(); | 21 file.readAsStringSync(); |
| 22 directory.listSync(); | 22 directory.listSync(); |
| 23 FileStat fileStat = FileStat.statSync(file.path); | 23 FileStat fileStat = FileStat.statSync(file.path); |
| 24 FileStat fileStatDirect = file.statSync(); | 24 FileStat fileStatDirect = file.statSync(); |
| 25 Expect.equals(FileSystemEntityType.FILE, fileStat.type); | 25 Expect.equals(FileSystemEntityType.FILE, fileStat.type); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 Expect.isTrue( | 41 Expect.isTrue( |
| 42 directoryStat.changed.compareTo(directoryStat.accessed) < 0); | 42 directoryStat.changed.compareTo(directoryStat.accessed) < 0); |
| 43 } | 43 } |
| 44 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. | 44 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. |
| 45 directory.deleteSync(recursive: true); | 45 directory.deleteSync(recursive: true); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| 50 Future testStatAsync() { | 50 Future testStatAsync() { |
| 51 return new Directory("").createTemp() | 51 return Directory.systemTemp.createTemp('dart_file_stat') |
| 52 .then((directory) { | 52 .then((directory) { |
| 53 File file = new File(join(directory.path, "file")); | 53 File file = new File(join(directory.path, "file")); |
| 54 return FileStat.stat(file.path) | 54 return FileStat.stat(file.path) |
| 55 .then((_) => Expect.fail("FileStat.stat should throw an exception.")) | 55 .then((_) => Expect.fail("FileStat.stat should throw an exception.")) |
| 56 .catchError((e) => null) | 56 .catchError((e) => null) |
| 57 .then((_) => file.stat()) | 57 .then((_) => file.stat()) |
| 58 .then((_) => Expect.fail("File.stat should throw an exception.")) | 58 .then((_) => Expect.fail("File.stat should throw an exception.")) |
| 59 .catchError((e) => null) | 59 .catchError((e) => null) |
| 60 .then((_) => file.writeAsString("Dart IO library test of FileStat")) | 60 .then((_) => file.writeAsString("Dart IO library test of FileStat")) |
| 61 .then((_) => new Future.delayed(const Duration(seconds: 2))) | 61 .then((_) => new Future.delayed(const Duration(seconds: 2))) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 }); | 117 }); |
| 118 }); | 118 }); |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 void main() { | 122 void main() { |
| 123 asyncStart(); | 123 asyncStart(); |
| 124 testStat(); | 124 testStat(); |
| 125 testStatAsync().then((_) => asyncEnd()); | 125 testStatAsync().then((_) => asyncEnd()); |
| 126 } | 126 } |
| OLD | NEW |