OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.stdio_process; | 5 library testing.stdio_process; |
6 | 6 |
7 import 'dart:async' show EventSink, Future, Stream, StreamTransformer, Timer; | 7 import 'dart:async' show EventSink, Future, Stream, StreamTransformer, Timer; |
8 | 8 |
9 import 'dart:convert' show UTF8; | 9 import 'dart:convert' show UTF8; |
10 | 10 |
11 import 'dart:io' show Process, ProcessSignal, Stdout; | 11 import 'dart:io' show Process, ProcessSignal, Stdout; |
12 | 12 |
13 import 'dart:io' as io show stderr, stdout; | 13 import 'dart:io' as io show stderr, stdout; |
14 | 14 |
15 import 'chain.dart' show Result; | 15 import 'chain.dart' show Result; |
16 | 16 |
| 17 import 'expectation.dart' show ExpectationSet; |
| 18 |
17 class StdioProcess { | 19 class StdioProcess { |
18 final int exitCode; | 20 final int exitCode; |
19 | 21 |
20 final String output; | 22 final String output; |
21 | 23 |
22 StdioProcess(this.exitCode, this.output); | 24 StdioProcess(this.exitCode, this.output); |
23 | 25 |
24 Result<int> toResult({int expected: 0}) { | 26 Result<int> toResult({int expected: 0}) { |
25 if (exitCode == expected) { | 27 if (exitCode == expected) { |
26 return new Result<int>.pass(exitCode); | 28 return new Result<int>.pass(exitCode); |
27 } else { | 29 } else { |
28 return new Result<int>.fail(exitCode, output); | 30 return new Result<Program>( |
| 31 exitCode, ExpectationSet.Default["RuntimeError"], output, null); |
29 } | 32 } |
30 } | 33 } |
31 | 34 |
32 static StreamTransformer<String, String> transformToStdio(Stdout stdio) { | 35 static StreamTransformer<String, String> transformToStdio(Stdout stdio) { |
33 return new StreamTransformer<String, String>.fromHandlers( | 36 return new StreamTransformer<String, String>.fromHandlers( |
34 handleData: (String data, EventSink<String> sink) { | 37 handleData: (String data, EventSink<String> sink) { |
35 sink.add(data); | 38 sink.add(data); |
36 stdio.write(data); | 39 stdio.write(data); |
37 }); | 40 }); |
38 } | 41 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 Future<List<String>> stdoutFuture = stdoutStream.toList(); | 76 Future<List<String>> stdoutFuture = stdoutStream.toList(); |
74 Future<List<String>> stderrFuture = stderrStream.toList(); | 77 Future<List<String>> stderrFuture = stderrStream.toList(); |
75 int exitCode = await process.exitCode; | 78 int exitCode = await process.exitCode; |
76 timer?.cancel(); | 79 timer?.cancel(); |
77 sb.writeAll(await stdoutFuture); | 80 sb.writeAll(await stdoutFuture); |
78 sb.writeAll(await stderrFuture); | 81 sb.writeAll(await stderrFuture); |
79 await closeFuture; | 82 await closeFuture; |
80 return new StdioProcess(exitCode, "$sb"); | 83 return new StdioProcess(exitCode, "$sb"); |
81 } | 84 } |
82 } | 85 } |
OLD | NEW |