Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: tests/standalone/io/file_stat_test.dart

Issue 16140008: dart:io | Make FileStat.stat throw an exception when the file does not exist, or cannot be accessed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
11 11
12 void testStat() { 12 void testStat() {
13 Directory directory = new Directory("").createTempSync(); 13 Directory directory = new Directory("").createTempSync();
14 File file = new File.fromPath(new Path(directory.path).append("file")); 14 File file = new File.fromPath(new Path(directory.path).append("file"));
15 FileStat nonExistent = FileStat.statSync(file.path); 15 Expect.throws(file.statSync);
16 Expect.equals(FileSystemEntityType.NOT_FOUND, nonExistent.type); 16 Expect.throws(() => FileStat.statSync(file.path));
17 file.writeAsStringSync("Dart IO library test of FileStat"); 17 file.writeAsStringSync("Dart IO library test of FileStat");
18 new Timer(const Duration(seconds: 2), () { 18 new Timer(const Duration(seconds: 2), () {
19 file.readAsStringSync(); 19 file.readAsStringSync();
20 directory.listSync(); 20 directory.listSync();
21 FileStat fileStat = FileStat.statSync(file.path); 21 FileStat fileStat = FileStat.statSync(file.path);
22 FileStat fileStatDirect = file.statSync(); 22 FileStat fileStatDirect = file.statSync();
23 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 23 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
24 Expect.equals(32, fileStat.size); 24 Expect.equals(32, fileStat.size);
25 Expect.equals(FileSystemEntityType.FILE, fileStatDirect.type); 25 Expect.equals(FileSystemEntityType.FILE, fileStatDirect.type);
26 Expect.equals(32, fileStatDirect.size); 26 Expect.equals(32, fileStatDirect.size);
(...skipping 16 matching lines...) Expand all
43 directory.deleteSync(recursive: true); 43 directory.deleteSync(recursive: true);
44 }); 44 });
45 } 45 }
46 46
47 47
48 Future testStatAsync() { 48 Future testStatAsync() {
49 return new Directory("").createTemp() 49 return new Directory("").createTemp()
50 .then((directory) { 50 .then((directory) {
51 File file = new File.fromPath(new Path(directory.path).append("file")); 51 File file = new File.fromPath(new Path(directory.path).append("file"));
52 return FileStat.stat(file.path) 52 return FileStat.stat(file.path)
53 .then((missingStat) { 53 .then((_) => Expect.fail("FileStat.stat should throw an exception."))
54 Expect.equals(FileSystemEntityType.NOT_FOUND, missingStat.type); 54 .catchError((e) => null)
55 }) 55 .then((_) => file.stat())
56 .then((_) => Expect.fail("File.stat should throw an exception."))
57 .catchError((e) => null)
56 .then((_) => file.writeAsString("Dart IO library test of FileStat")) 58 .then((_) => file.writeAsString("Dart IO library test of FileStat"))
57 .then((_) => new Future.delayed(const Duration(seconds: 2))) 59 .then((_) => new Future.delayed(const Duration(seconds: 2)))
58 .then((_) => file.readAsString()) 60 .then((_) => file.readAsString())
59 .then((_) => directory.list().last) 61 .then((_) => directory.list().last)
60 .then((_) => FileStat.stat(file.path)) 62 .then((_) => FileStat.stat(file.path))
61 .then((FileStat fileStat) { 63 .then((FileStat fileStat) {
62 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 64 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
63 Expect.equals(32, fileStat.size); 65 Expect.equals(32, fileStat.size);
64 if (Platform.operatingSystem != 'windows') { 66 if (Platform.operatingSystem != 'windows') {
65 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); 67 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 }); 115 });
114 }); 116 });
115 } 117 }
116 118
117 119
118 void main() { 120 void main() {
119 ReceivePort keepAlive = new ReceivePort(); 121 ReceivePort keepAlive = new ReceivePort();
120 testStat(); 122 testStat();
121 testStatAsync().then((_) => keepAlive.close()); 123 testStatAsync().then((_) => keepAlive.close());
122 } 124 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698