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

Side by Side Diff: pkg/testing/lib/src/stdio_process.dart

Issue 2624373003: Move package:testing to SDK. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/testing/lib/src/run_tests.dart ('k') | pkg/testing/lib/src/suite.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.md file.
4
5 library testing.stdio_process;
6
7 import 'dart:async' show
8 Future,
9 Timer;
10
11 import 'dart:convert' show
12 UTF8;
13
14 import 'dart:io' show
15 Process,
16 ProcessSignal;
17
18 import 'chain.dart' show
19 Result;
20
21 class StdioProcess {
22 final int exitCode;
23
24 final String output;
25
26 StdioProcess(this.exitCode, this.output);
27
28 Result<int> toResult({int expected: 0}) {
29 if (exitCode == expected) {
30 return new Result<int>.pass(exitCode);
31 } else {
32 return new Result<int>.fail(exitCode, output);
33 }
34 }
35
36 static Future<StdioProcess> run(
37 String executable, List<String> arguments,
38 {String input, Duration timeout: const Duration(seconds: 60)}) async {
39 Process process = await Process.start(executable, arguments);
40 Timer timer;
41 StringBuffer sb = new StringBuffer();
42 timer = new Timer(timeout, () {
43 sb.write("Process timed out: ");
44 sb.write(executable);
45 sb.write(" ");
46 sb.writeAll(arguments, " ");
47 sb.writeln();
48 sb.writeln("Sending SIGTERM to process");
49 process.kill();
50 timer = new Timer(const Duration(seconds: 10), () {
51 sb.writeln("Sending SIGKILL to process");
52 process.kill(ProcessSignal.SIGKILL);
53 });
54 });
55 if (input != null) {
56 process.stdin.write(input);
57 }
58 Future closeFuture = process.stdin.close();
59 Future<List<String>> stdoutFuture =
60 process.stdout.transform(UTF8.decoder).toList();
61 Future<List<String>> stderrFuture =
62 process.stderr.transform(UTF8.decoder).toList();
63 int exitCode = await process.exitCode;
64 timer.cancel();
65 sb.writeAll(await stdoutFuture);
66 sb.writeAll(await stderrFuture);
67 await closeFuture;
68 return new StdioProcess(exitCode, "$sb");
69 }
70 }
OLDNEW
« no previous file with comments | « pkg/testing/lib/src/run_tests.dart ('k') | pkg/testing/lib/src/suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698