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

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

Issue 25471003: Modify tests to use Directory.systemTemp (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 7 years, 2 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // 'fuzz' test the directory APIs by providing unexpected type 5 // 'fuzz' test the directory APIs by providing unexpected type
6 // arguments. The test passes if the VM does not crash. 6 // arguments. The test passes if the VM does not crash.
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import "package:async_helper/async_helper.dart"; 11 import "package:async_helper/async_helper.dart";
12 import "package:expect/expect.dart"; 12 import "package:expect/expect.dart";
13 13
14 import 'fuzz_support.dart'; 14 import 'fuzz_support.dart';
15 15
16 fuzzSyncMethods() { 16 fuzzSyncMethods() {
17 typeMapping.forEach((k, v) { 17 typeMapping.forEach((k, v) {
18 doItSync(() { 18 doItSync(() {
19 doItSync(() {
20 Directory.systemTemp.createTempSync(v).deleteSync();
21 });
19 var d = new Directory(v); 22 var d = new Directory(v);
20 doItSync(d.existsSync); 23 doItSync(d.existsSync);
21 doItSync(d.createSync); 24 doItSync(d.createSync);
22 doItSync(d.deleteSync); 25 doItSync(d.deleteSync);
23 doItSync(d.listSync); 26 doItSync(d.listSync);
24 doItSync(() { 27 doItSync(() {
25 d.createTempSync().deleteSync(); 28 d.createTempSync('tempdir').deleteSync();
26 }); 29 });
27 doItSync(() { 30 doItSync(() {
28 // Let's be a little careful. If the directory exists we don't 31 // Let's be a little careful. If the directory exists we don't
29 // want to delete it and all its contents. 32 // want to delete it and all its contents.
30 if (!d.existsSync()) d.deleteSync(recursive: true); 33 if (!d.existsSync()) d.deleteSync(recursive: true);
31 }); 34 });
32 typeMapping.forEach((k2, v2) { 35 typeMapping.forEach((k2, v2) {
33 doItSync(() => d.renameSync(v2)); 36 doItSync(() => d.renameSync(v2));
34 doItSync(() => d.listSync(recursive: v2)); 37 doItSync(() => d.listSync(recursive: v2));
35 }); 38 });
36 }); 39 });
37 }); 40 });
38 } 41 }
39 42
40 fuzzAsyncMethods() { 43 fuzzAsyncMethods() {
41 asyncStart(); 44 asyncStart();
42 var futures = []; 45 var futures = [];
43 typeMapping.forEach((k, v) { 46 typeMapping.forEach((k, v) {
47 futures.add(doItAsync(() {
48 Directory.systemTemp.createTempSync(v).deleteSync();
49 }));
44 if (v is! String) { 50 if (v is! String) {
45 Expect.throws(() => new Directory(v), 51 Expect.throws(() => new Directory(v),
46 (e) => e is ArgumentError); 52 (e) => e is ArgumentError);
47 return; 53 return;
48 } 54 }
49 var d = new Directory(v); 55 var d = new Directory(v);
50 futures.add(doItAsync(d.exists)); 56 futures.add(doItAsync(d.exists));
51 futures.add(doItAsync(d.create)); 57 futures.add(doItAsync(d.create));
52 futures.add(doItAsync(d.delete)); 58 futures.add(doItAsync(d.delete));
53 futures.add(doItAsync(() { 59 futures.add(doItAsync(() {
54 return d.createTemp().then((temp) { 60 return d.createTemp('tempdir').then((temp) {
55 return temp.delete(); 61 return temp.delete();
56 }); 62 });
57 })); 63 }));
58 futures.add(doItAsync(() { 64 futures.add(doItAsync(() {
59 return d.exists().then((res) { 65 return d.exists().then((res) {
60 if (!res) return d.delete(recursive: true); 66 if (!res) return d.delete(recursive: true);
61 return new Future.value(true); 67 return new Future.value(true);
62 }); 68 });
63 })); 69 }));
64 typeMapping.forEach((k2, v2) { 70 typeMapping.forEach((k2, v2) {
65 futures.add(doItAsync(() => d.rename(v2))); 71 futures.add(doItAsync(() => d.rename(v2)));
66 futures.add(doItAsync(() { 72 futures.add(doItAsync(() {
67 d.list(recursive: v2).listen((_) {}, onError: (e) => null); 73 d.list(recursive: v2).listen((_) {}, onError: (e) => null);
68 })); 74 }));
69 }); 75 });
70 }); 76 });
71 Future.wait(futures).then((_) => asyncEnd()); 77 Future.wait(futures).then((_) => asyncEnd());
72 } 78 }
73 79
74 main() { 80 main() {
75 fuzzSyncMethods(); 81 fuzzSyncMethods();
76 fuzzAsyncMethods(); 82 fuzzAsyncMethods();
77 } 83 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_error_test.dart ('k') | tests/standalone/io/directory_list_nonexistent_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698