OLD | NEW |
1 library test_pub; | 1 library test_pub; |
2 import 'dart:async'; | 2 import 'dart:async'; |
3 import 'dart:convert'; | 3 import 'dart:convert'; |
4 import 'dart:io'; | 4 import 'dart:io'; |
5 import 'dart:math'; | 5 import 'dart:math'; |
6 import 'package:http/testing.dart'; | 6 import 'package:http/testing.dart'; |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:scheduled_test/scheduled_process.dart'; | 8 import 'package:scheduled_test/scheduled_process.dart'; |
9 import 'package:scheduled_test/scheduled_server.dart'; | 9 import 'package:scheduled_test/scheduled_server.dart'; |
10 import 'package:scheduled_test/scheduled_stream.dart'; | 10 import 'package:scheduled_test/scheduled_stream.dart'; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 schedule( | 235 schedule( |
236 () => renameDir(p.join(sandboxDir, from), p.join(sandboxDir, to)), | 236 () => renameDir(p.join(sandboxDir, from), p.join(sandboxDir, to)), |
237 'renaming $from to $to'); | 237 'renaming $from to $to'); |
238 } | 238 } |
239 void scheduleSymlink(String target, String symlink) { | 239 void scheduleSymlink(String target, String symlink) { |
240 schedule( | 240 schedule( |
241 () => createSymlink(p.join(sandboxDir, target), p.join(sandboxDir, symlink
)), | 241 () => createSymlink(p.join(sandboxDir, target), p.join(sandboxDir, symlink
)), |
242 'symlinking $target to $symlink'); | 242 'symlinking $target to $symlink'); |
243 } | 243 } |
244 void schedulePub({List args, output, error, outputJson, int exitCode: | 244 void schedulePub({List args, output, error, outputJson, int exitCode: |
245 exit_codes.SUCCESS}) { | 245 exit_codes.SUCCESS, Map<String, String> environment}) { |
246 assert(output == null || outputJson == null); | 246 assert(output == null || outputJson == null); |
247 var pub = startPub(args: args); | 247 var pub = startPub(args: args, environment: environment); |
248 pub.shouldExit(exitCode); | 248 pub.shouldExit(exitCode); |
249 var failures = []; | 249 var failures = []; |
250 var stderr; | 250 var stderr; |
251 expect( | 251 expect( |
252 Future.wait( | 252 Future.wait( |
253 [pub.stdoutStream().toList(), pub.stderrStream().toList()]).then((resu
lts) { | 253 [pub.stdoutStream().toList(), pub.stderrStream().toList()]).then((resu
lts) { |
254 var stdout = results[0].join("\n"); | 254 var stdout = results[0].join("\n"); |
255 stderr = results[1].join("\n"); | 255 stderr = results[1].join("\n"); |
256 if (outputJson == null) { | 256 if (outputJson == null) { |
257 _validateOutput(failures, 'stdout', output, stdout); | 257 _validateOutput(failures, 'stdout', output, stdout); |
(...skipping 28 matching lines...) Expand all Loading... |
286 Map getPubTestEnvironment([String tokenEndpoint]) { | 286 Map getPubTestEnvironment([String tokenEndpoint]) { |
287 var environment = {}; | 287 var environment = {}; |
288 environment['_PUB_TESTING'] = 'true'; | 288 environment['_PUB_TESTING'] = 'true'; |
289 environment['PUB_CACHE'] = _pathInSandbox(cachePath); | 289 environment['PUB_CACHE'] = _pathInSandbox(cachePath); |
290 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; | 290 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; |
291 if (tokenEndpoint != null) { | 291 if (tokenEndpoint != null) { |
292 environment['_PUB_TEST_TOKEN_ENDPOINT'] = tokenEndpoint.toString(); | 292 environment['_PUB_TEST_TOKEN_ENDPOINT'] = tokenEndpoint.toString(); |
293 } | 293 } |
294 return environment; | 294 return environment; |
295 } | 295 } |
296 ScheduledProcess startPub({List args, Future<String> tokenEndpoint}) { | 296 ScheduledProcess startPub({List args, Future<String> tokenEndpoint, Map<String, |
| 297 String> environment}) { |
297 ensureDir(_pathInSandbox(appPath)); | 298 ensureDir(_pathInSandbox(appPath)); |
298 var dartBin = Platform.executable; | 299 var dartBin = Platform.executable; |
299 if (dartBin.contains(Platform.pathSeparator)) { | 300 if (dartBin.contains(Platform.pathSeparator)) { |
300 dartBin = p.absolute(dartBin); | 301 dartBin = p.absolute(dartBin); |
301 } | 302 } |
302 var pubPath = p.join(p.dirname(dartBin), 'snapshots/pub.dart.snapshot'); | 303 var pubPath = p.join(p.dirname(dartBin), 'snapshots/pub.dart.snapshot'); |
303 var dartArgs = [pubPath, '--verbose']; | 304 var dartArgs = [pubPath, '--verbose']; |
304 dartArgs.addAll(args); | 305 dartArgs.addAll(args); |
305 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 306 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
306 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { | 307 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
307 var environment = getPubTestEnvironment(tokenEndpoint); | 308 var pubEnvironment = getPubTestEnvironment(tokenEndpoint); |
308 if (_hasServer) { | 309 if (_hasServer) { |
309 return port.then((p) { | 310 return port.then((p) { |
310 environment['PUB_HOSTED_URL'] = "http://localhost:$p"; | 311 pubEnvironment['PUB_HOSTED_URL'] = "http://localhost:$p"; |
311 return environment; | 312 return pubEnvironment; |
312 }); | 313 }); |
313 } | 314 } |
314 return environment; | 315 return pubEnvironment; |
| 316 }).then((pubEnvironment) { |
| 317 if (environment != null) pubEnvironment.addAll(environment); |
| 318 return pubEnvironment; |
315 }); | 319 }); |
316 return new PubProcess.start( | 320 return new PubProcess.start( |
317 dartBin, | 321 dartBin, |
318 dartArgs, | 322 dartArgs, |
319 environment: environmentFuture, | 323 environment: environmentFuture, |
320 workingDirectory: _pathInSandbox(appPath), | 324 workingDirectory: _pathInSandbox(appPath), |
321 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 325 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
322 } | 326 } |
323 class PubProcess extends ScheduledProcess { | 327 class PubProcess extends ScheduledProcess { |
324 Stream<Pair<log.Level, String>> _log; | 328 Stream<Pair<log.Level, String>> _log; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 bool matches(item, Map matchState) { | 604 bool matches(item, Map matchState) { |
601 if (item is! Pair) return false; | 605 if (item is! Pair) return false; |
602 return _firstMatcher.matches(item.first, matchState) && | 606 return _firstMatcher.matches(item.first, matchState) && |
603 _lastMatcher.matches(item.last, matchState); | 607 _lastMatcher.matches(item.last, matchState); |
604 } | 608 } |
605 Description describe(Description description) { | 609 Description describe(Description description) { |
606 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 610 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
607 } | 611 } |
608 } | 612 } |
609 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 613 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |