Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
| 10 import 'package:scheduled_test/scheduled_process.dart'; | 10 import 'package:scheduled_test/scheduled_process.dart'; |
| 11 import 'package:scheduled_test/scheduled_test.dart'; | 11 import 'package:scheduled_test/scheduled_test.dart'; |
| 12 | 12 |
| 13 import '../test_pub.dart'; | 13 import '../test_pub.dart'; |
| 14 | 14 |
| 15 /// The pub process running "pub serve". | 15 /// The pub process running "pub serve". |
| 16 ScheduledProcess _pubServer; | 16 ScheduledProcess _pubServer; |
| 17 | 17 |
| 18 /// The ephemeral port assigned to the running server. | 18 /// The ephemeral port assigned to the running server. |
| 19 int _port; | 19 int _port; |
| 20 | 20 |
| 21 /// The code for a transformer that renames ".txt" files to ".out" and adds a | |
| 22 /// ".out" suffix. | |
| 23 const REWRITE_TRANSFORMER = """ | |
| 24 import 'dart:async'; | |
| 25 | |
| 26 import 'package:barback/barback.dart'; | |
| 27 | |
| 28 class RewriteTransformer extends Transformer { | |
| 29 RewriteTransformer(); | |
| 30 | |
| 31 String get allowedExtensions => '.txt'; | |
| 32 | |
| 33 Future apply(Transform transform) { | |
| 34 return transform.primaryInput | |
| 35 .then((input) => input.readAsString()) | |
| 36 .then((contents) { | |
| 37 var id = transform.primaryId.changeExtension(".out"); | |
| 38 transform.addOutput(new Asset.fromString(id, "\$contents.out")); | |
| 39 }); | |
| 40 } | |
| 41 } | |
| 42 """; | |
| 43 | |
| 21 /// Schedules starting the "pub serve" process. | 44 /// Schedules starting the "pub serve" process. |
| 22 /// | 45 /// |
| 23 /// If [shouldInstallFirst] is `true`, validates that pub install is run first. | 46 /// If [shouldInstallFirst] is `true`, validates that pub install is run first. |
| 24 void startPubServe({bool shouldInstallFirst: false}) { | 47 /// Returns the `pub serve` process. |
|
Bob Nystrom
2013/08/27 22:12:30
Newline above this.
nweiz
2013/08/28 20:45:23
Done.
| |
| 48 ScheduledProcess startPubServe({bool shouldInstallFirst: false}) { | |
| 25 // Use port 0 to get an ephemeral port. | 49 // Use port 0 to get an ephemeral port. |
| 26 _pubServer = startPub(args: ["serve", "--port=0"]); | 50 _pubServer = startPub(args: ["serve", "--port=0"]); |
| 27 | 51 |
| 28 if (shouldInstallFirst) { | 52 if (shouldInstallFirst) { |
| 29 expect(_pubServer.nextLine(), | 53 expect(_pubServer.nextLine(), |
| 30 completion(startsWith("Dependencies have changed"))); | 54 completion(startsWith("Dependencies have changed"))); |
| 31 expect(_pubServer.nextLine(), | 55 expect(_pubServer.nextLine(), |
| 32 completion(startsWith("Resolving dependencies..."))); | 56 completion(startsWith("Resolving dependencies..."))); |
| 33 expect(_pubServer.nextLine(), | 57 expect(_pubServer.nextLine(), |
| 34 completion(equals("Dependencies installed!"))); | 58 completion(equals("Dependencies installed!"))); |
| 35 } | 59 } |
| 36 | 60 |
| 37 expect(_pubServer.nextLine().then(_parsePort), completes); | 61 expect(_pubServer.nextLine().then(_parsePort), completes); |
| 62 return _pubServer; | |
| 38 } | 63 } |
| 39 | 64 |
| 40 /// Parses the port number from the "Serving blah on localhost:1234" line | 65 /// Parses the port number from the "Serving blah on localhost:1234" line |
| 41 /// printed by pub serve. | 66 /// printed by pub serve. |
| 42 void _parsePort(String line) { | 67 void _parsePort(String line) { |
| 43 var match = new RegExp(r"localhost:(\d+)").firstMatch(line); | 68 var match = new RegExp(r"localhost:(\d+)").firstMatch(line); |
| 44 assert(match != null); | 69 assert(match != null); |
| 45 _port = int.parse(match[1]); | 70 _port = int.parse(match[1]); |
| 46 } | 71 } |
| 47 | 72 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 return _pubServer.nextLine().then((line) { | 104 return _pubServer.nextLine().then((line) { |
| 80 if (line.contains("successfully")) return; | 105 if (line.contains("successfully")) return; |
| 81 | 106 |
| 82 // This line wasn't it, so ignore it and keep trying. | 107 // This line wasn't it, so ignore it and keep trying. |
| 83 return nextLine(); | 108 return nextLine(); |
| 84 }); | 109 }); |
| 85 } | 110 } |
| 86 | 111 |
| 87 schedule(nextLine); | 112 schedule(nextLine); |
| 88 } | 113 } |
| OLD | NEW |