Chromium Code Reviews

Side by Side Diff: test/io.dart

Issue 1187103004: Allow Suites to be added to an Engine over time. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 library test.test.io; 5 library test.test.io;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
kevmoo 2015/06/17 22:20:04 unused
nweiz 2015/06/17 22:41:08 Done.
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:test/src/util/io.dart'; 12 import 'package:test/src/util/io.dart';
13 import 'package:test/src/utils.dart'; 13 import 'package:test/src/utils.dart';
14 14
15 /// The path to the root directory of the `test` package. 15 /// The path to the root directory of the `test` package.
16 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); 16 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io)));
17 17
18 /// The path to the `pub` executable in the current Dart SDK. 18 /// The path to the `pub` executable in the current Dart SDK.
19 final _pubPath = p.absolute(p.join( 19 final _pubPath = p.absolute(p.join(
20 p.dirname(Platform.executable), 20 p.dirname(Platform.executable),
21 Platform.isWindows ? 'pub.bat' : 'pub')); 21 Platform.isWindows ? 'pub.bat' : 'pub'));
22 22
23 /// The platform-specific message emitted when a nonexistent file is loaded. 23 /// The platform-specific message emitted when a nonexistent file is loaded.
24 final String noSuchFileMessage = Platform.isWindows 24 final String noSuchFileMessage = Platform.isWindows
25 ? "The system cannot find the file specified." 25 ? "The system cannot find the file specified."
26 : "No such file or directory"; 26 : "No such file or directory";
27 27
28 /// A decoder that converts raw bytes to a line-by-line stream.
29 final _lines = UTF8.decoder.fuse(const LineSplitter());
30
31 /// A regular expression that matches the output of "pub serve". 28 /// A regular expression that matches the output of "pub serve".
32 final _servingRegExp = 29 final _servingRegExp =
33 new RegExp(r'^Serving myapp [a-z]+ on http://localhost:(\d+)$'); 30 new RegExp(r'^Serving myapp [a-z]+ on http://localhost:(\d+)$');
34 31
35 /// Runs the test executable with the package root set properly. 32 /// Runs the test executable with the package root set properly.
36 ProcessResult runTest(List<String> args, {String workingDirectory, 33 ProcessResult runTest(List<String> args, {String workingDirectory,
37 Map<String, String> environment}) { 34 Map<String, String> environment}) {
38 var allArgs = [ 35 var allArgs = [
39 p.absolute(p.join(packageDir, 'bin/test.dart')), 36 p.absolute(p.join(packageDir, 'bin/test.dart')),
40 "--package-root=${p.join(packageDir, 'packages')}" 37 "--package-root=${p.join(packageDir, 'packages')}"
(...skipping 69 matching lines...)
110 /// Starts "pub serve". 107 /// Starts "pub serve".
111 /// 108 ///
112 /// This returns a pair of the pub serve process and the port it's serving on. 109 /// This returns a pair of the pub serve process and the port it's serving on.
113 Future<Pair<Process, int>> startPubServe({List<String> args, 110 Future<Pair<Process, int>> startPubServe({List<String> args,
114 String workingDirectory, Map<String, String> environment}) async { 111 String workingDirectory, Map<String, String> environment}) async {
115 var allArgs = ['serve', '--port', '0']; 112 var allArgs = ['serve', '--port', '0'];
116 if (args != null) allArgs.addAll(args); 113 if (args != null) allArgs.addAll(args);
117 114
118 var process = await startPub(allArgs, 115 var process = await startPub(allArgs,
119 workingDirectory: workingDirectory, environment: environment); 116 workingDirectory: workingDirectory, environment: environment);
120 var line = await _lines.bind(process.stdout) 117 var line = await lineSplitter.bind(process.stdout)
121 .firstWhere(_servingRegExp.hasMatch); 118 .firstWhere(_servingRegExp.hasMatch);
122 var match = _servingRegExp.firstMatch(line); 119 var match = _servingRegExp.firstMatch(line);
123 120
124 return new Pair(process, int.parse(match[1])); 121 return new Pair(process, int.parse(match[1]));
125 } 122 }
126 123
127 /// A wrapper around [ProcessResult] that normalizes the newline format across 124 /// A wrapper around [ProcessResult] that normalizes the newline format across
128 /// operating systems. 125 /// operating systems.
129 class _NormalizedProcessResult implements ProcessResult { 126 class _NormalizedProcessResult implements ProcessResult {
130 final ProcessResult _inner; 127 final ProcessResult _inner;
131 128
132 int get exitCode => _inner.exitCode; 129 int get exitCode => _inner.exitCode;
133 int get pid => _inner.pid; 130 int get pid => _inner.pid;
134 131
135 final String stdout; 132 final String stdout;
136 final String stderr; 133 final String stderr;
137 134
138 _NormalizedProcessResult(ProcessResult inner) 135 _NormalizedProcessResult(ProcessResult inner)
139 : _inner = inner, 136 : _inner = inner,
140 stdout = Platform.isWindows 137 stdout = Platform.isWindows
141 ? inner.stdout.replaceAll("\r\n", "\n") 138 ? inner.stdout.replaceAll("\r\n", "\n")
142 : inner.stdout, 139 : inner.stdout,
143 stderr = Platform.isWindows 140 stderr = Platform.isWindows
144 ? inner.stderr.replaceAll("\r\n", "\n") 141 ? inner.stderr.replaceAll("\r\n", "\n")
145 : inner.stderr; 142 : inner.stderr;
146 } 143 }
OLDNEW

Powered by Google App Engine