Files
sdk/tests/standalone_2/io/process_environment_test.dart
T
Alexander Markov f5c16512cc [Tests] Pass VM options (Platform.executableArguments) to sub-processes
When testing runs with certain set of VM options and tests launch
new Dart processes, VM options should be also forwarded to child
processes.

Change-Id: I7207fe87672cd61fd50d7ac77ef1da67744af183
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97169
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-03-18 23:20:41 +00:00

80 lines
2.4 KiB
Dart

// 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 "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
import "process_test_util.dart";
runEnvironmentProcess(
Map<String, String> environment, name, includeParent, callback) {
var dartExecutable = Platform.executable;
var printEnv = 'tests/standalone_2/io/print_env.dart';
if (!new File(printEnv).existsSync()) {
printEnv = '../$printEnv';
}
Process.run(dartExecutable,
[]..addAll(Platform.executableArguments)..addAll([printEnv, name]),
environment: environment, includeParentEnvironment: includeParent)
.then((result) {
if (result.exitCode != 0) {
print('print_env.dart subprocess failed '
'with exit code ${result.exitCode}');
print('stdout:');
print(result.stdout);
print('stderr:');
print(result.stderr);
}
Expect.equals(0, result.exitCode);
callback(result.stdout);
});
}
testEnvironment() {
asyncStart();
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.keys) {
runEnvironmentProcess({}, k, true, (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<String, String>.from(env);
var name = 'MYENVVAR';
while (env.containsKey(name)) name = '${name}_';
copy[name] = 'value';
runEnvironmentProcess(copy, name, true, (output) {
Expect.isTrue(output.startsWith('value'));
asyncEnd();
});
});
// Only check one value to not spin up too many processes testing the
// same things.
break;
}
}
testNoIncludeEnvironment() {
asyncStart();
var env = Platform.environment;
Expect.isTrue(env.containsKey('PATH'));
env = new Map.from(env);
env.remove('PATH');
runEnvironmentProcess(env, "PATH", false, (output) {
Expect.isTrue(output.startsWith("null"));
asyncEnd();
});
}
main() {
testEnvironment();
testNoIncludeEnvironment();
}