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

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

Issue 11091070: Change Process.start to return a future that completes with a (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 // Process working directory test. 5 // Process working directory test.
6 6
7 #library("ProcessWorkingDirectoryTest"); 7 #library("ProcessWorkingDirectoryTest");
8 #import("dart:io"); 8 #import("dart:io");
9 #source("process_test_util.dart"); 9 #source("process_test_util.dart");
10 10
11 class ProcessWorkingDirectoryTest { 11 class ProcessWorkingDirectoryTest {
12 static String get fullTestFilePath { 12 static String get fullTestFilePath {
13 // Extract full path, since we run processes from another directory. 13 // Extract full path, since we run processes from another directory.
14 File path = new File(getProcessTestFileName()); 14 File path = new File(getProcessTestFileName());
15 Expect.isTrue(path.existsSync()); 15 Expect.isTrue(path.existsSync());
16 return path.fullPathSync(); 16 return path.fullPathSync();
17 } 17 }
18 18
19 static void testValidDirectory() { 19 static void testValidDirectory() {
20 Directory directory = new Directory("").createTempSync(); 20 Directory directory = new Directory("").createTempSync();
21 Expect.isTrue(directory.existsSync()); 21 Expect.isTrue(directory.existsSync());
22 22
23 var options = new ProcessOptions(); 23 var options = new ProcessOptions();
24 options.workingDirectory = directory.path; 24 options.workingDirectory = directory.path;
25 Process process = Process.start(fullTestFilePath, 25 Process.start(fullTestFilePath,
26 const ["0", "0", "99", "0"], 26 const ["0", "0", "99", "0"],
27 options); 27 options).then((process) {
28 process.onExit = (int exitCode) {
29 Expect.equals(exitCode, 99);
30 process.close();
31 directory.deleteSync();
32 };
28 33
29 process.onExit = (int exitCode) { 34 process.onError = (error) {
30 Expect.equals(exitCode, 99); 35 Expect.fail("error running process $error");
31 process.close(); 36 directory.deleteSync();
32 directory.deleteSync(); 37 };
33 }; 38 });
34
35 process.onError = (error) {
36 Expect.fail("error running process $error");
37 directory.deleteSync();
38 };
39 } 39 }
40 40
41 static void testInvalidDirectory() { 41 static void testInvalidDirectory() {
42 Directory directory = new Directory("").createTempSync(); 42 Directory directory = new Directory("").createTempSync();
43 Expect.isTrue(directory.existsSync()); 43 Expect.isTrue(directory.existsSync());
44 44
45 var options = new ProcessOptions(); 45 var options = new ProcessOptions();
46 options.workingDirectory = directory.path.concat("/subPath"); 46 options.workingDirectory = directory.path.concat("/subPath");
47 Process process = Process.start(fullTestFilePath, 47 var future = Process.start(fullTestFilePath,
Søren Gjesse 2012/10/12 07:47:22 One could consider writing this with cascades and
Mads Ager (google) 2012/10/12 08:44:46 I actually did a couple of places and removed it a
48 const ["0", "0", "99", "0"], 48 const ["0", "0", "99", "0"],
49 options); 49 options);
50 50 future.then((process) {
51 process.onExit = (int exitCode) {
52 Expect.fail("bad process completed"); 51 Expect.fail("bad process completed");
53 process.close(); 52 process.close();
54 directory.deleteSync(); 53 directory.deleteSync();
55 }; 54 });
56 55
57 process.onError = (error) { 56 future.handleException((e) {
58 Expect.isNotNull(error); 57 Expect.isNotNull(e);
59 directory.deleteSync(); 58 directory.deleteSync();
60 }; 59 return true;
60 });
61 } 61 }
62 } 62 }
63 63
64 64
65 65
66 main() { 66 main() {
67 ProcessWorkingDirectoryTest.testValidDirectory(); 67 ProcessWorkingDirectoryTest.testValidDirectory();
68 ProcessWorkingDirectoryTest.testInvalidDirectory(); 68 ProcessWorkingDirectoryTest.testInvalidDirectory();
69 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698