OLD | NEW |
1 // Copyright (c) 2011, 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("ProcessTestUtil.dart"); | 9 #source("ProcessTestUtil.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(""); | 20 Directory directory = new Directory(""); |
21 directory.createTempSync(); | 21 directory.createTempSync(); |
22 Expect.isTrue(directory.existsSync()); | 22 Expect.isTrue(directory.existsSync()); |
23 | 23 |
24 Process process = new Process.start(fullTestFilePath, | 24 Process process = new Process.start(fullTestFilePath, |
25 const ["0", "0", "99", "0"], | 25 const ["0", "0", "99", "0"], |
26 directory.path); | 26 directory.path); |
27 | 27 |
28 process.exitHandler = (int exitCode) { | 28 process.onExit = (int exitCode) { |
29 Expect.equals(exitCode, 99); | 29 Expect.equals(exitCode, 99); |
30 process.close(); | 30 process.close(); |
31 directory.deleteSync(); | 31 directory.deleteSync(); |
32 }; | 32 }; |
33 | 33 |
34 process.errorHandler = (error) { | 34 process.onError = (error) { |
35 Expect.fail("error running process $error"); | 35 Expect.fail("error running process $error"); |
36 directory.deleteSync(); | 36 directory.deleteSync(); |
37 }; | 37 }; |
38 } | 38 } |
39 | 39 |
40 static void testInvalidDirectory() { | 40 static void testInvalidDirectory() { |
41 Directory directory = new Directory(""); | 41 Directory directory = new Directory(""); |
42 directory.createTempSync(); | 42 directory.createTempSync(); |
43 Expect.isTrue(directory.existsSync()); | 43 Expect.isTrue(directory.existsSync()); |
44 | 44 |
45 Process process = new Process.start(fullTestFilePath, | 45 Process process = new Process.start(fullTestFilePath, |
46 const ["0", "0", "99", "0"], | 46 const ["0", "0", "99", "0"], |
47 directory.path + "/subPath"); | 47 directory.path + "/subPath"); |
48 | 48 |
49 process.exitHandler = (int exitCode) { | 49 process.onExit = (int exitCode) { |
50 Expect.fail("bad process completed"); | 50 Expect.fail("bad process completed"); |
51 process.close(); | 51 process.close(); |
52 directory.deleteSync(); | 52 directory.deleteSync(); |
53 }; | 53 }; |
54 | 54 |
55 process.errorHandler = (error) { | 55 process.onError = (error) { |
56 Expect.isNotNull(error); | 56 Expect.isNotNull(error); |
57 directory.deleteSync(); | 57 directory.deleteSync(); |
58 }; | 58 }; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 | 62 |
63 | 63 |
64 main() { | 64 main() { |
65 ProcessWorkingDirectoryTest.testValidDirectory(); | 65 ProcessWorkingDirectoryTest.testValidDirectory(); |
66 ProcessWorkingDirectoryTest.testInvalidDirectory(); | 66 ProcessWorkingDirectoryTest.testInvalidDirectory(); |
67 } | 67 } |
OLD | NEW |