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

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: Comments cleanup. 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/_internal/pub/test/test_pub.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 /// description of this process; it defaults to the command-line invocation. 74 /// [Process.start]. [description] is a string description of this process; it
75 /// [encoding] is the [Encoding] that will be used for the process's input and 75 /// defaults to the command-line invocation. [encoding] is the [Encoding] that
76 /// output. 76 /// will be used for the process's input and output.
77 /// 77 ///
78 /// [executable], [arguments], and [options] may be either a [Future] or a 78 /// [executable], [arguments], [workingDirectory], and [environment] may be
79 /// concrete value. If any are [Future]s, the process won't start until the 79 /// either a [Future] or a concrete value. If any are [Future]s, the process
80 /// [Future]s have completed. In addition, [arguments] may be a [List] 80 /// won't start until the [Future]s have completed. In addition, [arguments]
81 /// containing a mix of strings and [Future]s. 81 /// may be a [List] containing a mix of strings and [Future]s.
82 ScheduledProcess.start(executable, arguments, 82 ScheduledProcess.start(executable, arguments,
83 {options, String description, Encoding encoding: Encoding.UTF_8}) 83 {workingDirectory, environment, String description,
84 Encoding encoding: Encoding.UTF_8})
84 : _encoding = encoding, 85 : _encoding = encoding,
85 _explicitDescription = description != null, 86 _explicitDescription = description != null,
86 _description = description { 87 _description = description {
87 assert(currentSchedule.state == ScheduleState.SET_UP); 88 assert(currentSchedule.state == ScheduleState.SET_UP);
88 89
89 _updateDescription(executable, arguments); 90 _updateDescription(executable, arguments);
90 91
91 _scheduleStartProcess(executable, arguments, options); 92 _scheduleStartProcess(executable, arguments, workingDirectory, environment);
92 93
93 _scheduleExceptionCleanup(); 94 _scheduleExceptionCleanup();
94 95
95 var stdoutWithCanceller = _lineStreamWithCanceller( 96 var stdoutWithCanceller = _lineStreamWithCanceller(
96 _process.then((p) => p.stdout)); 97 _process.then((p) => p.stdout));
97 _stdoutCanceller = stdoutWithCanceller.last; 98 _stdoutCanceller = stdoutWithCanceller.last;
98 _stdoutLog = stdoutWithCanceller.first; 99 _stdoutLog = stdoutWithCanceller.first;
99 100
100 var stderrWithCanceller = _lineStreamWithCanceller( 101 var stderrWithCanceller = _lineStreamWithCanceller(
101 _process.then((p) => p.stderr)); 102 _process.then((p) => p.stderr));
(...skipping 11 matching lines...) Expand all
113 if (executable is Future) { 114 if (executable is Future) {
114 _description = "future process"; 115 _description = "future process";
115 } else if (arguments is Future || arguments.any((e) => e is Future)) { 116 } else if (arguments is Future || arguments.any((e) => e is Future)) {
116 _description = executable; 117 _description = executable;
117 } else { 118 } else {
118 _description = "$executable ${arguments.map((a) => '"$a"').join(' ')}"; 119 _description = "$executable ${arguments.map((a) => '"$a"').join(' ')}";
119 } 120 }
120 } 121 }
121 122
122 /// Schedules the process to start and sets [_process]. 123 /// Schedules the process to start and sets [_process].
123 void _scheduleStartProcess(executable, arguments, options) { 124 void _scheduleStartProcess(executable,
125 arguments,
126 workingDirectory,
127 environment) {
nweiz 2013/07/22 20:15:11 These arguments shouldn't be aligned like this; th
Søren Gjesse 2013/07/23 13:04:00 In the C++ style guide (which is the basis for the
124 var exitCodeCompleter = new Completer(); 128 var exitCodeCompleter = new Completer();
125 _exitCode = new ValueFuture(exitCodeCompleter.future); 129 _exitCode = new ValueFuture(exitCodeCompleter.future);
126 130
127 _process = new ValueFuture(schedule(() { 131 _process = new ValueFuture(schedule(() {
128 if (!_endScheduled) { 132 if (!_endScheduled) {
129 throw new StateError("Scheduled process '$description' must " 133 throw new StateError("Scheduled process '$description' must "
130 "have shouldExit() or kill() called before the test is run."); 134 "have shouldExit() or kill() called before the test is run.");
131 } 135 }
132 136
133 _handleExit(exitCodeCompleter); 137 _handleExit(exitCodeCompleter);
134 138
135 return Future.wait([ 139 return Future.wait([
136 new Future.sync(() => executable), 140 new Future.sync(() => executable),
137 awaitObject(arguments), 141 awaitObject(arguments),
138 new Future.sync(() => options) 142 new Future.sync(() => workingDirectory),
143 new Future.sync(() => environment)
139 ]).then((results) { 144 ]).then((results) {
140 executable = results[0]; 145 executable = results[0];
141 arguments = results[1]; 146 arguments = results[1];
142 options = results[2]; 147 workingDirectory = results[2];
148 environment = results[3];
143 _updateDescription(executable, arguments); 149 _updateDescription(executable, arguments);
144 return Process.start(executable, arguments, options).then((process) { 150 return Process.start(executable,
151 arguments,
152 workingDirectory: workingDirectory,
153 environment: environment).then((process) {
145 // TODO(nweiz): enable this when issue 9020 is fixed. 154 // TODO(nweiz): enable this when issue 9020 is fixed.
146 // process.stdin.encoding = Encoding.UTF_8; 155 // process.stdin.encoding = Encoding.UTF_8;
147 return process; 156 return process;
148 }); 157 });
149 }); 158 });
150 }, "starting process '$description'")); 159 }, "starting process '$description'"));
151 } 160 }
152 161
153 /// Listens for [_process] to exit and passes the exit code to 162 /// Listens for [_process] to exit and passes the exit code to
154 /// [exitCodeCompleter]. If the process completes earlier than expected, an 163 /// [exitCodeCompleter]. If the process completes earlier than expected, an
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 schedule(() { 345 schedule(() {
337 _endExpected = true; 346 _endExpected = true;
338 return _exitCode.then((exitCode) { 347 return _exitCode.then((exitCode) {
339 if (expectedExitCode != null) { 348 if (expectedExitCode != null) {
340 expect(exitCode, equals(expectedExitCode)); 349 expect(exitCode, equals(expectedExitCode));
341 } 350 }
342 }); 351 });
343 }, "waiting for process '$description' to exit"); 352 }, "waiting for process '$description' to exit");
344 } 353 }
345 } 354 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_patch.dart » ('j') | sdk/lib/_internal/pub/test/test_pub.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698