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

Side by Side Diff: pkg/scheduled_test/lib/scheduled_process.dart

Issue 15883003: Remove ProcessOptions and make the options named arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | « no previous file | runtime/bin/process_patch.dart » ('j') | sdk/lib/io/process.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library scheduled_test.scheduled_process; 5 library scheduled_test.scheduled_process;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'scheduled_test.dart'; 10 import 'scheduled_test.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 /// [shouldExit] or [kill]. 62 /// [shouldExit] or [kill].
63 var _endScheduled = false; 63 var _endScheduled = false;
64 64
65 /// The task that runs immediately before this process is scheduled to end. If 65 /// The task that runs immediately before this process is scheduled to end. If
66 /// the process ends during this task, we treat that as expected. 66 /// the process ends during this task, we treat that as expected.
67 Task _taskBeforeEnd; 67 Task _taskBeforeEnd;
68 68
69 /// Whether the process is expected to terminate at this point. 69 /// Whether the process is expected to terminate at this point.
70 var _endExpected = false; 70 var _endExpected = false;
71 71
72 /// Schedules a process to start. [executable], [arguments], and [options] 72 /// Schedules a process to start. [executable], [arguments],
73 /// have the same meaning as for [Process.start]. [description] is a string 73 /// [workingDirectory], and [environment] have the same meaning as for
74 /// [Process.start]. [description] is a string
nweiz 2013/05/23 18:55:11 Please re-justify the whole paragraph. The followi
Anders Johnsen 2013/05/24 11:04:15 Done.
74 /// description of this process; it defaults to the command-line invocation. 75 /// description of this process; it defaults to the command-line invocation.
75 /// [encoding] is the [Encoding] that will be used for the process's input and 76 /// [encoding] is the [Encoding] that will be used for the process's input and
76 /// output. 77 /// output.
77 /// 78 ///
78 /// [executable], [arguments], and [options] may be either a [Future] or a 79 /// [executable], [arguments], [workingDirectory], and [environment] may be
80 /// either a [Future] or a
79 /// concrete value. If any are [Future]s, the process won't start until the 81 /// concrete value. If any are [Future]s, the process won't start until the
80 /// [Future]s have completed. In addition, [arguments] may be a [List] 82 /// [Future]s have completed. In addition, [arguments] may be a [List]
81 /// containing a mix of strings and [Future]s. 83 /// containing a mix of strings and [Future]s.
82 ScheduledProcess.start(executable, arguments, 84 ScheduledProcess.start(executable, arguments,
83 {options, String description, Encoding encoding: Encoding.UTF_8}) 85 {workingDirectory, environment, String description,
kustermann 2013/05/24 08:44:30 I wouldn't mind if we make this 'cwd'. But I guess
Anders Johnsen 2013/05/24 11:04:15 Yep. :)
86 Encoding encoding: Encoding.UTF_8})
84 : _encoding = encoding, 87 : _encoding = encoding,
85 _explicitDescription = description != null, 88 _explicitDescription = description != null,
86 _description = description { 89 _description = description {
87 assert(currentSchedule.state == ScheduleState.SET_UP); 90 assert(currentSchedule.state == ScheduleState.SET_UP);
88 91
89 _updateDescription(executable, arguments); 92 _updateDescription(executable, arguments);
90 93
91 _scheduleStartProcess(executable, arguments, options); 94 _scheduleStartProcess(executable, arguments, workingDirectory, environment);
92 95
93 _scheduleExceptionCleanup(); 96 _scheduleExceptionCleanup();
94 97
95 var stdoutWithCanceller = _lineStreamWithCanceller( 98 var stdoutWithCanceller = _lineStreamWithCanceller(
96 _process.then((p) => p.stdout)); 99 _process.then((p) => p.stdout));
97 _stdoutCanceller = stdoutWithCanceller.last; 100 _stdoutCanceller = stdoutWithCanceller.last;
98 _stdoutLog = stdoutWithCanceller.first; 101 _stdoutLog = stdoutWithCanceller.first;
99 102
100 var stderrWithCanceller = _lineStreamWithCanceller( 103 var stderrWithCanceller = _lineStreamWithCanceller(
101 _process.then((p) => p.stderr)); 104 _process.then((p) => p.stderr));
(...skipping 11 matching lines...) Expand all
113 if (executable is Future) { 116 if (executable is Future) {
114 _description = "future process"; 117 _description = "future process";
115 } else if (arguments is Future || arguments.any((e) => e is Future)) { 118 } else if (arguments is Future || arguments.any((e) => e is Future)) {
116 _description = executable; 119 _description = executable;
117 } else { 120 } else {
118 _description = "$executable ${arguments.map((a) => '"$a"').join(' ')}"; 121 _description = "$executable ${arguments.map((a) => '"$a"').join(' ')}";
119 } 122 }
120 } 123 }
121 124
122 /// Schedules the process to start and sets [_process]. 125 /// Schedules the process to start and sets [_process].
123 void _scheduleStartProcess(executable, arguments, options) { 126 void _scheduleStartProcess(executable,
127 arguments,
128 workingDirectory,
129 environment) {
124 var exitCodeCompleter = new Completer(); 130 var exitCodeCompleter = new Completer();
125 _exitCode = new ValueFuture(exitCodeCompleter.future); 131 _exitCode = new ValueFuture(exitCodeCompleter.future);
126 132
127 _process = new ValueFuture(schedule(() { 133 _process = new ValueFuture(schedule(() {
128 if (!_endScheduled) { 134 if (!_endScheduled) {
129 throw new StateError("Scheduled process '$description' must " 135 throw new StateError("Scheduled process '$description' must "
130 "have shouldExit() or kill() called before the test is run."); 136 "have shouldExit() or kill() called before the test is run.");
131 } 137 }
132 138
133 _handleExit(exitCodeCompleter); 139 _handleExit(exitCodeCompleter);
134 140
135 return Future.wait([ 141 return Future.wait([
136 new Future.sync(() => executable), 142 new Future.sync(() => executable),
137 awaitObject(arguments), 143 awaitObject(arguments),
138 new Future.sync(() => options) 144 new Future.sync(() => workingDirectory),
145 new Future.sync(() => environment)
kustermann 2013/05/24 08:44:30 Why do we have 'new Future.sync(() => executable)'
Anders Johnsen 2013/05/24 11:04:15 Since the executable can be wrapped in a Future. S
139 ]).then((results) { 146 ]).then((results) {
140 executable = results[0]; 147 executable = results[0];
141 arguments = results[1]; 148 arguments = results[1];
142 options = results[2]; 149 workingDirectory = results[2];
150 environment = results[3];
143 _updateDescription(executable, arguments); 151 _updateDescription(executable, arguments);
144 return Process.start(executable, arguments, options).then((process) { 152 return Process.start(executable,
153 arguments,
154 workingDirectory: workingDirectory,
155 environment: environment).then((process) {
145 // TODO(nweiz): enable this when issue 9020 is fixed. 156 // TODO(nweiz): enable this when issue 9020 is fixed.
Yonggang Luo 2013/05/24 18:55:59 https://code.google.com/p/dart/issues/detail?id=90
nweiz 2013/05/24 20:15:50 Nice catch, I'll enable this in a separate CL.
146 // process.stdin.encoding = Encoding.UTF_8; 157 // process.stdin.encoding = Encoding.UTF_8;
147 return process; 158 return process;
148 }); 159 });
149 }); 160 });
150 }, "starting process '$description'")); 161 }, "starting process '$description'"));
151 } 162 }
152 163
153 /// Listens for [_process] to exit and passes the exit code to 164 /// Listens for [_process] to exit and passes the exit code to
154 /// [exitCodeCompleter]. If the process completes earlier than expected, an 165 /// [exitCodeCompleter]. If the process completes earlier than expected, an
155 /// exception will be signaled to the schedule. 166 /// exception will be signaled to the schedule.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 schedule(() { 347 schedule(() {
337 _endExpected = true; 348 _endExpected = true;
338 return _exitCode.then((exitCode) { 349 return _exitCode.then((exitCode) {
339 if (expectedExitCode != null) { 350 if (expectedExitCode != null) {
340 expect(exitCode, equals(expectedExitCode)); 351 expect(exitCode, equals(expectedExitCode));
341 } 352 }
342 }); 353 });
343 }, "waiting for process '$description' to exit"); 354 }, "waiting for process '$description' to exit");
344 } 355 }
345 } 356 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_patch.dart » ('j') | sdk/lib/io/process.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698