Skip to content

Commit c3cbd55

Browse files
refactor: streamline argument parsing in coverage scripts
1 parent 781b2d7 commit c3cbd55

File tree

8 files changed

+6
-147
lines changed

8 files changed

+6
-147
lines changed

pkgs/coverage/bin/collect_coverage.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@ Options _parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
8585
'the provided package path are considered')
8686
..addFlag('wait-paused',
8787
abbr: 'w',
88-
defaultsTo: defaultOptions.waitPaused,
88+
defaultsTo: false,
8989
help: 'wait for all isolates to be paused before collecting coverage')
9090
..addFlag('resume-isolates',
91-
abbr: 'r',
92-
defaultsTo: defaultOptions.resumeIsolates,
93-
help: 'resume all isolates on exit')
91+
abbr: 'r', defaultsTo: false, help: 'resume all isolates on exit')
9492
..addFlag('include-dart',
95-
abbr: 'd',
96-
defaultsTo: defaultOptions.includeDart,
97-
help: 'include "dart:" libraries')
93+
abbr: 'd', defaultsTo: false, help: 'include "dart:" libraries')
9894
..addFlag('function-coverage',
9995
abbr: 'f',
10096
defaultsTo: defaultOptions.functionCoverage,

pkgs/coverage/bin/format_coverage.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ Environment parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
139139
'sdk-root',
140140
abbr: 's',
141141
help: 'path to the SDK root',
142-
defaultsTo: defaultOptions.sdkRoot,
143142
)
144143
..addOption(
145144
'packages',
@@ -166,28 +165,24 @@ Environment parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
166165
help: 'number of workers',
167166
)
168167
..addOption('bazel-workspace',
169-
defaultsTo: defaultOptions.bazelWorkspace,
170-
help: 'Bazel workspace directory')
168+
defaultsTo: '', help: 'Bazel workspace directory')
171169
..addOption('base-directory',
172170
abbr: 'b',
173171
defaultsTo: defaultOptions.baseDirectory,
174172
help: 'the base directory relative to which source paths are output')
175173
..addFlag('bazel',
176-
defaultsTo: defaultOptions.bazel,
177-
help: 'use Bazel-style path resolution')
174+
defaultsTo: false, help: 'use Bazel-style path resolution')
178175
..addFlag('pretty-print',
179176
abbr: 'r',
180177
defaultsTo: defaultOptions.prettyPrint,
181178
negatable: false,
182179
help: 'convert line coverage data to pretty print format')
183180
..addFlag('pretty-print-func',
184181
abbr: 'f',
185-
defaultsTo: defaultOptions.prettyPrintFunc,
186182
negatable: false,
187183
help: 'convert function coverage data to pretty print format')
188184
..addFlag('pretty-print-branch',
189185
negatable: false,
190-
defaultsTo: defaultOptions.prettyPrintBranch,
191186
help: 'convert branch coverage data to pretty print format')
192187
..addFlag('lcov',
193188
abbr: 'l',
@@ -202,7 +197,6 @@ Environment parseArgs(List<String> arguments, CoverageOptions defaultOptions) {
202197
..addFlag(
203198
'check-ignore',
204199
abbr: 'c',
205-
defaultsTo: defaultOptions.checkIgnore,
206200
negatable: false,
207201
help: 'check for coverage ignore comments.'
208202
' Not supported in web coverage.',

pkgs/coverage/lib/src/coverage_options.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,16 @@ class CoverageOptions {
66
required this.output,
77
this.connectTimeout,
88
required this.scopeOutput,
9-
required this.waitPaused,
109
required this.resumeIsolates,
11-
required this.includeDart,
1210
required this.functionCoverage,
1311
required this.branchCoverage,
14-
this.sdkRoot,
1512
required this.packagePath,
1613
this.input,
1714
this.reportOn,
1815
required this.workers,
19-
required this.bazelWorkspace,
2016
this.baseDirectory,
21-
required this.bazel,
2217
required this.prettyPrint,
23-
required this.prettyPrintFunc,
24-
required this.prettyPrintBranch,
2518
required this.lcov,
26-
required this.checkIgnore,
2719
required this.ignoreFiles,
2820
this.packageName,
2921
required this.testScript,
@@ -38,37 +30,23 @@ class CoverageOptions {
3830
defaultOptions.connectTimeout,
3931
scopeOutput: options.optionalStringList('scope_output') ??
4032
defaultOptions.scopeOutput,
41-
waitPaused:
42-
options.optionalBool('wait_paused') ?? defaultOptions.waitPaused,
4333
resumeIsolates: options.optionalBool('resume_isolates') ??
4434
defaultOptions.resumeIsolates,
45-
includeDart:
46-
options.optionalBool('include_dart') ?? defaultOptions.includeDart,
4735
functionCoverage: options.optionalBool('function_coverage') ??
4836
defaultOptions.functionCoverage,
4937
branchCoverage: options.optionalBool('branch_coverage') ??
5038
defaultOptions.branchCoverage,
51-
sdkRoot: options.optionalString('sdk_root') ?? defaultOptions.sdkRoot,
5239
packagePath:
5340
options.optionalString('package') ?? defaultOptions.packagePath,
5441
input: options.optionalString('in') ?? defaultOptions.input,
5542
reportOn:
5643
options.optionalStringList('report_on') ?? defaultOptions.reportOn,
5744
workers: options.optionalInt('workers') ?? defaultOptions.workers,
58-
bazelWorkspace: options.optionalString('bazel_workspace') ??
59-
defaultOptions.bazelWorkspace,
6045
baseDirectory: options.optionalString('base_directory') ??
6146
defaultOptions.baseDirectory,
62-
bazel: options.optionalBool('bazel') ?? defaultOptions.bazel,
6347
prettyPrint:
6448
options.optionalBool('pretty_print') ?? defaultOptions.prettyPrint,
65-
prettyPrintFunc: options.optionalBool('pretty_print_func') ??
66-
defaultOptions.prettyPrintFunc,
67-
prettyPrintBranch: options.optionalBool('pretty_print_branch') ??
68-
defaultOptions.prettyPrintBranch,
6949
lcov: options.optionalBool('lcov') ?? defaultOptions.lcov,
70-
checkIgnore:
71-
options.optionalBool('check_ignore') ?? defaultOptions.checkIgnore,
7250
ignoreFiles: options.optionalStringList('ignore_files') ??
7351
defaultOptions.ignoreFiles,
7452
packageName:
@@ -81,24 +59,16 @@ class CoverageOptions {
8159
final String output;
8260
final int? connectTimeout;
8361
final List<String> scopeOutput;
84-
final bool waitPaused;
8562
final bool resumeIsolates;
86-
final bool includeDart;
8763
final bool functionCoverage;
8864
final bool branchCoverage;
89-
final String? sdkRoot;
9065
final String packagePath;
9166
final String? input;
9267
final List<String>? reportOn;
9368
final int workers;
94-
final String bazelWorkspace;
9569
final String? baseDirectory;
96-
final bool bazel;
9770
final bool prettyPrint;
98-
final bool prettyPrintFunc;
99-
final bool prettyPrintBranch;
10071
final bool lcov;
101-
final bool checkIgnore;
10272
final List<String> ignoreFiles;
10373
final String? packageName;
10474
final String testScript;
@@ -136,24 +106,16 @@ class CoverageOptionsProvider {
136106
output: 'stdout',
137107
connectTimeout: null,
138108
scopeOutput: [],
139-
waitPaused: false,
140109
resumeIsolates: false,
141-
includeDart: false,
142110
functionCoverage: false,
143111
branchCoverage: false,
144-
sdkRoot: null,
145112
packagePath: '.',
146113
input: null,
147114
reportOn: null,
148115
workers: 1,
149-
bazelWorkspace: '',
150116
baseDirectory: '.',
151-
bazel: false,
152117
prettyPrint: false,
153-
prettyPrintFunc: false,
154-
prettyPrintBranch: false,
155118
lcov: false,
156-
checkIgnore: false,
157119
ignoreFiles: [],
158120
packageName: null,
159121
testScript: 'test',

pkgs/coverage/test/collect_coverage_config_test.dart

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ void main() {
1515

1616
expect(collectedCoverage.scopeOutput, defaults.scopeOutput);
1717
expect(collectedCoverage.resumeIsolates, defaults.resumeIsolates);
18-
expect(collectedCoverage.waitPaused, defaults.waitPaused);
1918
expect(collectedCoverage.functionCoverage, defaults.functionCoverage);
2019
expect(collectedCoverage.branchCoverage, defaults.branchCoverage);
2120
expect(collectedCoverage.connectTimeout, defaults.connectTimeout);
22-
expect(collectedCoverage.includeDart, defaults.includeDart);
2321
expect(collectedCoverage.output, defaults.output);
2422
});
2523

@@ -28,19 +26,13 @@ void main() {
2826
parseArgsFormatCoverage(defaultInputArgs, defaults);
2927

3028
expect(formattedCoverage.baseDirectory, defaults.baseDirectory);
31-
expect(formattedCoverage.bazel, defaults.bazel);
32-
expect(formattedCoverage.bazelWorkspace, defaults.bazelWorkspace);
33-
expect(formattedCoverage.checkIgnore, defaults.checkIgnore);
3429
expect(formattedCoverage.input, 'coverage.json');
3530
expect(formattedCoverage.lcov, defaults.lcov);
3631
expect(formattedCoverage.output, defaults.output);
3732
expect(formattedCoverage.packagePath, defaults.packagePath);
3833
expect(formattedCoverage.prettyPrint, defaults.prettyPrint);
39-
expect(formattedCoverage.prettyPrintFunc, defaults.prettyPrintFunc);
40-
expect(formattedCoverage.prettyPrintBranch, defaults.prettyPrintBranch);
4134
expect(formattedCoverage.reportOn, defaults.reportOn);
4235
expect(formattedCoverage.ignoreFiles, defaults.ignoreFiles);
43-
expect(formattedCoverage.sdkRoot, defaults.sdkRoot);
4436
expect(formattedCoverage.verbose, defaults.verbose);
4537
expect(formattedCoverage.workers, defaults.workers);
4638
});
@@ -72,28 +64,20 @@ void main() {
7264
// Verify collect coverage yaml values
7365
expect(collectedCoverage.scopeOutput, ['lib', 'src']);
7466
expect(collectedCoverage.resumeIsolates, isFalse);
75-
expect(collectedCoverage.waitPaused, isTrue);
7667
expect(collectedCoverage.functionCoverage, isTrue);
7768
expect(collectedCoverage.branchCoverage, isFalse);
7869
expect(collectedCoverage.connectTimeout, 30);
79-
expect(collectedCoverage.includeDart, isFalse);
8070
expect(collectedCoverage.output, 'coverage');
8171

8272
// Verify format coverage yaml values
8373
expect(formattedCoverage.baseDirectory, '.');
84-
expect(formattedCoverage.bazel, isFalse);
85-
expect(formattedCoverage.bazelWorkspace, '');
86-
expect(formattedCoverage.checkIgnore, isFalse);
8774
expect(formattedCoverage.input, 'coverage.json');
8875
expect(formattedCoverage.lcov, isTrue);
8976
expect(formattedCoverage.output, 'coverage');
9077
expect(formattedCoverage.packagePath, '.');
9178
expect(formattedCoverage.prettyPrint, isFalse);
92-
expect(formattedCoverage.prettyPrintFunc, isFalse);
93-
expect(formattedCoverage.prettyPrintBranch, isFalse);
9479
expect(formattedCoverage.reportOn, ['lib', 'bin']);
9580
expect(formattedCoverage.ignoreFiles, ['test']);
96-
expect(formattedCoverage.sdkRoot, '.');
9781
expect(formattedCoverage.verbose, isTrue);
9882
expect(formattedCoverage.workers, 2);
9983

@@ -123,9 +107,7 @@ void main() {
123107
// Verify collect coverage yaml values
124108
expect(collectedCoverage.output, 'custom_coverage.json');
125109
expect(collectedCoverage.scopeOutput, ['lib', 'test']);
126-
expect(collectedCoverage.resumeIsolates, isTrue);
127110
expect(collectedCoverage.functionCoverage, isFalse);
128-
expect(collectedCoverage.includeDart, isTrue);
129111
expect(collectedCoverage.connectTimeout, 20);
130112

131113
// Verify format coverage yaml values
@@ -135,7 +117,6 @@ void main() {
135117
expect(formattedCoverage.ignoreFiles, ['example']);
136118
expect(formattedCoverage.reportOn, ['lib']);
137119
expect(formattedCoverage.prettyPrint, isTrue);
138-
expect(formattedCoverage.prettyPrintFunc, isFalse);
139120

140121
// Verify test with coverage yaml values
141122
expect(testCoverage.packageName, 'Custom Dart Package');
@@ -155,20 +136,15 @@ void main() {
155136

156137
// Verify collect coverage yaml values
157138
expect(collectedCoverage.scopeOutput, ['lib', 'tools']);
158-
expect(collectedCoverage.includeDart, isFalse);
159139
expect(collectedCoverage.branchCoverage, isFalse);
160-
expect(collectedCoverage.waitPaused, isFalse);
161140
expect(collectedCoverage.connectTimeout, 15);
162141
expect(collectedCoverage.functionCoverage, isTrue);
163142

164143
// Verify format coverage yaml values
165-
expect(formattedCoverage.bazel, isTrue);
166-
expect(formattedCoverage.checkIgnore, isTrue);
167144
expect(formattedCoverage.input, 'custom_coverage.json');
168145
expect(formattedCoverage.output, 'custom_lcov.info');
169146
expect(formattedCoverage.packagePath, '.');
170147
expect(formattedCoverage.reportOn, ['src', 'scripts']);
171-
expect(formattedCoverage.sdkRoot, './dart-sdk');
172148

173149
// Verify test with coverage yaml values
174150
expect(testCoverage.packageName, 'coverage');
@@ -188,8 +164,6 @@ void main() {
188164
'--out=coverage.json',
189165
'--scope-output=lib',
190166
'--connect-timeout=10',
191-
'--resume-isolates',
192-
'--no-wait-paused',
193167
'--no-function-coverage',
194168
'--branch-coverage',
195169
], configuredOptions);
@@ -211,8 +185,6 @@ void main() {
211185
// Verify collect coverage command line args
212186
expect(collectedCoverage.output, 'coverage.json');
213187
expect(collectedCoverage.scopeOutput, ['lib']);
214-
expect(collectedCoverage.resumeIsolates, isTrue);
215-
expect(collectedCoverage.waitPaused, isFalse);
216188
expect(collectedCoverage.functionCoverage, isFalse);
217189
expect(collectedCoverage.branchCoverage, isTrue);
218190
expect(collectedCoverage.connectTimeout, 10);
@@ -245,28 +217,20 @@ void main() {
245217
// Verify collect coverage defaults
246218
expect(collectedCoverage.scopeOutput, isEmpty);
247219
expect(collectedCoverage.resumeIsolates, isFalse);
248-
expect(collectedCoverage.waitPaused, isFalse);
249220
expect(collectedCoverage.functionCoverage, isFalse);
250221
expect(collectedCoverage.branchCoverage, isFalse);
251222
expect(collectedCoverage.connectTimeout, isNull);
252-
expect(collectedCoverage.includeDart, isFalse);
253223
expect(collectedCoverage.output, 'stdout');
254224

255225
// Verify format coverage defaults
256226
expect(formattedCoverage.baseDirectory, '.');
257-
expect(formattedCoverage.bazel, isFalse);
258-
expect(formattedCoverage.bazelWorkspace, '');
259-
expect(formattedCoverage.checkIgnore, isFalse);
260227
expect(formattedCoverage.input, 'coverage.json');
261228
expect(formattedCoverage.lcov, isFalse);
262229
expect(formattedCoverage.output, 'stdout');
263230
expect(formattedCoverage.packagePath, '.');
264231
expect(formattedCoverage.prettyPrint, isFalse);
265-
expect(formattedCoverage.prettyPrintFunc, isFalse);
266-
expect(formattedCoverage.prettyPrintBranch, isFalse);
267232
expect(formattedCoverage.reportOn, isNull);
268233
expect(formattedCoverage.ignoreFiles, isEmpty);
269-
expect(formattedCoverage.sdkRoot, isNull);
270234
expect(formattedCoverage.verbose, isFalse);
271235
expect(formattedCoverage.workers, 1);
272236

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
out: "coverage"
22
connect-timeout: 30
33
scope-output: ["lib", "src"]
4-
resume-isolates: false
5-
include-dart: false
64
function-coverage: true
75
branch-coverage: false
8-
wait-paused: true
96
base-directory: "."
10-
bazel: false
11-
bazel-workspace: null
127
in: "coverage.json"
138
package: "."
149
package-name: "My Dart Package"
1510
report-on: ["lib", "bin"]
1611
ignore-files: ["test"]
17-
sdk-root: "."
1812
workers: 2
19-
check-ignore: false
2013
verbose: true
2114
lcov: true
2215
pretty-print: false
23-
pretty-print-func: false
24-
pretty-print-branch: false
2516
test: "test"

pkgs/coverage/test/test_coverage_options/partial_fields1.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ out: 'custom_coverage.json'
22
scope-output:
33
- 'lib'
44
- 'test'
5-
resume-isolates: true
6-
function-coverage: false
7-
include-dart: true
85
connect-timeout: 20
96
lcov: false
107
verbose: false
@@ -14,5 +11,4 @@ ignore-files:
1411
report-on:
1512
- 'lib'
1613
pretty-print: true
17-
pretty-print-func: false
1814
package-name: 'Custom Dart Package'
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
scope-output:
22
- 'lib'
33
- 'tools'
4-
include-dart: false
54
branch-coverage: false
6-
wait-paused: false
75
connect-timeout: 15
86

9-
bazel: true
10-
check-ignore: true
117
in: 'custom_coverage.json'
128
out: 'custom_lcov.info'
139
package: '.'
1410
report-on:
1511
- 'src'
1612
- 'scripts'
17-
sdk-root: './dart-sdk'
1813

1914
test: 'custom_test'
2015
function-coverage: true

0 commit comments

Comments
 (0)