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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return startPub(args: args, tokenEndpoint: tokenEndpoint); | 273 return startPub(args: args, tokenEndpoint: tokenEndpoint); |
274 } | 274 } |
275 void confirmPublish(ScheduledProcess pub) { | 275 void confirmPublish(ScheduledProcess pub) { |
276 pub.stdout.expect(startsWith('Publishing test_pkg 1.0.0 to ')); | 276 pub.stdout.expect(startsWith('Publishing test_pkg 1.0.0 to ')); |
277 pub.stdout.expect( | 277 pub.stdout.expect( |
278 emitsLines( | 278 emitsLines( |
279 "|-- LICENSE\n" "|-- lib\n" "| '-- test_pkg.dart\n" "'-- pubspec.yam
l\n" "\n" | 279 "|-- LICENSE\n" "|-- lib\n" "| '-- test_pkg.dart\n" "'-- pubspec.yam
l\n" "\n" |
280 "Looks great! Are you ready to upload your package (y/n)?")); | 280 "Looks great! Are you ready to upload your package (y/n)?")); |
281 pub.writeLine("y"); | 281 pub.writeLine("y"); |
282 } | 282 } |
| 283 String _pathInSandbox(String relPath) { |
| 284 return p.join(p.absolute(sandboxDir), relPath); |
| 285 } |
| 286 Map getPubTestEnvironment([Uri tokenEndpoint]) { |
| 287 var environment = {}; |
| 288 environment['_PUB_TESTING'] = 'true'; |
| 289 environment['PUB_CACHE'] = _pathInSandbox(cachePath); |
| 290 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; |
| 291 if (tokenEndpoint != null) { |
| 292 environment['_PUB_TEST_TOKEN_ENDPOINT'] = tokenEndpoint.toString(); |
| 293 } |
| 294 return environment; |
| 295 } |
283 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { | 296 ScheduledProcess startPub({List args, Future<Uri> tokenEndpoint}) { |
284 String pathInSandbox(String relPath) { | 297 ensureDir(_pathInSandbox(appPath)); |
285 return p.join(p.absolute(sandboxDir), relPath); | |
286 } | |
287 ensureDir(pathInSandbox(appPath)); | |
288 var dartBin = Platform.executable; | 298 var dartBin = Platform.executable; |
289 if (dartBin.contains(Platform.pathSeparator)) { | 299 if (dartBin.contains(Platform.pathSeparator)) { |
290 dartBin = p.absolute(dartBin); | 300 dartBin = p.absolute(dartBin); |
291 } | 301 } |
292 var pubPath = p.join(p.dirname(dartBin), 'snapshots/pub.dart.snapshot'); | 302 var pubPath = p.join(p.dirname(dartBin), 'snapshots/pub.dart.snapshot'); |
293 var dartArgs = [pubPath, '--verbose']; | 303 var dartArgs = [pubPath, '--verbose']; |
294 dartArgs.addAll(args); | 304 dartArgs.addAll(args); |
295 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); | 305 if (tokenEndpoint == null) tokenEndpoint = new Future.value(); |
296 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { | 306 var environmentFuture = tokenEndpoint.then((tokenEndpoint) { |
297 var environment = {}; | 307 var environment = getPubTestEnvironment(tokenEndpoint); |
298 environment['_PUB_TESTING'] = 'true'; | |
299 environment['PUB_CACHE'] = pathInSandbox(cachePath); | |
300 environment['_PUB_TEST_SDK_VERSION'] = "0.1.2+3"; | |
301 if (tokenEndpoint != null) { | |
302 environment['_PUB_TEST_TOKEN_ENDPOINT'] = tokenEndpoint.toString(); | |
303 } | |
304 if (_hasServer) { | 308 if (_hasServer) { |
305 return port.then((p) { | 309 return port.then((p) { |
306 environment['PUB_HOSTED_URL'] = "http://localhost:$p"; | 310 environment['PUB_HOSTED_URL'] = "http://localhost:$p"; |
307 return environment; | 311 return environment; |
308 }); | 312 }); |
309 } | 313 } |
310 return environment; | 314 return environment; |
311 }); | 315 }); |
312 return new PubProcess.start( | 316 return new PubProcess.start( |
313 dartBin, | 317 dartBin, |
314 dartArgs, | 318 dartArgs, |
315 environment: environmentFuture, | 319 environment: environmentFuture, |
316 workingDirectory: pathInSandbox(appPath), | 320 workingDirectory: _pathInSandbox(appPath), |
317 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); | 321 description: args.isEmpty ? 'pub' : 'pub ${args.first}'); |
318 } | 322 } |
319 class PubProcess extends ScheduledProcess { | 323 class PubProcess extends ScheduledProcess { |
320 Stream<Pair<log.Level, String>> _log; | 324 Stream<Pair<log.Level, String>> _log; |
321 Stream<String> _stdout; | 325 Stream<String> _stdout; |
322 Stream<String> _stderr; | 326 Stream<String> _stderr; |
323 PubProcess.start(executable, arguments, {workingDirectory, environment, | 327 PubProcess.start(executable, arguments, {workingDirectory, environment, |
324 String description, Encoding encoding: UTF8}) | 328 String description, Encoding encoding: UTF8}) |
325 : super.start( | 329 : super.start( |
326 executable, | 330 executable, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 bool matches(item, Map matchState) { | 600 bool matches(item, Map matchState) { |
597 if (item is! Pair) return false; | 601 if (item is! Pair) return false; |
598 return _firstMatcher.matches(item.first, matchState) && | 602 return _firstMatcher.matches(item.first, matchState) && |
599 _lastMatcher.matches(item.last, matchState); | 603 _lastMatcher.matches(item.last, matchState); |
600 } | 604 } |
601 Description describe(Description description) { | 605 Description describe(Description description) { |
602 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); | 606 return description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]); |
603 } | 607 } |
604 } | 608 } |
605 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); | 609 StreamMatcher emitsLines(String output) => inOrder(output.split("\n")); |
OLD | NEW |