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

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

Issue 156633002: Change FileStat static methods to return NOT_FOUND instead for throwing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 6 years, 10 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 | « sdk/lib/io/file_system_entity.dart ('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 '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 = Directory.systemTemp.createTempSync('dart_file_stat'); 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 FileStat fileStat = FileStat.statSync(file.path);
18 Expect.throws(() => FileStat.statSync(file.path)); 18 FileStat fileStatDirect = file.statSync();
19 Expect.equals(FileSystemEntityType.NOT_FOUND, fileStat.type);
20 Expect.equals(FileSystemEntityType.NOT_FOUND, fileStatDirect.type);
19 file.writeAsStringSync("Dart IO library test of FileStat"); 21 file.writeAsStringSync("Dart IO library test of FileStat");
20 new Timer(const Duration(seconds: 2), () { 22 new Timer(const Duration(seconds: 2), () {
21 file.readAsStringSync(); 23 file.readAsStringSync();
22 directory.listSync(); 24 directory.listSync();
23 FileStat fileStat = FileStat.statSync(file.path); 25 FileStat fileStat = FileStat.statSync(file.path);
24 FileStat fileStatDirect = file.statSync(); 26 FileStat fileStatDirect = file.statSync();
25 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 27 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
26 Expect.equals(32, fileStat.size); 28 Expect.equals(32, fileStat.size);
27 Expect.equals(FileSystemEntityType.FILE, fileStatDirect.type); 29 Expect.equals(FileSystemEntityType.FILE, fileStatDirect.type);
28 Expect.equals(32, fileStatDirect.size); 30 Expect.equals(32, fileStatDirect.size);
(...skipping 16 matching lines...) Expand all
45 directory.deleteSync(recursive: true); 47 directory.deleteSync(recursive: true);
46 }); 48 });
47 } 49 }
48 50
49 51
50 Future testStatAsync() { 52 Future testStatAsync() {
51 return Directory.systemTemp.createTemp('dart_file_stat') 53 return Directory.systemTemp.createTemp('dart_file_stat')
52 .then((directory) { 54 .then((directory) {
53 File file = new File(join(directory.path, "file")); 55 File file = new File(join(directory.path, "file"));
54 return FileStat.stat(file.path) 56 return FileStat.stat(file.path)
55 .then((_) => Expect.fail("FileStat.stat should throw an exception.")) 57 .then((fileStat) => Expect.equals(FileSystemEntityType.NOT_FOUND,
56 .catchError((e) => null) 58 fileStat.type))
57 .then((_) => file.stat()) 59 .then((_) => file.stat())
58 .then((_) => Expect.fail("File.stat should throw an exception.")) 60 .then((fileStat) => Expect.equals(FileSystemEntityType.NOT_FOUND,
59 .catchError((e) => null) 61 fileStat.type))
60 .then((_) => file.writeAsString("Dart IO library test of FileStat")) 62 .then((_) => file.writeAsString("Dart IO library test of FileStat"))
61 .then((_) => new Future.delayed(const Duration(seconds: 2))) 63 .then((_) => new Future.delayed(const Duration(seconds: 2)))
62 .then((_) => file.readAsString()) 64 .then((_) => file.readAsString())
63 .then((_) => directory.list().last) 65 .then((_) => directory.list().last)
64 .then((_) => FileStat.stat(file.path)) 66 .then((_) => FileStat.stat(file.path))
65 .then((FileStat fileStat) { 67 .then((FileStat fileStat) {
66 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 68 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
67 Expect.equals(32, fileStat.size); 69 Expect.equals(32, fileStat.size);
68 if (Platform.operatingSystem != 'windows') { 70 if (Platform.operatingSystem != 'windows') {
69 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); 71 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 }); 119 });
118 }); 120 });
119 } 121 }
120 122
121 123
122 void main() { 124 void main() {
123 asyncStart(); 125 asyncStart();
124 testStat(); 126 testStat();
125 testStatAsync().then((_) => asyncEnd()); 127 testStatAsync().then((_) => asyncEnd());
126 } 128 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_system_entity.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698