| Index: tests/standalone/src/io/ProcessEnvironmentTest.dart
|
| diff --git a/tests/standalone/src/io/ProcessEnvironmentTest.dart b/tests/standalone/src/io/ProcessEnvironmentTest.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2dc2b4a129e507efc3b92727e26c630ee28ae73f
|
| --- /dev/null
|
| +++ b/tests/standalone/src/io/ProcessEnvironmentTest.dart
|
| @@ -0,0 +1,57 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +#import('dart:io');
|
| +#import('dart:isolate');
|
| +#source('ProcessTestUtil.dart');
|
| +
|
| +runEnvironmentProcess(Map environment, name, callback) {
|
| + var dartExecutable = getDartFileName();
|
| + var options = new ProcessOptions();
|
| + options.environment = environment;
|
| + var printEnv = 'tests/standalone/src/io/PrintEnv.dart';
|
| + if (!new File(printEnv).existsSync()) {
|
| + printEnv = '../$printEnv';
|
| + }
|
| + var process = new Process.run(dartExecutable,
|
| + [printEnv, name],
|
| + options,
|
| + (exit, out, err) {
|
| + Expect.equals(0, exit);
|
| + callback(out);
|
| + });
|
| + process.onError = (e) => Expect.fail('Unexpected process start error');
|
| +}
|
| +
|
| +testEnvironment() {
|
| + var donePort = new ReceivePort();
|
| + Map env = Platform.environment();
|
| + Expect.isFalse(env.isEmpty());
|
| + // Check that some value in the environment stays the same when passed
|
| + // to another process.
|
| + for (var k in env.getKeys()) {
|
| + runEnvironmentProcess(env, k, (output) {
|
| + // Only check startsWith. The print statements will add
|
| + // newlines at the end.
|
| + Expect.isTrue(output.startsWith(env[k]));
|
| + // Add a new variable and check that it becomes an environment
|
| + // variable in the child process.
|
| + var copy = new Map.from(env);
|
| + var name = 'MYENVVAR';
|
| + while (env.containsKey(name)) name = '${name}_';
|
| + copy[name] = 'value';
|
| + runEnvironmentProcess(copy, name, (output) {
|
| + Expect.isTrue(output.startsWith('value'));
|
| + donePort.close();
|
| + });
|
| + });
|
| + // Only check one value to not spin up too many processes testing the
|
| + // same things.
|
| + break;
|
| + }
|
| +}
|
| +
|
| +main() {
|
| + testEnvironment();
|
| +}
|
|
|