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