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

Side by Side Diff: test/io.dart

Issue 2068363002: pkg/test: Resolve a number of analyzer warnings (Closed) Base URL: https://github.com/dart-lang/test.git@master
Patch Set: more nits Created 4 years, 6 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 | « lib/src/utils.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 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it 5 // TODO(nweiz): Remove this tag when we can get [packageDir] working without it
6 // (dart-lang/sdk#24022). 6 // (dart-lang/sdk#24022).
7 library test.test.io; 7 library test.test.io;
8 8
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:convert';
11 import 'dart:io'; 10 import 'dart:io';
12 11
13 import 'package:path/path.dart' as p; 12 import 'package:path/path.dart' as p;
14 import 'package:scheduled_test/descriptor.dart' as d; 13 import 'package:scheduled_test/descriptor.dart' as d;
15 import 'package:scheduled_test/scheduled_process.dart'; 14 import 'package:scheduled_test/scheduled_process.dart';
16 import 'package:scheduled_test/scheduled_stream.dart'; 15 import 'package:scheduled_test/scheduled_stream.dart';
17 import 'package:scheduled_test/scheduled_test.dart'; 16 import 'package:scheduled_test/scheduled_test.dart';
18 import 'package:test/src/util/io.dart'; 17 import 'package:test/src/util/io.dart';
19 import 'package:yaml/yaml.dart';
20 18
21 /// The path to the root directory of the `test` package. 19 /// The path to the root directory of the `test` package.
22 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io))); 20 final String packageDir = p.dirname(p.dirname(libraryPath(#test.test.io)));
23 21
24 /// The path to the `pub` executable in the current Dart SDK. 22 /// The path to the `pub` executable in the current Dart SDK.
25 final _pubPath = p.absolute(p.join( 23 final _pubPath = p.absolute(p.join(
26 p.dirname(Platform.resolvedExecutable), 24 p.dirname(Platform.resolvedExecutable),
27 Platform.isWindows ? 'pub.bat' : 'pub')); 25 Platform.isWindows ? 'pub.bat' : 'pub'));
28 26
29 /// The platform-specific message emitted when a nonexistent file is loaded. 27 /// The platform-specific message emitted when a nonexistent file is loaded.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 /// 95 ///
98 /// This expects each string in [strings] to match a different string in the 96 /// This expects each string in [strings] to match a different string in the
99 /// stream. 97 /// stream.
100 StreamMatcher containsInOrder(Iterable<String> strings) => 98 StreamMatcher containsInOrder(Iterable<String> strings) =>
101 inOrder(strings.map((string) => consumeThrough(contains(string)))); 99 inOrder(strings.map((string) => consumeThrough(contains(string))));
102 100
103 /// Runs the test executable with the package root set properly. 101 /// Runs the test executable with the package root set properly.
104 /// 102 ///
105 /// If [forwardStdio] is true, the standard output and error from the process 103 /// If [forwardStdio] is true, the standard output and error from the process
106 /// will be printed as part of the parent test. This is used for debugging. 104 /// will be printed as part of the parent test. This is used for debugging.
107 ScheduledProcess runTest(List args, {String reporter, 105 ScheduledProcess runTest(List<String> args, {String reporter,
108 int concurrency, Map<String, String> environment, 106 int concurrency, Map<String, String> environment,
109 bool forwardStdio: false}) { 107 bool forwardStdio: false}) {
110 concurrency ??= 1; 108 concurrency ??= 1;
111 109
112 var allArgs = [ 110 var allArgs = [
113 p.absolute(p.join(packageDir, 'bin/test.dart')), 111 p.absolute(p.join(packageDir, 'bin/test.dart')),
114 "--package-root=${p.join(packageDir, 'packages')}", 112 "--package-root=${p.join(packageDir, 'packages')}",
115 "--concurrency=$concurrency" 113 "--concurrency=$concurrency"
116 ]; 114 ];
117 if (reporter != null) allArgs.add("--reporter=$reporter"); 115 if (reporter != null) allArgs.add("--reporter=$reporter");
118 allArgs.addAll(args); 116 allArgs.addAll(args);
119 117
120 if (environment == null) environment = {}; 118 if (environment == null) environment = {};
121 environment.putIfAbsent("_DART_TEST_TESTING", () => "true"); 119 environment.putIfAbsent("_DART_TEST_TESTING", () => "true");
122 120
123 var process = runDart(allArgs, 121 var process = runDart(allArgs,
124 environment: environment, 122 environment: environment,
125 description: "dart bin/test.dart"); 123 description: "dart bin/test.dart");
126 124
127 if (forwardStdio) { 125 if (forwardStdio) {
128 process.stdoutStream().listen(print); 126 process.stdoutStream().listen(print);
129 process.stderrStream().listen(print); 127 process.stderrStream().listen(print);
130 } 128 }
131 129
132 return process; 130 return process;
133 } 131 }
134 132
135 /// Runs Dart. 133 /// Runs Dart.
136 ScheduledProcess runDart(List args, {Map<String, String> environment, 134 ScheduledProcess runDart(List<String> args, {Map<String, String> environment,
137 String description}) { 135 String description}) {
138 var allArgs = Platform.executableArguments.map((arg) { 136 var allArgs = Platform.executableArguments.map((arg) {
139 // The package root might be relative, so we need to make it absolute if 137 // The package root might be relative, so we need to make it absolute if
140 // we're going to run in a different working directory. 138 // we're going to run in a different working directory.
141 if (!arg.startsWith("--package-root=")) return arg; 139 if (!arg.startsWith("--package-root=")) return arg;
142 return "--package-root=" + 140 return "--package-root=" +
143 p.absolute(p.fromUri(arg.substring("--package-root=".length))); 141 p.absolute(p.fromUri(arg.substring("--package-root=".length)));
144 }).toList()..addAll(args); 142 }).toList()..addAll(args);
145 143
146 return new ScheduledProcess.start( 144 return new ScheduledProcess.start(
147 p.absolute(Platform.resolvedExecutable), allArgs, 145 p.absolute(Platform.resolvedExecutable), allArgs,
148 workingDirectory: _sandbox, 146 workingDirectory: _sandbox,
149 environment: environment, 147 environment: environment,
150 description: description); 148 description: description);
151 } 149 }
152 150
153 /// Runs Pub. 151 /// Runs Pub.
154 ScheduledProcess runPub(List args, {Map<String, String> environment}) { 152 ScheduledProcess runPub(List args, {Map<String, String> environment}) {
155 return new ScheduledProcess.start( 153 return new ScheduledProcess.start(
156 _pubPath, args, 154 _pubPath, args,
157 workingDirectory: _sandbox, 155 workingDirectory: _sandbox,
158 environment: environment, 156 environment: environment,
159 description: "pub ${args.first}"); 157 description: "pub ${args.first}");
160 } 158 }
161 159
162 /// Runs "pub serve". 160 /// Runs "pub serve".
163 /// 161 ///
164 /// This returns assigns [_pubServePort] to a future that will complete to the 162 /// This returns assigns [_pubServePort] to a future that will complete to the
165 /// port of the "pub serve" instance. 163 /// port of the "pub serve" instance.
166 ScheduledProcess runPubServe({List args, String workingDirectory, 164 ScheduledProcess runPubServe({List<String> args, String workingDirectory,
167 Map<String, String> environment}) { 165 Map<String, String> environment}) {
168 _pubServePortCompleter = new Completer(); 166 _pubServePortCompleter = new Completer();
169 currentSchedule.onComplete.schedule(() => _pubServePortCompleter = null); 167 currentSchedule.onComplete.schedule(() => _pubServePortCompleter = null);
170 168
171 var allArgs = ['serve', '--port', '0']; 169 var allArgs = ['serve', '--port', '0'];
172 if (args != null) allArgs.addAll(args); 170 if (args != null) allArgs.addAll(args);
173 171
174 var pub = runPub(allArgs, environment: environment); 172 var pub = runPub(allArgs, environment: environment);
175 173
176 schedule(() async { 174 schedule(() async {
177 var match; 175 var match;
178 while (match == null) { 176 while (match == null) {
179 var line = await pub.stdout.next(); 177 var line = await pub.stdout.next();
180 match = _servingRegExp.firstMatch(line); 178 match = _servingRegExp.firstMatch(line);
181 } 179 }
182 _pubServePortCompleter.complete(int.parse(match[1])); 180 _pubServePortCompleter.complete(int.parse(match[1]));
183 }, "waiting for pub serve to emit its port number"); 181 }, "waiting for pub serve to emit its port number");
184 182
185 return pub; 183 return pub;
186 } 184 }
OLDNEW
« no previous file with comments | « lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698