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