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

Unified Diff: pkg/analyzer_experimental/bin/coverage.dart

Issue 16964008: Code coverage, something is working now. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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: pkg/analyzer_experimental/bin/coverage.dart
diff --git a/pkg/analyzer_experimental/bin/coverage.dart b/pkg/analyzer_experimental/bin/coverage.dart
index 87be02e8ee0686cc8a5e38e7fdba742bf3c2f702..967c6e08af898edef1ee5a45eddedea7301511f3 100644
--- a/pkg/analyzer_experimental/bin/coverage.dart
+++ b/pkg/analyzer_experimental/bin/coverage.dart
@@ -4,19 +4,86 @@
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;
Bob Nystrom 2013/06/17 21:30:11 Is there anything you were specifically trying to
scheglov 2013/06/18 06:11:04 Done.
+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
Bob Nystrom 2013/06/17 21:30:11 Remove this?
scheglov 2013/06/18 06:11:04 Done.
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');
Bob Nystrom 2013/06/17 21:30:11 Long line. For Dart, we stick to 80 columns.
scheglov 2013/06/18 06:11:04 Done.
+
+
+printUsage([var description = 'Code coverage tool for Dart.']) {
+ var buffer = new StringBuffer();
+ buffer.write(description);
+ buffer.write('\n\n');
+ buffer.write('Usage: coverage [options] <script>\n\n');
+ buffer.write('${_argParser.getUsage()}\n\n');
pquitslund 2013/06/17 20:15:58 Cascade here?
scheglov 2013/06/17 20:50:59 Done.
+ print(buffer.toString());
Bob Nystrom 2013/06/17 21:30:11 Instead of building a buffer, I'd probably just pr
scheglov 2013/06/18 06:11:04 Done.
+}
+
+
+/// General error code.
+const ERROR = 1;

Powered by Google App Engine
This is Rietveld 408576698