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

Side by Side Diff: tests/standalone/io/process_environment_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/io/platform_test.dart ('k') | tests/standalone/io/process_non_ascii_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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";
6
7 import "package:async_helper/async_helper.dart";
5 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
6 import "dart:io"; 9
7 import "dart:isolate";
8 import "process_test_util.dart"; 10 import "process_test_util.dart";
9 11
10 runEnvironmentProcess(Map environment, name, includeParent, callback) { 12 runEnvironmentProcess(Map environment, name, includeParent, callback) {
11 var dartExecutable = Platform.executable; 13 var dartExecutable = Platform.executable;
12 var printEnv = 'tests/standalone/io/print_env.dart'; 14 var printEnv = 'tests/standalone/io/print_env.dart';
13 if (!new File(printEnv).existsSync()) { 15 if (!new File(printEnv).existsSync()) {
14 printEnv = '../$printEnv'; 16 printEnv = '../$printEnv';
15 } 17 }
16 Process.run(dartExecutable, 18 Process.run(dartExecutable,
17 [printEnv, name], 19 [printEnv, name],
18 environment: environment, 20 environment: environment,
19 includeParentEnvironment: includeParent) 21 includeParentEnvironment: includeParent)
20 .then((result) { 22 .then((result) {
21 Expect.equals(0, result.exitCode); 23 Expect.equals(0, result.exitCode);
22 callback(result.stdout); 24 callback(result.stdout);
23 }); 25 });
24 } 26 }
25 27
26 testEnvironment() { 28 testEnvironment() {
27 var donePort = new ReceivePort(); 29 asyncStart();
28 Map env = Platform.environment; 30 Map env = Platform.environment;
29 Expect.isFalse(env.isEmpty); 31 Expect.isFalse(env.isEmpty);
30 // Check that some value in the environment stays the same when passed 32 // Check that some value in the environment stays the same when passed
31 // to another process. 33 // to another process.
32 for (var k in env.keys) { 34 for (var k in env.keys) {
33 runEnvironmentProcess({}, k, true, (output) { 35 runEnvironmentProcess({}, k, true, (output) {
34 // Only check startsWith. The print statements will add 36 // Only check startsWith. The print statements will add
35 // newlines at the end. 37 // newlines at the end.
36 Expect.isTrue(output.startsWith(env[k])); 38 Expect.isTrue(output.startsWith(env[k]));
37 // Add a new variable and check that it becomes an environment 39 // Add a new variable and check that it becomes an environment
38 // variable in the child process. 40 // variable in the child process.
39 var copy = new Map.from(env); 41 var copy = new Map.from(env);
40 var name = 'MYENVVAR'; 42 var name = 'MYENVVAR';
41 while (env.containsKey(name)) name = '${name}_'; 43 while (env.containsKey(name)) name = '${name}_';
42 copy[name] = 'value'; 44 copy[name] = 'value';
43 runEnvironmentProcess(copy, name, true, (output) { 45 runEnvironmentProcess(copy, name, true, (output) {
44 Expect.isTrue(output.startsWith('value')); 46 Expect.isTrue(output.startsWith('value'));
45 donePort.close(); 47 asyncEnd();
46 }); 48 });
47 }); 49 });
48 // Only check one value to not spin up too many processes testing the 50 // Only check one value to not spin up too many processes testing the
49 // same things. 51 // same things.
50 break; 52 break;
51 } 53 }
52 } 54 }
53 55
54 testNoIncludeEnvironment() { 56 testNoIncludeEnvironment() {
55 var donePort = new ReceivePort(); 57 asyncStart();
56 var env = Platform.environment; 58 var env = Platform.environment;
57 Expect.isTrue(env.containsKey('PATH')); 59 Expect.isTrue(env.containsKey('PATH'));
58 env.remove('PATH'); 60 env.remove('PATH');
59 runEnvironmentProcess(env, "PATH", false, (output) { 61 runEnvironmentProcess(env, "PATH", false, (output) {
60 donePort.close();
61 Expect.isTrue(output.startsWith("null")); 62 Expect.isTrue(output.startsWith("null"));
63 asyncEnd();
62 }); 64 });
63 } 65 }
64 66
65 main() { 67 main() {
66 testEnvironment(); 68 testEnvironment();
67 testNoIncludeEnvironment(); 69 testNoIncludeEnvironment();
68 } 70 }
OLDNEW
« no previous file with comments | « tests/standalone/io/platform_test.dart ('k') | tests/standalone/io/process_non_ascii_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698