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 #import('dart:io'); | 5 #import('dart:io'); |
6 #import('dart:isolate'); | 6 #import('dart:isolate'); |
7 #source('process_test_util.dart'); | 7 #source('process_test_util.dart'); |
8 | 8 |
9 runEnvironmentProcess(Map environment, name, callback) { | 9 runEnvironmentProcess(Map environment, name, callback) { |
10 var dartExecutable = getDartFileName(); | 10 var dartExecutable = getDartFileName(); |
11 var options = new ProcessOptions(); | 11 var options = new ProcessOptions(); |
12 options.environment = environment; | 12 options.environment = environment; |
13 var printEnv = 'tests/standalone/io/print_env.dart'; | 13 var printEnv = 'tests/standalone/io/print_env.dart'; |
14 if (!new File(printEnv).existsSync()) { | 14 if (!new File(printEnv).existsSync()) { |
15 printEnv = '../$printEnv'; | 15 printEnv = '../$printEnv'; |
16 } | 16 } |
17 var process = new Process.run(dartExecutable, | 17 var process = new Process.run(dartExecutable, |
18 [printEnv, name], | 18 [printEnv, name], |
19 options, | 19 options, |
20 (exit, out, err) { | 20 (exit, out, err) { |
21 Expect.equals(0, exit); | 21 Expect.equals(0, exit); |
22 callback(out); | 22 callback(out); |
23 }); | 23 }); |
24 process.onError = (e) => Expect.fail("Unexpected process start error: '$e'"); | 24 process.onError = (e) => Expect.fail("Unexpected process start error: '$e'"); |
25 } | 25 } |
26 | 26 |
27 testEnvironment() { | 27 testEnvironment() { |
28 var donePort = new ReceivePort(); | 28 var donePort = new ReceivePort(); |
29 Map env = Platform.environment(); | 29 Map env = Platform.environment; |
30 Expect.isFalse(env.isEmpty()); | 30 Expect.isFalse(env.isEmpty()); |
31 // Check that some value in the environment stays the same when passed | 31 // Check that some value in the environment stays the same when passed |
32 // to another process. | 32 // to another process. |
33 for (var k in env.getKeys()) { | 33 for (var k in env.getKeys()) { |
34 runEnvironmentProcess(env, k, (output) { | 34 runEnvironmentProcess(env, k, (output) { |
35 // Only check startsWith. The print statements will add | 35 // Only check startsWith. The print statements will add |
36 // newlines at the end. | 36 // newlines at the end. |
37 Expect.isTrue(output.startsWith(env[k])); | 37 Expect.isTrue(output.startsWith(env[k])); |
38 // Add a new variable and check that it becomes an environment | 38 // Add a new variable and check that it becomes an environment |
39 // variable in the child process. | 39 // variable in the child process. |
40 var copy = new Map.from(env); | 40 var copy = new Map.from(env); |
41 var name = 'MYENVVAR'; | 41 var name = 'MYENVVAR'; |
42 while (env.containsKey(name)) name = '${name}_'; | 42 while (env.containsKey(name)) name = '${name}_'; |
43 copy[name] = 'value'; | 43 copy[name] = 'value'; |
44 runEnvironmentProcess(copy, name, (output) { | 44 runEnvironmentProcess(copy, name, (output) { |
45 Expect.isTrue(output.startsWith('value')); | 45 Expect.isTrue(output.startsWith('value')); |
46 donePort.close(); | 46 donePort.close(); |
47 }); | 47 }); |
48 }); | 48 }); |
49 // Only check one value to not spin up too many processes testing the | 49 // Only check one value to not spin up too many processes testing the |
50 // same things. | 50 // same things. |
51 break; | 51 break; |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 main() { | 55 main() { |
56 testEnvironment(); | 56 testEnvironment(); |
57 } | 57 } |
OLD | NEW |