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

Unified Diff: lib/src/executable.dart

Issue 1062523003: Add support for --pub-serve. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/executable.dart
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index fe403b2a1f26423aed50fcc52059e55c28de2aba..413343f58e5eb871c333f495a55d31fa5d8fb073 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -13,6 +13,7 @@ import 'dart:isolate';
import 'package:args/args.dart';
import 'package:stack_trace/stack_trace.dart';
+import 'package:yaml/yaml.dart';
import 'backend/test_platform.dart';
import 'runner/reporter/compact.dart';
@@ -25,6 +26,33 @@ import 'utils.dart';
/// The argument parser used to parse the executable arguments.
final _parser = new ArgParser(allowTrailingOptions: true);
+/// Returns whether the current package has a pubspec which uses the
+/// `test/pub_serve` transformer.
+bool get _usesTransformer {
+ if (!new File('pubspec.yaml').existsSync()) return false;
+ var contents = new File('pubspec.yaml').readAsStringSync();
+
+ var yaml;
+ try {
+ yaml = loadYaml(contents);
+ } on FormatException {
+ return false;
+ }
+
+ if (yaml is! Map) return false;
+
+ var transformers = yaml['transformers'];
+ if (transformers == null) return false;
+ if (transformers is! List) return false;
+
+ return transformers.any((transformer) {
+ if (transformer is String) return transformer == 'test/pub_serve';
+ if (transformer is! Map) return false;
+ if (transformer.keys.length != 1) return false;
+ return transformer.keys.single == 'test/pub_serve';
+ });
+}
+
void main(List<String> args) {
_parser.addFlag("help", abbr: "h", negatable: false,
help: "Shows this usage information.");
@@ -42,6 +70,10 @@ void main(List<String> args) {
allowed: TestPlatform.all.map((platform) => platform.identifier).toList(),
defaultsTo: 'vm',
allowMultiple: true);
+ _parser.addOption("pub-serve",
+ help: 'The port of a pub serve instance serving "test/".',
+ hide: !supportsPubServe,
+ valueHelp: 'port');
_parser.addFlag("color", defaultsTo: null,
help: 'Whether to use terminal colors.\n(auto-detected by default)');
@@ -62,9 +94,29 @@ void main(List<String> args) {
var color = options["color"];
if (color == null) color = canUseSpecialChars;
+ var pubServeUrl;
+ if (options["pub-serve"] != null) {
+ pubServeUrl = Uri.parse("http://localhost:${options['pub-serve']}");
+ if (!_usesTransformer) {
+ stderr.write('''
+When using --pub-serve, you must include the "test/pub_serve" transformer in
+your pubspec:
+
+transformers:
+- test/pub_serve:
+ \$include: test/**_test.dart
+''');
+ exitCode = exit_codes.data;
+ return;
+ }
+ }
+
var platforms = options["platform"].map(TestPlatform.find);
var loader = new Loader(platforms,
- packageRoot: options["package-root"], color: color);
+ pubServeUrl: pubServeUrl,
+ packageRoot: options["package-root"],
+ color: color);
+
new Future.sync(() {
var paths = options.rest;
if (paths.isEmpty) {
« no previous file with comments | « lib/pub_serve.dart ('k') | lib/src/runner/browser/server.dart » ('j') | lib/src/util/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698