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