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

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

Issue 890633002: Add an option for starting a detached process with stdio connected (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 5 years, 10 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/process_detached_script.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // Process test program to test detached processes. 5 // Process test program to test detached processes.
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import "package:async_helper/async_helper.dart"; 10 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
12 12
13 import "process_test_util.dart"; 13 import "process_test_util.dart";
14 14
15 void test() { 15 void test() {
16 asyncStart(); 16 asyncStart();
17 var script = 17 var script =
18 Platform.script.resolve('process_detached_script.dart').toFilePath(); 18 Platform.script.resolve('process_detached_script.dart').toFilePath();
19 var future = Process.start(Platform.executable, [script], detach: true); 19 var future = Process.start(
20 Platform.executable, [script], mode: ProcessStartMode.DETACHED);
20 future.then((process) { 21 future.then((process) {
21 print(process.pid);
22 Expect.isNotNull(process.pid); 22 Expect.isNotNull(process.pid);
23 Expect.isTrue(process.pid is int); 23 Expect.isTrue(process.pid is int);
24 Expect.isNull(process.exitCode); 24 Expect.isNull(process.exitCode);
25 Expect.isNull(process.stderr); 25 Expect.isNull(process.stderr);
26 Expect.isNull(process.stdin); 26 Expect.isNull(process.stdin);
27 Expect.isNull(process.stdout); 27 Expect.isNull(process.stdout);
28 Expect.isTrue(process.kill()); 28 Expect.isTrue(process.kill());
29 }).whenComplete(() { 29 }).whenComplete(() {
30 asyncEnd(); 30 asyncEnd();
31 }); 31 });
32 } 32 }
33 33
34 void testWithStdio() {
35 asyncStart();
36 var script =
37 Platform.script.resolve('process_detached_script.dart').toFilePath();
38 var future = Process.start(
39 Platform.executable,
40 [script, 'echo'],
41 mode: ProcessStartMode.DETACHED_WITH_STDIO);
42 future.then((process) {
43 Expect.isNotNull(process.pid);
44 Expect.isTrue(process.pid is int);
45 Expect.isNull(process.exitCode);
46 var message = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
47 process.stdin.add(message);
48 process.stdin.close();
49 var f1 = process.stdout.fold([], (p, e) => p..addAll(e));
50 var f2 = process.stderr.fold([], (p, e) => p..addAll(e));
51 Future.wait([f1, f2])
52 .then((values) {
53 Expect.listEquals(values[0], message);
54 Expect.listEquals(values[1], message);
55 })
56 .whenComplete(() {
57 Expect.isTrue(process.kill());
58 });
59 }).whenComplete(() {
60 asyncEnd();
61 });
62 }
63
34 void testFailure() { 64 void testFailure() {
35 asyncStart(); 65 asyncStart();
36 Directory.systemTemp.createTemp('dart_detached_process').then((temp) { 66 Directory.systemTemp.createTemp('dart_detached_process').then((temp) {
37 var future = Process.start(temp.path, ['a', 'b'], detach: true); 67 var future = Process.start(
68 temp.path, ['a', 'b'], mode: ProcessStartMode.DETACHED);
38 future.then((process) { 69 future.then((process) {
39 Expect.fail('Starting process from invalid executable succeeded'); 70 Expect.fail('Starting process from invalid executable succeeded');
40 }, onError: (e) { 71 }, onError: (e) {
41 Expect.isTrue(e is ProcessException); 72 Expect.isTrue(e is ProcessException);
42 }).whenComplete(() { 73 }).whenComplete(() {
43 temp.deleteSync(); 74 temp.deleteSync();
44 asyncEnd(); 75 asyncEnd();
45 }); 76 });
46 }); 77 });
47 } 78 }
48 79
49 main() { 80 main() {
50 test(); 81 test();
82 testWithStdio();
51 testFailure(); 83 testFailure();
52 } 84 }
OLDNEW
« no previous file with comments | « tests/standalone/io/process_detached_script.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698