-
Notifications
You must be signed in to change notification settings - Fork 104
coverage: Allow specifying coverage flags via a yaml file
#1954
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
Merged
liamappelbe
merged 21 commits into
dart-lang:main
from
Dhruv-Maradiya:coverage-flags-yaml
Feb 4, 2025
Merged
Changes from 12 commits
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 ff390a9
Added test cases to cover YAML configuration options.
Dhruv-Maradiya 9cd8dce
Bump version to 1.11.2 and add support for specifying coverage flags …
Dhruv-Maradiya 949917c
feat: update dependencies and refactor coverage options handling usin…
Dhruv-Maradiya eebc68f
test: refactor test cases to align with updated coverage options hand…
Dhruv-Maradiya bb0eb60
test: optimized test cases
Dhruv-Maradiya 781b2d7
fix: set default VM service port to 8181 in test_with_coverage.dart
Dhruv-Maradiya c3cbd55
refactor: streamline argument parsing in coverage scripts
Dhruv-Maradiya 4a1d57f
removed support for all uncommon flags
Dhruv-Maradiya c610504
refactor: changed test cases to align with updated coverage options
Dhruv-Maradiya b1efad0
change: Resolve output and package paths to absolute paths; add upwar…
Dhruv-Maradiya beac649
refactor: use absolute and normalize instead of canonicalize for path…
Dhruv-Maradiya 8d3ca0c
refactor: made argument parser visible for testing
Dhruv-Maradiya c6452f7
test: add coverage options file locator tests
Dhruv-Maradiya fcfca3f
refactor: handling path in test using canonicalize
Dhruv-Maradiya 69858bf
refactor: update coverage output paths to use 'coverage_data' directory
Dhruv-Maradiya 6c85d14
refactor: improve file creation logic for coverage output paths
Dhruv-Maradiya fc28600
refactor: update coverage output paths to use 'var/coverage_data' dir…
Dhruv-Maradiya a8a3844
refactor: formatted the code
Dhruv-Maradiya 28c6c7b
Merge branch 'dart-lang:main' into coverage-flags-yaml
Dhruv-Maradiya e7a315a
fix: make coverage output paths relative on Ubuntu and macOS by remov…
Dhruv-Maradiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import 'dart:io'; | ||
| import 'package:cli_config/cli_config.dart'; | ||
| import 'package:path/path.dart' as path; | ||
|
|
||
| class CoverageOptions { | ||
| const CoverageOptions({ | ||
| this.outputDirectory, | ||
| required this.scopeOutput, | ||
| required this.functionCoverage, | ||
| required this.branchCoverage, | ||
| required this.packageDirectory, | ||
| this.packageName, | ||
| required this.testScript, | ||
| }); | ||
|
|
||
| factory CoverageOptions.fromConfig( | ||
| Config options, CoverageOptions defaultOptions, String? optionsFilePath) { | ||
| var outputDirectory = options.optionalString('output_directory') ?? | ||
| defaultOptions.outputDirectory; | ||
| var packageDirectory = options.optionalString('package_directory') ?? | ||
| defaultOptions.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( | ||
| outputDirectory: outputDirectory, | ||
| scopeOutput: options.optionalStringList('scope_output') ?? | ||
| defaultOptions.scopeOutput, | ||
| functionCoverage: options.optionalBool('function_coverage') ?? | ||
| defaultOptions.functionCoverage, | ||
| branchCoverage: options.optionalBool('branch_coverage') ?? | ||
| defaultOptions.branchCoverage, | ||
| packageDirectory: packageDirectory, | ||
| packageName: | ||
| options.optionalString('package_name') ?? defaultOptions.packageName, | ||
| testScript: | ||
| options.optionalString('test_script') ?? defaultOptions.testScript, | ||
| ); | ||
| } | ||
|
|
||
| final String? outputDirectory; | ||
| final List<String> scopeOutput; | ||
| final bool functionCoverage; | ||
| final bool branchCoverage; | ||
| final String packageDirectory; | ||
| final String? packageName; | ||
| final String testScript; | ||
| } | ||
|
|
||
| class CoverageOptionsProvider { | ||
| CoverageOptionsProvider({ | ||
| String? filePath, | ||
| }) { | ||
| final file = _getOptionsFile(filePath); | ||
| final fileContents = file?.readAsStringSync(); | ||
|
|
||
| final isFileEmpty = fileContents?.isEmpty ?? false; | ||
|
|
||
| // Pass null to fileContents if the file is empty | ||
|
Dhruv-Maradiya marked this conversation as resolved.
|
||
| final options = Config.fromConfigFileContents( | ||
| fileContents: isFileEmpty ? null : fileContents, | ||
| fileSourceUri: file?.uri, | ||
| ); | ||
|
|
||
| coverageOptions = | ||
| CoverageOptions.fromConfig(options, defaultOptions, optionsFilePath); | ||
| } | ||
|
|
||
| late final CoverageOptions coverageOptions; | ||
| late final String? optionsFilePath; | ||
| static const defaultFilePath = 'coverage_options.yaml'; | ||
|
|
||
| File? _getOptionsFile(String? filePath) { | ||
| filePath ??= _findOptionsFilePath(); | ||
|
|
||
| optionsFilePath = filePath != null ? path.canonicalize(filePath) : null; | ||
|
Dhruv-Maradiya marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (optionsFilePath == null) { | ||
| return null; | ||
| } | ||
|
|
||
| final file = File(optionsFilePath!); | ||
| return file.existsSync() ? file : null; | ||
| } | ||
|
|
||
| String? _findOptionsFilePath() { | ||
| var currentDir = Directory.current; | ||
|
|
||
| while (true) { | ||
| final pubSpecFilePath = path.join(currentDir.path, 'pubspec.yaml'); | ||
| if (File(pubSpecFilePath).existsSync()) { | ||
| return path.join(currentDir.path, defaultFilePath); | ||
| } | ||
| final parentDir = currentDir.parent; | ||
| if (parentDir.path == currentDir.path) { | ||
| return null; | ||
| } | ||
| currentDir = parentDir; | ||
| } | ||
| } | ||
|
|
||
| static const defaultOptions = CoverageOptions( | ||
| outputDirectory: null, | ||
| scopeOutput: [], | ||
| functionCoverage: false, | ||
| branchCoverage: false, | ||
| packageDirectory: '.', | ||
| packageName: null, | ||
| testScript: 'test', | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.