| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "dart:io"; |
| 6 |
| 7 void testRunShell() { |
| 8 test(args) { |
| 9 var options = new Options(); |
| 10 var path = new Path(options.script); |
| 11 path = path.directoryPath.join(new Path("process_echo_util.dart")); |
| 12 Process.runShell(options.executable, [path.toString()]..addAll(args)) |
| 13 .then((result) { |
| 14 if (Platform.operatingSystem == "windows") { |
| 15 result = result.stdout.split("\r\n"); |
| 16 } else { |
| 17 result = result.stdout.split("\n"); |
| 18 } |
| 19 if (result.length - 1 != args.length) { |
| 20 throw "wrong number of args: $args vs $result"; |
| 21 } |
| 22 for (int i = 0; i < args.length; i++) { |
| 23 if (args[i] != result[i]) { |
| 24 throw "bad result at $i: '${args[i]}' vs '${result[i]}'"; |
| 25 } |
| 26 } |
| 27 }); |
| 28 } |
| 29 test(["\""]); |
| 30 test(["a b"]); |
| 31 test(["'"]); |
| 32 test(["'\"\"'\"'\"'"]); |
| 33 test(["'\"\"'", "\"'\"'"]); |
| 34 test(["'\$HOME'"]); |
| 35 test(["'\$tmp'"]); |
| 36 } |
| 37 |
| 38 void testShell() { |
| 39 test(args, expected) { |
| 40 var options = new Options(); |
| 41 var path = new Path(options.script); |
| 42 path = path.directoryPath.join(new Path("process_echo_util.dart")); |
| 43 var command = "${options.executable} $path $args"; |
| 44 Process.runShell(command, []) |
| 45 .then((result) { |
| 46 if (Platform.operatingSystem == "windows") { |
| 47 result = result.stdout.split("\r\n"); |
| 48 } else { |
| 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 } |
| 59 }); |
| 60 } |
| 61 test("arg", ["arg"]); |
| 62 test("arg1 arg2", ["arg1", "arg2"]); |
| 63 if (Platform.operatingSystem != 'windows') { |
| 64 test("arg1 arg2 > /dev/null", []); |
| 65 } |
| 66 } |
| 67 |
| 68 void main() { |
| 69 testRunShell(); |
| 70 testShell(); |
| 71 } |
| 72 |
| OLD | NEW |