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