| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library runtime.coverage; | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 import 'package:analyzer/src/services/runtime/coverage/coverage_impl.dart'; | |
| 10 import 'package:analyzer/src/services/runtime/log.dart' as log; | |
| 11 import 'package:args/args.dart'; | |
| 12 | |
| 13 | |
| 14 /// General error code. | |
| 15 const ERROR = 1; | |
| 16 | |
| 17 | |
| 18 final ArgParser _argParser = new ArgParser() | |
| 19 ..addFlag('help', negatable: false, help: 'Print this usage information.') | |
| 20 ..addOption( | |
| 21 'level', | |
| 22 help: 'The level of the coverage.', | |
| 23 allowed: ['method', 'block', 'statement'], | |
| 24 defaultsTo: 'statement') | |
| 25 ..addOption('out', help: 'The output file with statistics.') | |
| 26 ..addOption( | |
| 27 'port', | |
| 28 help: 'The port to run server on, if 0 select any.', | |
| 29 defaultsTo: '0'); | |
| 30 | |
| 31 | |
| 32 main(args) { | |
| 33 ArgResults options; | |
| 34 try { | |
| 35 options = _argParser.parse(args); | |
| 36 } on FormatException catch (e) { | |
| 37 print(e.message); | |
| 38 print('Run "coverage --help" to see available options.'); | |
| 39 exit(ERROR); | |
| 40 } | |
| 41 | |
| 42 if (options['help']) { | |
| 43 printUsage(); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 // No script to run. | |
| 48 if (options.rest.isEmpty) { | |
| 49 printUsage('<No script to run specified>'); | |
| 50 exit(ERROR); | |
| 51 } | |
| 52 | |
| 53 // More than one script specified. | |
| 54 if (options.rest.length != 1) { | |
| 55 print('<Only one script should be specified>'); | |
| 56 exit(ERROR); | |
| 57 } | |
| 58 | |
| 59 var scriptPath = options.rest[0]; | |
| 60 | |
| 61 // Validate that script file exists. | |
| 62 if (!new File(scriptPath).existsSync()) { | |
| 63 print('<File "$scriptPath" does not exist>'); | |
| 64 exit(ERROR); | |
| 65 } | |
| 66 | |
| 67 // Prepare output file path. | |
| 68 var outPath = options['out']; | |
| 69 if (outPath == null) { | |
| 70 printUsage('No --out specified.'); | |
| 71 exit(ERROR); | |
| 72 } | |
| 73 | |
| 74 // Configure logigng. | |
| 75 log.everything(); | |
| 76 log.toConsole(); | |
| 77 | |
| 78 // Run script. | |
| 79 runServerApplication(scriptPath, outPath); | |
| 80 } | |
| 81 | |
| 82 | |
| 83 printUsage([var description = 'Code coverage tool for Dart.']) { | |
| 84 var usage = _argParser.usage; | |
| 85 print('$description\n'); | |
| 86 print('Usage: coverage [options] <script>\n'); | |
| 87 print('$usage\n'); | |
| 88 } | |
| OLD | NEW |