Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS 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 runtime.coverage; | 5 library runtime.coverage; |
| 6 | 6 |
| 7 import "package:logging/logging.dart" as log; | 7 import "dart:io"; |
| 8 | 8 |
| 9 import 'package:analyzer_experimental/src/services/runtime/coverage_impl.dart'; | 9 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.
| |
| 10 | |
| 11 import 'package:analyzer_experimental/src/services/runtime/log.dart' as log; | |
| 12 import 'package:analyzer_experimental/src/services/runtime/coverage/coverage_imp l.dart'; | |
| 13 | |
| 14 // /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.
| |
| 15 | |
| 16 main() { | |
| 17 ArgResults options; | |
| 18 try { | |
| 19 options = _argParser.parse(new Options().arguments); | |
| 20 } on FormatException catch (e) { | |
| 21 print(e.message); | |
| 22 print('Run "coverage --help" to see available options.'); | |
| 23 exit(ERROR); | |
| 24 } | |
| 25 | |
| 26 if (options['help']) { | |
| 27 printUsage(); | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 // No script to run. | |
| 32 if (options.rest.isEmpty) { | |
| 33 printUsage('<No script to run specified>'); | |
| 34 exit(ERROR); | |
| 35 } | |
| 36 | |
| 37 // More than one script specified. | |
| 38 if (options.rest.length != 1) { | |
| 39 print('<Only one script should be specified>'); | |
| 40 exit(ERROR); | |
| 41 } | |
| 42 | |
| 43 var scriptPath = options.rest[0]; | |
| 44 | |
| 45 // Validate that script file exists. | |
| 46 if (!new File(scriptPath).existsSync()) { | |
| 47 print('<File "$scriptPath" does not exist>'); | |
| 48 exit(ERROR); | |
| 49 } | |
| 50 | |
| 51 // Prepare output file path. | |
| 52 var outPath = options['out']; | |
| 53 if (outPath == null) { | |
| 54 printUsage('No --out specified.'); | |
| 55 exit(ERROR); | |
| 56 } | |
| 57 | |
| 58 // Configure logigng. | |
| 59 log.everything(); | |
| 60 log.toConsole(); | |
| 61 | |
| 62 // Run script. | |
| 63 runServerApplication(scriptPath, outPath); | |
| 64 } | |
| 10 | 65 |
| 11 | 66 |
| 12 main() { | 67 final ArgParser _argParser = new ArgParser() |
| 13 var logger = log.Logger.root; | 68 ..addFlag('help', negatable: false, help: 'Print this usage information.') |
| 14 logger.level = log.Level.ALL; | 69 ..addOption( |
| 15 logger.onRecord.listen((log.LogRecord record) { | 70 'level', |
| 16 String levelString = record.level.toString(); | 71 help: 'The level of the coverage.', |
| 17 while (levelString.length < 6) levelString += ' '; | 72 allowed: ['method', 'block', 'statement'], |
| 18 print('${record.time}: ${levelString} ${record.message}'); | 73 defaultsTo: 'statement') |
| 19 }); | 74 ..addOption('out', help: 'The output file with statistics.') |
| 20 // TODO(scheglov) get script from options | 75 ..addOption('port', help: 'The port to run server on, if 0 select any.', def aultsTo: '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.
| |
| 21 new CoverageServer('/Users/scheglov/dart/Test/bin').start(); | 76 |
| 22 } | 77 |
| 78 printUsage([var description = 'Code coverage tool for Dart.']) { | |
| 79 var buffer = new StringBuffer(); | |
| 80 buffer.write(description); | |
| 81 buffer.write('\n\n'); | |
| 82 buffer.write('Usage: coverage [options] <script>\n\n'); | |
| 83 buffer.write('${_argParser.getUsage()}\n\n'); | |
|
pquitslund
2013/06/17 20:15:58
Cascade here?
scheglov
2013/06/17 20:50:59
Done.
| |
| 84 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.
| |
| 85 } | |
| 86 | |
| 87 | |
| 88 /// General error code. | |
| 89 const ERROR = 1; | |
| OLD | NEW |