Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "dart:io"; | 5 import "dart:io"; |
| 6 import "dart:isolate"; | |
| 6 | 7 |
| 7 void testRunShell() { | 8 void testRunShell() { |
| 8 test(args) { | 9 test(args) { |
| 9 var options = new Options(); | 10 var options = new Options(); |
| 10 var path = new Path(options.script); | 11 var path = new Path(options.script); |
| 11 path = path.directoryPath.join(new Path("process_echo_util.dart")); | 12 path = path.directoryPath.join(new Path("process_echo_util.dart")); |
| 12 Process.runShell(options.executable, [path.toString()]..addAll(args)) | 13 Process.run(options.executable, |
| 14 [path.toString()]..addAll(args), | |
| 15 runInShell: true) | |
| 13 .then((result) { | 16 .then((result) { |
| 14 if (Platform.operatingSystem == "windows") { | 17 if (Platform.operatingSystem == "windows") { |
| 15 result = result.stdout.split("\r\n"); | 18 result = result.stdout.split("\r\n"); |
| 16 } else { | 19 } else { |
| 17 result = result.stdout.split("\n"); | 20 result = result.stdout.split("\n"); |
| 18 } | 21 } |
| 19 if (result.length - 1 != args.length) { | 22 if (result.length - 1 != args.length) { |
| 20 throw "wrong number of args: $args vs $result"; | 23 throw "wrong number of args: $args vs $result"; |
| 21 } | 24 } |
| 22 for (int i = 0; i < args.length; i++) { | 25 for (int i = 0; i < args.length; i++) { |
| 23 if (args[i] != result[i]) { | 26 if (args[i] != result[i]) { |
| 24 throw "bad result at $i: '${args[i]}' vs '${result[i]}'"; | 27 throw "bad result at $i: '${args[i]}' vs '${result[i]}'"; |
| 25 } | 28 } |
| 26 } | 29 } |
| 27 }); | 30 }); |
| 28 } | 31 } |
| 29 test(["\""]); | 32 test(["\""]); |
| 30 test(["a b"]); | 33 test(["a b"]); |
| 31 test(["'"]); | 34 test(["'"]); |
| 35 test(["'", "'"]); | |
| 32 test(["'\"\"'\"'\"'"]); | 36 test(["'\"\"'\"'\"'"]); |
| 33 test(["'\"\"'", "\"'\"'"]); | 37 test(["'\"\"'", "\"'\"'"]); |
| 38 test(["'\\\"\\\"'\\", "\"\\'\"'"]); | |
| 34 test(["'\$HOME'"]); | 39 test(["'\$HOME'"]); |
| 35 test(["'\$tmp'"]); | 40 test(["'\$tmp'"]); |
| 41 test(["arg'"]); | |
| 42 test(["arg\\'", "'\\arg"]); | |
| 36 } | 43 } |
| 37 | 44 |
| 38 void testShell() { | 45 void testBadRunShell() { |
|
Bill Hesse
2013/07/22 15:36:29
This change to testBadRunShell seems totally broke
Anders Johnsen
2013/07/22 15:44:22
It's supposed to test that you can't run the progr
Bill Hesse
2013/07/22 15:50:22
OK, so it has nothing to do with the testShell() f
| |
| 39 test(args, expected) { | 46 test(exe, [args = const []]) { |
| 40 var options = new Options(); | 47 var options = new Options(); |
| 41 var path = new Path(options.script); | 48 var path = new Path(options.script); |
| 42 path = path.directoryPath.join(new Path("process_echo_util.dart")); | 49 path = path.directoryPath.join(new Path("process_echo_util.dart")); |
| 43 var command = "${options.executable} $path $args"; | 50 Process.run(exe, args, runInShell: true) |
| 44 Process.runShell(command, []) | |
| 45 .then((result) { | 51 .then((result) { |
| 46 if (Platform.operatingSystem == "windows") { | 52 port.close(); |
| 47 result = result.stdout.split("\r\n"); | 53 if (result.exitCode == 0) { |
| 48 } else { | 54 throw "error expected"; |
| 49 result = result.stdout.split("\n"); | |
| 50 } | |
| 51 if (result.length - 1 != expected.length) { | |
| 52 throw "wrong number of args: $expected vs $result"; | |
| 53 } | |
| 54 for (int i = 0; i < expected.length; i++) { | |
| 55 if (expected[i] != result[i]) { | |
| 56 throw "bad result at $i: ${expected[i]} vs ${result[i]}"; | |
| 57 } | |
| 58 } | 55 } |
| 59 }); | 56 }); |
| 60 } | 57 } |
| 61 test("arg", ["arg"]); | 58 test("\""); |
| 62 test("arg1 arg2", ["arg1", "arg2"]); | 59 test("'\$HOME'"); |
| 63 if (Platform.operatingSystem != 'windows') { | |
| 64 test("arg1 arg2 > /dev/null", []); | |
| 65 } | |
| 66 } | 60 } |
| 67 | 61 |
| 68 void main() { | 62 void main() { |
| 69 testRunShell(); | 63 testRunShell(); |
| 70 testShell(); | 64 testBadRunShell(); |
| 71 } | 65 } |
| 72 | 66 |
| OLD | NEW |