Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: Allow specifying coverage flags via a yaml file #1954

Merged
merged 21 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
99afba1
Implemented functionality to allows specifying coverage options and f…
Dhruv-Maradiya Dec 31, 2024
ff390a9
Added test cases to cover YAML configuration options.
Dhruv-Maradiya Dec 31, 2024
9cd8dce
Bump version to 1.11.2 and add support for specifying coverage flags …
Dhruv-Maradiya Dec 31, 2024
949917c
feat: update dependencies and refactor coverage options handling usin…
Dhruv-Maradiya Jan 7, 2025
eebc68f
test: refactor test cases to align with updated coverage options hand…
Dhruv-Maradiya Jan 7, 2025
bb0eb60
test: optimized test cases
Dhruv-Maradiya Jan 7, 2025
781b2d7
fix: set default VM service port to 8181 in test_with_coverage.dart
Dhruv-Maradiya Jan 7, 2025
c3cbd55
refactor: streamline argument parsing in coverage scripts
Dhruv-Maradiya Jan 9, 2025
4a1d57f
removed support for all uncommon flags
Dhruv-Maradiya Jan 16, 2025
c610504
refactor: changed test cases to align with updated coverage options
Dhruv-Maradiya Jan 16, 2025
b1efad0
change: Resolve output and package paths to absolute paths; add upwar…
Dhruv-Maradiya Jan 17, 2025
beac649
refactor: use absolute and normalize instead of canonicalize for path…
Dhruv-Maradiya Jan 20, 2025
8d3ca0c
refactor: made argument parser visible for testing
Dhruv-Maradiya Jan 23, 2025
c6452f7
test: add coverage options file locator tests
Dhruv-Maradiya Jan 23, 2025
fcfca3f
refactor: handling path in test using canonicalize
Dhruv-Maradiya Jan 27, 2025
69858bf
refactor: update coverage output paths to use 'coverage_data' directory
Dhruv-Maradiya Jan 29, 2025
6c85d14
refactor: improve file creation logic for coverage output paths
Dhruv-Maradiya Jan 30, 2025
fc28600
refactor: update coverage output paths to use 'var/coverage_data' dir…
Dhruv-Maradiya Feb 2, 2025
a8a3844
refactor: formatted the code
Dhruv-Maradiya Feb 3, 2025
28c6c7b
Merge branch 'dart-lang:main' into coverage-flags-yaml
Dhruv-Maradiya Feb 4, 2025
e7a315a
fix: make coverage output paths relative on Ubuntu and macOS by remov…
Dhruv-Maradiya Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkgs/coverage/bin/collect_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ Options _parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
(outPath == null && defaultOptions.outputDirectory == null)) {
out = stdout;
} else {
final outFilePath = p.canonicalize(
outPath ?? '${defaultOptions.outputDirectory}/coverage.json');
final outFilePath = p.normalize(outPath ??
p.absolute(defaultOptions.outputDirectory!, 'coverage.json'));
final outFile = File(outFilePath)..createSync(recursive: true);
out = outFile.openWrite();
}
Expand Down
9 changes: 4 additions & 5 deletions pkgs/coverage/bin/format_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ Environment parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
if (args['in'] == null && defaultOptions.outputDirectory == null) {
fail('No input files given.');
}
final inputPath = args['in'] as String? ??
'${defaultOptions.outputDirectory}/coverage.json';
final input = p.absolute(p.normalize(inputPath));
final input = p.normalize((args['in'] as String?) ??
p.absolute(defaultOptions.outputDirectory!, 'coverage.json'));
if (!FileSystemEntity.isDirectorySync(input) &&
!FileSystemEntity.isFileSync(input)) {
fail('Provided input "${args["in"]}" is neither a directory nor a file.');
Expand All @@ -256,8 +255,8 @@ Environment parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
(outPath == null && defaultOptions.outputDirectory == null)) {
output = stdout;
} else {
final outFilePath = p
.canonicalize(outPath ?? '${defaultOptions.outputDirectory}/lcov.info');
final outFilePath = p.normalize(
outPath ?? p.absolute(defaultOptions.outputDirectory!, 'lcov.info'));
final outfile = File(outFilePath)..createSync(recursive: true);
output = outfile.openWrite();
}
Expand Down
31 changes: 17 additions & 14 deletions pkgs/coverage/lib/src/coverage_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ class CoverageOptions {
});

factory CoverageOptions.fromConfig(
Config options, CoverageOptions defaultOptions, String optionsFilePath) {
Config options, CoverageOptions defaultOptions, String? optionsFilePath) {
var outputDirectory = options.optionalString('output_directory') ??
defaultOptions.outputDirectory;
var packageDirectory = options.optionalString('package_directory') ??
defaultOptions.packageDirectory;

if (outputDirectory != null && !path.isAbsolute(outputDirectory)) {
outputDirectory = path.canonicalize(
path.join(path.dirname(optionsFilePath), outputDirectory));
}
if (!path.isAbsolute(packageDirectory)) {
packageDirectory = path.canonicalize(
path.join(path.dirname(optionsFilePath), packageDirectory));
if (optionsFilePath != null) {
if (outputDirectory != null && !path.isAbsolute(outputDirectory)) {
outputDirectory = path.normalize(
path.absolute(path.dirname(optionsFilePath), outputDirectory));
}
if (!path.isAbsolute(packageDirectory)) {
packageDirectory = path.normalize(
path.absolute(path.dirname(optionsFilePath), packageDirectory));
}
}

return CoverageOptions(
Dhruv-Maradiya marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -74,18 +76,19 @@ class CoverageOptionsProvider {
}

late final CoverageOptions coverageOptions;
late final String optionsFilePath;
late final String? optionsFilePath;
static const defaultFilePath = 'coverage_options.yaml';

File? _getOptionsFile(String? filePath) {
filePath ??= _findOptionsFilePath();
if (filePath == null) {
throw StateError('Could not find a pubspec.yaml file.');
}

optionsFilePath = path.canonicalize(filePath);
optionsFilePath = filePath != null ? path.canonicalize(filePath) : null;
Dhruv-Maradiya marked this conversation as resolved.
Show resolved Hide resolved

if (optionsFilePath == null) {
return null;
}

final file = File(optionsFilePath);
final file = File(optionsFilePath!);
return file.existsSync() ? file : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ output-directory: 'custom_coverage'
scope-output:
- 'lib'
- 'test'
package-name: 'Custom Dart Package'
package-name: 'Custom Dart Package'
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ branch-coverage: false
output-directory: 'custom_lcov'
package-directory: '.'
test_script: 'custom_test'
function-coverage: true
function-coverage: true
Loading