From 4a1d57f98d6746505eb154973c08b059db0efd32 Mon Sep 17 00:00:00 2001 From: Dhruv Maradiya Date: Thu, 16 Jan 2025 22:23:16 +0530 Subject: [PATCH] removed support for all uncommon flags --- pkgs/coverage/CHANGELOG.md | 2 +- pkgs/coverage/bin/collect_coverage.dart | 21 +++++---- pkgs/coverage/bin/format_coverage.dart | 51 ++++++++++----------- pkgs/coverage/bin/test_with_coverage.dart | 2 +- pkgs/coverage/lib/src/coverage_options.dart | 50 +------------------- pkgs/coverage/pubspec.yaml | 2 +- 6 files changed, 41 insertions(+), 87 deletions(-) diff --git a/pkgs/coverage/CHANGELOG.md b/pkgs/coverage/CHANGELOG.md index d641416d1..bc4ddab72 100644 --- a/pkgs/coverage/CHANGELOG.md +++ b/pkgs/coverage/CHANGELOG.md @@ -1,4 +1,4 @@ -## 1.11.2 +## 1.12.0 - Introduced support for specifying coverage flags through a YAML file. diff --git a/pkgs/coverage/bin/collect_coverage.dart b/pkgs/coverage/bin/collect_coverage.dart index c2e122ea6..1808fdb17 100644 --- a/pkgs/coverage/bin/collect_coverage.dart +++ b/pkgs/coverage/bin/collect_coverage.dart @@ -10,6 +10,7 @@ import 'package:args/args.dart'; import 'package:coverage/src/collect.dart'; import 'package:coverage/src/coverage_options.dart'; import 'package:logging/logging.dart'; +import 'package:path/path.dart' as p; import 'package:stack_trace/stack_trace.dart'; Future main(List arguments) async { @@ -71,14 +72,9 @@ Options _parseArgs(List arguments, CoverageOptions defaultOptions) { help: 'remote VM port. DEPRECATED: use --uri', defaultsTo: '8181') ..addOption('uri', abbr: 'u', help: 'VM observatory service URI') - ..addOption('out', - abbr: 'o', - defaultsTo: defaultOptions.output, - help: 'output: may be file or stdout') + ..addOption('out', abbr: 'o', help: 'output: may be file or stdout') ..addOption('connect-timeout', - defaultsTo: defaultOptions.connectTimeout?.toString(), - abbr: 't', - help: 'connect timeout in seconds') + abbr: 't', help: 'connect timeout in seconds') ..addMultiOption('scope-output', defaultsTo: defaultOptions.scopeOutput, help: 'restrict coverage results so that only scripts that start with ' @@ -135,12 +131,17 @@ Options _parseArgs(List arguments, CoverageOptions defaultOptions) { final scopedOutput = args['scope-output'] as List; IOSink out; - if (args['out'] == 'stdout') { + final outPath = args['out'] as String?; + if (outPath == 'stdout' || + (outPath == null && defaultOptions.output == null)) { out = stdout; } else { - final outfile = File(args['out'] as String)..createSync(recursive: true); - out = outfile.openWrite(); + final outFilePath = p.absolute( + p.normalize(outPath ?? '${defaultOptions.output}/coverage.json')); + final outFile = File(outFilePath)..createSync(recursive: true); + out = outFile.openWrite(); } + final timeout = (args['connect-timeout'] == null) ? null : Duration(seconds: int.parse(args['connect-timeout'] as String)); diff --git a/pkgs/coverage/bin/format_coverage.dart b/pkgs/coverage/bin/format_coverage.dart index b2b64d7e1..d4a0ec7eb 100644 --- a/pkgs/coverage/bin/format_coverage.dart +++ b/pkgs/coverage/bin/format_coverage.dart @@ -147,34 +147,31 @@ Environment parseArgs(List arguments, CoverageOptions defaultOptions) { ..addOption('package', help: 'root directory of the package', defaultsTo: defaultOptions.packagePath) - ..addOption('in', - abbr: 'i', - help: 'input(s): may be file or directory', - defaultsTo: defaultOptions.input) - ..addOption('out', - abbr: 'o', - defaultsTo: defaultOptions.output, - help: 'output: may be file or stdout') - ..addMultiOption('report-on', - help: 'which directories or files to report coverage on', - defaultsTo: defaultOptions.reportOn) + ..addOption( + 'in', + abbr: 'i', + help: 'input(s): may be file or directory', + ) + ..addOption('out', abbr: 'o', help: 'output: may be file or stdout') + ..addMultiOption( + 'report-on', + help: 'which directories or files to report coverage on', + ) ..addOption( 'workers', abbr: 'j', - defaultsTo: defaultOptions.workers.toString(), + defaultsTo: '1', help: 'number of workers', ) ..addOption('bazel-workspace', defaultsTo: '', help: 'Bazel workspace directory') ..addOption('base-directory', abbr: 'b', - defaultsTo: defaultOptions.baseDirectory, help: 'the base directory relative to which source paths are output') ..addFlag('bazel', defaultsTo: false, help: 'use Bazel-style path resolution') ..addFlag('pretty-print', abbr: 'r', - defaultsTo: defaultOptions.prettyPrint, negatable: false, help: 'convert line coverage data to pretty print format') ..addFlag('pretty-print-func', @@ -186,14 +183,9 @@ Environment parseArgs(List arguments, CoverageOptions defaultOptions) { help: 'convert branch coverage data to pretty print format') ..addFlag('lcov', abbr: 'l', - defaultsTo: defaultOptions.lcov, negatable: false, help: 'convert coverage data to lcov format') - ..addFlag('verbose', - abbr: 'v', - defaultsTo: defaultOptions.verbose, - negatable: false, - help: 'verbose output') + ..addFlag('verbose', abbr: 'v', negatable: false, help: 'verbose output') ..addFlag( 'check-ignore', abbr: 'c', @@ -203,7 +195,7 @@ Environment parseArgs(List arguments, CoverageOptions defaultOptions) { ) ..addMultiOption( 'ignore-files', - defaultsTo: defaultOptions.ignoreFiles, + defaultsTo: [], help: 'Ignore files by glob patterns', ) ..addFlag('help', abbr: 'h', negatable: false, help: 'show this help'); @@ -247,19 +239,26 @@ Environment parseArgs(List arguments, CoverageOptions defaultOptions) { fail('Package spec "${args["package"]}" not found, or not a directory.'); } - if (args['in'] == null) fail('No input files given.'); - final input = p.absolute(p.normalize(args['in'] as String)); + if (args['in'] == null && defaultOptions.output == null) { + fail('No input files given.'); + } + final inputPath = + args['in'] as String? ?? '${defaultOptions.output}/coverage.json'; + final input = p.absolute(p.normalize(inputPath)); if (!FileSystemEntity.isDirectorySync(input) && !FileSystemEntity.isFileSync(input)) { fail('Provided input "${args["in"]}" is neither a directory nor a file.'); } IOSink output; - if (args['out'] == 'stdout') { + final outPath = args['out'] as String?; + if (outPath == 'stdout' || + (outPath == null && defaultOptions.output == null)) { output = stdout; } else { - final outpath = p.absolute(p.normalize(args['out'] as String)); - final outfile = File(outpath)..createSync(recursive: true); + final outFilePath = p + .absolute(p.normalize(outPath ?? '${defaultOptions.output}/lcov.info')); + final outfile = File(outFilePath)..createSync(recursive: true); output = outfile.openWrite(); } diff --git a/pkgs/coverage/bin/test_with_coverage.dart b/pkgs/coverage/bin/test_with_coverage.dart index c0bb37789..046db9786 100644 --- a/pkgs/coverage/bin/test_with_coverage.dart +++ b/pkgs/coverage/bin/test_with_coverage.dart @@ -55,7 +55,7 @@ ArgParser _createArgParser(CoverageOptions defaultOptions) => ArgParser() ..addOption( 'package', help: 'Root directory of the package to test.', - defaultsTo: defaultOptions.packageName, + defaultsTo: defaultOptions.packagePath, ) ..addOption( 'package-name', diff --git a/pkgs/coverage/lib/src/coverage_options.dart b/pkgs/coverage/lib/src/coverage_options.dart index dbb9da8b9..180455ae5 100644 --- a/pkgs/coverage/lib/src/coverage_options.dart +++ b/pkgs/coverage/lib/src/coverage_options.dart @@ -4,75 +4,39 @@ import 'package:cli_config/cli_config.dart'; class CoverageOptions { const CoverageOptions({ required this.output, - this.connectTimeout, required this.scopeOutput, - required this.resumeIsolates, required this.functionCoverage, required this.branchCoverage, required this.packagePath, - this.input, - this.reportOn, - required this.workers, - this.baseDirectory, - required this.prettyPrint, - required this.lcov, - required this.ignoreFiles, this.packageName, required this.testScript, - required this.verbose, }); factory CoverageOptions.fromConfig( Config options, CoverageOptions defaultOptions) { return CoverageOptions( output: options.optionalString('out') ?? defaultOptions.output, - connectTimeout: options.optionalInt('connect_timeout') ?? - defaultOptions.connectTimeout, scopeOutput: options.optionalStringList('scope_output') ?? defaultOptions.scopeOutput, - resumeIsolates: options.optionalBool('resume_isolates') ?? - defaultOptions.resumeIsolates, functionCoverage: options.optionalBool('function_coverage') ?? defaultOptions.functionCoverage, branchCoverage: options.optionalBool('branch_coverage') ?? defaultOptions.branchCoverage, packagePath: options.optionalString('package') ?? defaultOptions.packagePath, - input: options.optionalString('in') ?? defaultOptions.input, - reportOn: - options.optionalStringList('report_on') ?? defaultOptions.reportOn, - workers: options.optionalInt('workers') ?? defaultOptions.workers, - baseDirectory: options.optionalString('base_directory') ?? - defaultOptions.baseDirectory, - prettyPrint: - options.optionalBool('pretty_print') ?? defaultOptions.prettyPrint, - lcov: options.optionalBool('lcov') ?? defaultOptions.lcov, - ignoreFiles: options.optionalStringList('ignore_files') ?? - defaultOptions.ignoreFiles, packageName: options.optionalString('package_name') ?? defaultOptions.packageName, testScript: options.optionalString('test') ?? defaultOptions.testScript, - verbose: options.optionalBool('verbose') ?? defaultOptions.verbose, ); } - final String output; - final int? connectTimeout; + final String? output; final List scopeOutput; - final bool resumeIsolates; final bool functionCoverage; final bool branchCoverage; final String packagePath; - final String? input; - final List? reportOn; - final int workers; - final String? baseDirectory; - final bool prettyPrint; - final bool lcov; - final List ignoreFiles; final String? packageName; final String testScript; - final bool verbose; } class CoverageOptionsProvider { @@ -103,22 +67,12 @@ class CoverageOptionsProvider { } static const defaultOptions = CoverageOptions( - output: 'stdout', - connectTimeout: null, + output: null, scopeOutput: [], - resumeIsolates: false, functionCoverage: false, branchCoverage: false, packagePath: '.', - input: null, - reportOn: null, - workers: 1, - baseDirectory: '.', - prettyPrint: false, - lcov: false, - ignoreFiles: [], packageName: null, testScript: 'test', - verbose: false, ); } diff --git a/pkgs/coverage/pubspec.yaml b/pkgs/coverage/pubspec.yaml index a8f4f84b5..6bd452470 100644 --- a/pkgs/coverage/pubspec.yaml +++ b/pkgs/coverage/pubspec.yaml @@ -1,5 +1,5 @@ name: coverage -version: 1.11.2 +version: 1.12.0 description: Coverage data manipulation and formatting repository: https://github.com/dart-lang/tools/tree/main/pkgs/coverage issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Acoverage