| Index: pkg/analyzer_experimental/bin/coverage.dart
|
| diff --git a/pkg/analyzer_experimental/bin/coverage.dart b/pkg/analyzer_experimental/bin/coverage.dart
|
| index 87be02e8ee0686cc8a5e38e7fdba742bf3c2f702..72d52b00e7adaaf6ab72a8bd5e6bae89f87f1478 100644
|
| --- a/pkg/analyzer_experimental/bin/coverage.dart
|
| +++ b/pkg/analyzer_experimental/bin/coverage.dart
|
| @@ -4,19 +4,87 @@
|
|
|
| library runtime.coverage;
|
|
|
| -import "package:logging/logging.dart" as log;
|
| +import 'dart:io';
|
|
|
| -import 'package:analyzer_experimental/src/services/runtime/coverage_impl.dart';
|
| +import 'package:args/args.dart' show ArgParser, ArgResults;
|
|
|
| +import 'package:analyzer_experimental/src/services/runtime/log.dart' as log;
|
| +import 'package:analyzer_experimental/src/services/runtime/coverage/coverage_impl.dart';
|
| +
|
| +// /Users/scheglov/Source/Dart/dart/pkg/analyzer_experimental/test/generated/all_test.dart
|
|
|
| main() {
|
| - var logger = log.Logger.root;
|
| - logger.level = log.Level.ALL;
|
| - logger.onRecord.listen((log.LogRecord record) {
|
| - String levelString = record.level.toString();
|
| - while (levelString.length < 6) levelString += ' ';
|
| - print('${record.time}: ${levelString} ${record.message}');
|
| - });
|
| - // TODO(scheglov) get script from options
|
| - new CoverageServer('/Users/scheglov/dart/Test/bin').start();
|
| -}
|
| + ArgResults options;
|
| + try {
|
| + options = _argParser.parse(new Options().arguments);
|
| + } on FormatException catch (e) {
|
| + print(e.message);
|
| + print('Run "coverage --help" to see available options.');
|
| + exit(ERROR);
|
| + }
|
| +
|
| + if (options['help']) {
|
| + printUsage();
|
| + return;
|
| + }
|
| +
|
| + // No script to run.
|
| + if (options.rest.isEmpty) {
|
| + printUsage('<No script to run specified>');
|
| + exit(ERROR);
|
| + }
|
| +
|
| + // More than one script specified.
|
| + if (options.rest.length != 1) {
|
| + print('<Only one script should be specified>');
|
| + exit(ERROR);
|
| + }
|
| +
|
| + var scriptPath = options.rest[0];
|
| +
|
| + // Validate that script file exists.
|
| + if (!new File(scriptPath).existsSync()) {
|
| + print('<File "$scriptPath" does not exist>');
|
| + exit(ERROR);
|
| + }
|
| +
|
| + // Prepare output file path.
|
| + var outPath = options['out'];
|
| + if (outPath == null) {
|
| + printUsage('No --out specified.');
|
| + exit(ERROR);
|
| + }
|
| +
|
| + // Configure logigng.
|
| + log.everything();
|
| + log.toConsole();
|
| +
|
| + // Run script.
|
| + runServerApplication(scriptPath, outPath);
|
| +}
|
| +
|
| +
|
| +final ArgParser _argParser = new ArgParser()
|
| + ..addFlag('help', negatable: false, help: 'Print this usage information.')
|
| + ..addOption(
|
| + 'level',
|
| + help: 'The level of the coverage.',
|
| + allowed: ['method', 'block', 'statement'],
|
| + defaultsTo: 'statement')
|
| + ..addOption('out', help: 'The output file with statistics.')
|
| + ..addOption('port', help: 'The port to run server on, if 0 select any.', defaultsTo: '0');
|
| +
|
| +
|
| +printUsage([var description = 'Code coverage tool for Dart.']) {
|
| + var buffer = new StringBuffer();
|
| + var usage = _argParser.getUsage();
|
| + buffer.write(
|
| + '$description\n\n'
|
| + 'Usage: coverage [options] <script>\n\n'
|
| + '$usage\n\n');
|
| + print(buffer.toString());
|
| +}
|
| +
|
| +
|
| +/// General error code.
|
| +const ERROR = 1;
|
|
|