| 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; |
| 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 |
| 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'); |
| 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 var usage = _argParser.getUsage(); |
| 81 buffer.write( |
| 82 '$description\n\n' |
| 83 'Usage: coverage [options] <script>\n\n' |
| 84 '$usage\n\n'); |
| 85 print(buffer.toString()); |
| 86 } |
| 87 |
| 88 |
| 89 /// General error code. |
| 90 const ERROR = 1; |
| OLD | NEW |