| 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 "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 import "process_test_util.dart"; | 10 import "process_test_util.dart"; |
| 11 | 11 |
| 12 class ProcessWorkingDirectoryTest { | 12 class ProcessWorkingDirectoryTest { |
| 13 static String get fullTestFilePath { | 13 static String get fullTestFilePath { |
| 14 // Extract full path, since we run processes from another directory. | 14 // Extract full path, since we run processes from another directory. |
| 15 File path = new File(getProcessTestFileName()); | 15 File path = new File(getProcessTestFileName()); |
| 16 Expect.isTrue(path.existsSync()); | 16 Expect.isTrue(path.existsSync()); |
| 17 return path.fullPathSync(); | 17 return path.fullPathSync(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 static void testValidDirectory() { | 20 static void testValidDirectory() { |
| 21 Directory directory = new Directory("").createTempSync(); | 21 Directory directory = |
| 22 Directory.systemTemp.createTempSync('dart_process_working_directory'); |
| 22 Expect.isTrue(directory.existsSync()); | 23 Expect.isTrue(directory.existsSync()); |
| 23 | 24 |
| 24 Process.start(fullTestFilePath, | 25 Process.start(fullTestFilePath, |
| 25 const ["0", "0", "99", "0"], | 26 const ["0", "0", "99", "0"], |
| 26 workingDirectory: directory.path) | 27 workingDirectory: directory.path) |
| 27 .then((process) { | 28 .then((process) { |
| 28 process.exitCode.then((int exitCode) { | 29 process.exitCode.then((int exitCode) { |
| 29 Expect.equals(exitCode, 99); | 30 Expect.equals(exitCode, 99); |
| 30 directory.deleteSync(); | 31 directory.deleteSync(); |
| 31 }); | 32 }); |
| 32 process.stdout.listen((_) {}); | 33 process.stdout.listen((_) {}); |
| 33 process.stderr.listen((_) {}); | 34 process.stderr.listen((_) {}); |
| 34 }).catchError((error) { | 35 }).catchError((error) { |
| 35 directory.deleteSync(); | 36 directory.deleteSync(); |
| 36 Expect.fail("Couldn't start process"); | 37 Expect.fail("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 = |
| 43 Directory.systemTemp.createTempSync('dart_process_working_directory'); |
| 42 Expect.isTrue(directory.existsSync()); | 44 Expect.isTrue(directory.existsSync()); |
| 43 | 45 |
| 44 Process.start(fullTestFilePath, | 46 Process.start(fullTestFilePath, |
| 45 const ["0", "0", "99", "0"], | 47 const ["0", "0", "99", "0"], |
| 46 workingDirectory: directory.path + "/subPath") | 48 workingDirectory: directory.path + "/subPath") |
| 47 .then((process) { | 49 .then((process) { |
| 48 Expect.fail("bad process completed"); | 50 Expect.fail("bad process completed"); |
| 49 directory.deleteSync(); | 51 directory.deleteSync(); |
| 50 }).catchError((e) { | 52 }).catchError((e) { |
| 51 Expect.isNotNull(e); | 53 Expect.isNotNull(e); |
| 52 directory.deleteSync(); | 54 directory.deleteSync(); |
| 53 }); | 55 }); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 | 59 |
| 58 | 60 |
| 59 main() { | 61 main() { |
| 60 ProcessWorkingDirectoryTest.testValidDirectory(); | 62 ProcessWorkingDirectoryTest.testValidDirectory(); |
| 61 ProcessWorkingDirectoryTest.testInvalidDirectory(); | 63 ProcessWorkingDirectoryTest.testInvalidDirectory(); |
| 62 } | 64 } |
| OLD | NEW |