Skip to content

Commit

Permalink
removed support for all uncommon flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruv-Maradiya committed Jan 16, 2025
1 parent c3cbd55 commit 4a1d57f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 87 deletions.
2 changes: 1 addition & 1 deletion pkgs/coverage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.11.2
## 1.12.0

- Introduced support for specifying coverage flags through a YAML file.

Expand Down
21 changes: 11 additions & 10 deletions pkgs/coverage/bin/collect_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main(List<String> arguments) async {
Expand Down Expand Up @@ -71,14 +72,9 @@ Options _parseArgs(List<String> 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 '
Expand Down Expand Up @@ -135,12 +131,17 @@ Options _parseArgs(List<String> arguments, CoverageOptions defaultOptions) {

final scopedOutput = args['scope-output'] as List<String>;
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));
Expand Down
51 changes: 25 additions & 26 deletions pkgs/coverage/bin/format_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,31 @@ Environment parseArgs(List<String> 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',
Expand All @@ -186,14 +183,9 @@ Environment parseArgs(List<String> 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',
Expand All @@ -203,7 +195,7 @@ Environment parseArgs(List<String> 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');
Expand Down Expand Up @@ -247,19 +239,26 @@ Environment parseArgs(List<String> 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();
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/bin/test_with_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
50 changes: 2 additions & 48 deletions pkgs/coverage/lib/src/coverage_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> scopeOutput;
final bool resumeIsolates;
final bool functionCoverage;
final bool branchCoverage;
final String packagePath;
final String? input;
final List<String>? reportOn;
final int workers;
final String? baseDirectory;
final bool prettyPrint;
final bool lcov;
final List<String> ignoreFiles;
final String? packageName;
final String testScript;
final bool verbose;
}

class CoverageOptionsProvider {
Expand Down Expand Up @@ -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,
);
}
2 changes: 1 addition & 1 deletion pkgs/coverage/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4a1d57f

Please sign in to comment.