Skip to content

Commit

Permalink
test: refactor test cases to align with updated coverage options hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
Dhruv-Maradiya committed Jan 7, 2025
1 parent 949917c commit eebc68f
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 394 deletions.
426 changes: 155 additions & 271 deletions pkgs/coverage/test/collect_coverage_config_test.dart

Large diffs are not rendered by default.

64 changes: 25 additions & 39 deletions pkgs/coverage/test/test_coverage_options/all_field.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
defaults:
collect_coverage:
uri: "http://127.0.0.1:8181/"
out: "coverage.json"
connect-timeout: 30
scope-output: ["lib/"]
resume-isolates: false
include-dart: false
function-coverage: true
branch-coverage: false
wait-paused: true

format_coverage:
base-directory: "."
bazel-workspace: null
in: "coverage.json"
out: "lcov.info"
package: "."
report-on: ["lib/", "bin/"]
ignore-files: ["test/"]
sdk-root: '.'
workers: 2
check-ignore: false
bazel: false
verbose: true
lcov: true
pretty-print: false
pretty-print-func: false
pretty-print-branch: false

test_with_coverage:
package: "."
package-name: "My Dart Package"
out: "test_coverage.json"
port: 8181
test: "test"
scope-output: ["lib/src/"]
function-coverage: true
branch-coverage: false
out: "coverage"
connect-timeout: 30
scope-output: ["lib", "src"]
resume-isolates: false
include-dart: false
function-coverage: true
branch-coverage: false
wait-paused: true
base-directory: "."
bazel: false
bazel-workspace: null
in: "coverage.json"
package: "."
package-name: "My Dart Package"
report-on: ["lib", "bin"]
ignore-files: ["test"]
sdk-root: "."
workers: 2
check-ignore: false
verbose: true
lcov: true
pretty-print: false
pretty-print-func: false
pretty-print-branch: false
test: "test"
53 changes: 0 additions & 53 deletions pkgs/coverage/test/test_coverage_options/partial_fields.dart

This file was deleted.

18 changes: 18 additions & 0 deletions pkgs/coverage/test/test_coverage_options/partial_fields1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
out: 'custom_coverage.json'
scope-output:
- 'lib'
- 'test'
resume-isolates: true
function-coverage: false
include-dart: true
connect-timeout: 20
lcov: false
verbose: false
base-directory: 'src'
ignore-files:
- 'example'
report-on:
- 'lib'
pretty-print: true
pretty-print-func: false
package-name: 'Custom Dart Package'
20 changes: 20 additions & 0 deletions pkgs/coverage/test/test_coverage_options/partial_fields2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
scope-output:
- 'lib'
- 'tools'
include-dart: false
branch-coverage: false
wait-paused: false
connect-timeout: 15

bazel: true
check-ignore: true
in: 'custom_coverage.json'
out: 'custom_lcov.info'
package: '.'
report-on:
- 'src'
- 'scripts'
sdk-root: './dart-sdk'

test: 'custom_test'
function-coverage: true
98 changes: 67 additions & 31 deletions pkgs/coverage/test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ extension ListTestExtension on List {
);
}

CollectCoverageOptions parseArgsCollectCoverage(
List<String> arguments, CollectCoverageOptions defaultOptions) {
CoverageOptions parseArgsCollectCoverage(
List<String> arguments, CoverageOptions defaultOptions) {
final parser = ArgParser()
..addOption('host', abbr: 'H')
..addOption('port', abbr: 'p')
..addOption('uri', abbr: 'u')
..addOption('out', abbr: 'o', defaultsTo: defaultOptions.out)
..addOption('out', abbr: 'o', defaultsTo: defaultOptions.output)
..addOption('connect-timeout',
abbr: 't', defaultsTo: defaultOptions.connectTimeout?.toString())
..addMultiOption('scope-output', defaultsTo: defaultOptions.scopeOutput)
Expand All @@ -115,31 +115,40 @@ CollectCoverageOptions parseArgsCollectCoverage(

final args = parser.parse(arguments);

String serviceUri;
if (args['uri'] == null && (args['host'] != null || args['port'] != null)) {
final host = args['host'] ?? defaultOptions.host;
final port = args['port'] ?? defaultOptions.port;

serviceUri = 'http://$host:$port/';
} else {
serviceUri = (args['uri'] ?? defaultOptions.uri) as String;
}

return CollectCoverageOptions(
uri: serviceUri,
out: args['out'] as String,
connectTimeout: int.tryParse(args['connect-timeout'] as String? ?? ''),
return CoverageOptions(
output: args['out'] as String,
connectTimeout: args['connect-timeout'] == null
? defaultOptions.connectTimeout
: int.parse(args['connect-timeout'] as String),
scopeOutput: args['scope-output'] as List<String>,
waitPaused: args['wait-paused'] as bool,
resumeIsolates: args['resume-isolates'] as bool,
includeDart: args['include-dart'] as bool,
functionCoverage: args['function-coverage'] as bool,
branchCoverage: args['branch-coverage'] as bool,
bazel: defaultOptions.bazel,
bazelWorkspace: defaultOptions.bazelWorkspace,
baseDirectory: defaultOptions.baseDirectory,
checkIgnore: defaultOptions.checkIgnore,
ignoreFiles: defaultOptions.ignoreFiles,
input: defaultOptions.input,
lcov: defaultOptions.lcov,
packagePath: defaultOptions.packagePath,
packageName: defaultOptions.packageName,
prettyPrint: defaultOptions.prettyPrint,
prettyPrintBranch: defaultOptions.prettyPrintBranch,
prettyPrintFunc: defaultOptions.prettyPrintFunc,
reportOn: defaultOptions.reportOn,
sdkRoot: defaultOptions.sdkRoot,
testScript: defaultOptions.testScript,
verbose: defaultOptions.verbose,
workers: defaultOptions.workers,

);
}

FormatCoverageOptions parseArgsFormatCoverage(
List<String> arguments, FormatCoverageOptions defaultOptions) {
CoverageOptions parseArgsFormatCoverage(
List<String> arguments, CoverageOptions defaultOptions) {
final parser = ArgParser()
..addOption('sdk-root', abbr: 's', defaultsTo: defaultOptions.sdkRoot)
..addOption('packages')
Expand Down Expand Up @@ -174,7 +183,7 @@ FormatCoverageOptions parseArgsFormatCoverage(

if (args['in'] == null) throw ArgumentError('Missing required argument: in');

return FormatCoverageOptions(
return CoverageOptions(
baseDirectory: args['base-directory'] as String?,
bazel: args['bazel'] as bool,
bazelWorkspace: args['bazel-workspace'] as String,
Expand All @@ -193,24 +202,33 @@ FormatCoverageOptions parseArgsFormatCoverage(
sdkRoot: args['sdk-root'] as String?,
verbose: args['verbose'] as bool,
workers: int.parse(args['workers'] as String),
branchCoverage: defaultOptions.branchCoverage,
functionCoverage: defaultOptions.functionCoverage,
connectTimeout: defaultOptions.connectTimeout,
includeDart: defaultOptions.includeDart,
packageName: defaultOptions.packageName,
resumeIsolates: defaultOptions.resumeIsolates,
scopeOutput: defaultOptions.scopeOutput,
waitPaused: defaultOptions.waitPaused,
testScript: defaultOptions.testScript,
);
}

Future<TestWithCoverageOptions> parseArgsTestWithCoverage(
List<String> arguments, TestWithCoverageOptions defaultOptions) async {
Future<CoverageOptions> parseArgsTestWithCoverage(
List<String> arguments, CoverageOptions defaultOptions) async {
final parser = ArgParser()
..addOption(
'package',
defaultsTo: defaultOptions.packageDir,
defaultsTo: defaultOptions.packagePath,
)
..addOption(
'package-name',
defaultsTo: defaultOptions.packageName,
)
..addOption('port', defaultsTo: defaultOptions.port)
..addOption('port')
..addOption(
'out',
defaultsTo: defaultOptions.outDir,
defaultsTo: defaultOptions.output,
abbr: 'o',
)
..addOption('test', defaultsTo: defaultOptions.testScript)
Expand All @@ -234,21 +252,39 @@ Future<TestWithCoverageOptions> parseArgsTestWithCoverage(
ArgumentError('Invalid package directory: $packageDir');
}

final packageName = (args['package-name'] as String?) ??
final packageName =
args['package-name'] ??
await _packageNameFromConfig(packageDir);
if (packageName == null) {
ArgumentError('Could not determine package name');
}

return TestWithCoverageOptions(
packageDir: packageDir,
packageName: packageName,
outDir: (args['out'] as String?) ?? 'coverage',
port: args['port'] as String,
return CoverageOptions(
packagePath: packageDir,
packageName: packageName as String,
output: (args['out'] as String?) ?? 'coverage',
testScript: args['test'] as String,
functionCoverage: args['function-coverage'] as bool,
branchCoverage: args['branch-coverage'] as bool,
scopeOutput: args['scope-output'] as List<String>,
bazel: defaultOptions.bazel,
bazelWorkspace: defaultOptions.bazelWorkspace,
baseDirectory: defaultOptions.baseDirectory,
checkIgnore: defaultOptions.checkIgnore,
connectTimeout: defaultOptions.connectTimeout,
ignoreFiles: defaultOptions.ignoreFiles,
includeDart: defaultOptions.includeDart,
input: defaultOptions.input,
lcov: defaultOptions.lcov,
prettyPrint: defaultOptions.prettyPrint,
prettyPrintBranch: defaultOptions.prettyPrintBranch,
prettyPrintFunc: defaultOptions.prettyPrintFunc,
reportOn: defaultOptions.reportOn,
resumeIsolates: defaultOptions.resumeIsolates,
sdkRoot: defaultOptions.sdkRoot,
verbose: defaultOptions.verbose,
waitPaused: defaultOptions.waitPaused,
workers: defaultOptions.workers,
);
}

Expand Down

0 comments on commit eebc68f

Please sign in to comment.