Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: tests/standalone/src/io/ProcessEnvironmentTest.dart

Issue 10127008: Support passing an environment variable map to child processes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/src/io/PrintEnv.dart ('k') | tests/standalone/src/io/TestingServer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+}
« no previous file with comments | « tests/standalone/src/io/PrintEnv.dart ('k') | tests/standalone/src/io/TestingServer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698