diff --git a/pkgs/coverage/test/collect_coverage_config_test.dart b/pkgs/coverage/test/collect_coverage_config_test.dart index 51f66cd20..8c64240c3 100644 --- a/pkgs/coverage/test/collect_coverage_config_test.dart +++ b/pkgs/coverage/test/collect_coverage_config_test.dart @@ -4,8 +4,6 @@ import 'package:test/test.dart'; import 'test_util.dart'; void main() { - final defaultInputArgs = ['--in=coverage.json']; - group('defaults when no yaml or command-line args provided', () { // Setup final defaults = CoverageOptionsProvider.defaultOptions; @@ -14,27 +12,17 @@ void main() { final collectedCoverage = parseArgsCollectCoverage([], defaults); expect(collectedCoverage.scopeOutput, defaults.scopeOutput); - expect(collectedCoverage.resumeIsolates, defaults.resumeIsolates); expect(collectedCoverage.functionCoverage, defaults.functionCoverage); expect(collectedCoverage.branchCoverage, defaults.branchCoverage); - expect(collectedCoverage.connectTimeout, defaults.connectTimeout); - expect(collectedCoverage.output, defaults.output); + expect(collectedCoverage.output, 'stdout'); }); test('format coverage', () { final formattedCoverage = - parseArgsFormatCoverage(defaultInputArgs, defaults); + parseArgsFormatCoverage([], defaults); - expect(formattedCoverage.baseDirectory, defaults.baseDirectory); - expect(formattedCoverage.input, 'coverage.json'); - expect(formattedCoverage.lcov, defaults.lcov); - expect(formattedCoverage.output, defaults.output); + expect(formattedCoverage.output, 'stdout'); expect(formattedCoverage.packagePath, defaults.packagePath); - expect(formattedCoverage.prettyPrint, defaults.prettyPrint); - expect(formattedCoverage.reportOn, defaults.reportOn); - expect(formattedCoverage.ignoreFiles, defaults.ignoreFiles); - expect(formattedCoverage.verbose, defaults.verbose); - expect(formattedCoverage.workers, defaults.workers); }); test('test with coverage', () async { @@ -42,7 +30,7 @@ void main() { expect(testCoverage.packagePath, getPackageDir(defaults.packagePath)); expect(testCoverage.packageName, 'coverage'); - expect(testCoverage.output, defaults.output); + expect(testCoverage.output, 'coverage'); expect(testCoverage.testScript, defaults.testScript); expect(testCoverage.functionCoverage, defaults.functionCoverage); expect(testCoverage.branchCoverage, defaults.branchCoverage); @@ -58,28 +46,18 @@ void main() { // Parse arguments with empty command line args final collectedCoverage = parseArgsCollectCoverage([], configuredOptions); final formattedCoverage = - parseArgsFormatCoverage(defaultInputArgs, configuredOptions); + parseArgsFormatCoverage([], configuredOptions); final testCoverage = await parseArgsTestWithCoverage([], configuredOptions); // Verify collect coverage yaml values expect(collectedCoverage.scopeOutput, ['lib', 'src']); - expect(collectedCoverage.resumeIsolates, isFalse); expect(collectedCoverage.functionCoverage, isTrue); expect(collectedCoverage.branchCoverage, isFalse); - expect(collectedCoverage.connectTimeout, 30); - expect(collectedCoverage.output, 'coverage'); + expect(collectedCoverage.output, 'coverage/coverage.json'); // Verify format coverage yaml values - expect(formattedCoverage.baseDirectory, '.'); - expect(formattedCoverage.input, 'coverage.json'); - expect(formattedCoverage.lcov, isTrue); - expect(formattedCoverage.output, 'coverage'); + expect(formattedCoverage.output, 'coverage/lcov.info'); expect(formattedCoverage.packagePath, '.'); - expect(formattedCoverage.prettyPrint, isFalse); - expect(formattedCoverage.reportOn, ['lib', 'bin']); - expect(formattedCoverage.ignoreFiles, ['test']); - expect(formattedCoverage.verbose, isTrue); - expect(formattedCoverage.workers, 2); // Verify test with coverage yaml values expect(testCoverage.packagePath, getPackageDir('.')); @@ -99,26 +77,14 @@ void main() { // Parse arguments with empty command line args final collectedCoverage = parseArgsCollectCoverage([], configuredOptions); - final formattedCoverage = - parseArgsFormatCoverage(defaultInputArgs, configuredOptions); final testCoverage = await parseArgsTestWithCoverage([], configuredOptions); + final formattedCoverage = parseArgsFormatCoverage([], configuredOptions); - // Verify collect coverage yaml values - expect(collectedCoverage.output, 'custom_coverage.json'); + expect(collectedCoverage.output, 'custom_coverage/coverage.json'); expect(collectedCoverage.scopeOutput, ['lib', 'test']); expect(collectedCoverage.functionCoverage, isFalse); - expect(collectedCoverage.connectTimeout, 20); - - // Verify format coverage yaml values - expect(formattedCoverage.lcov, isFalse); - expect(formattedCoverage.verbose, isFalse); - expect(formattedCoverage.baseDirectory, 'src'); - expect(formattedCoverage.ignoreFiles, ['example']); - expect(formattedCoverage.reportOn, ['lib']); - expect(formattedCoverage.prettyPrint, isTrue); - - // Verify test with coverage yaml values + expect(formattedCoverage.output, 'custom_coverage/lcov.info'); expect(testCoverage.packageName, 'Custom Dart Package'); expect(testCoverage.scopeOutput, ['lib', 'test']); }); @@ -137,18 +103,16 @@ void main() { // Verify collect coverage yaml values expect(collectedCoverage.scopeOutput, ['lib', 'tools']); expect(collectedCoverage.branchCoverage, isFalse); - expect(collectedCoverage.connectTimeout, 15); expect(collectedCoverage.functionCoverage, isTrue); + expect(collectedCoverage.output, 'custom_lcov/coverage.json'); // Verify format coverage yaml values - expect(formattedCoverage.input, 'custom_coverage.json'); - expect(formattedCoverage.output, 'custom_lcov.info'); + expect(formattedCoverage.output, 'custom_lcov/lcov.info'); expect(formattedCoverage.packagePath, '.'); - expect(formattedCoverage.reportOn, ['src', 'scripts']); // Verify test with coverage yaml values expect(testCoverage.packageName, 'coverage'); - expect(testCoverage.output, 'custom_lcov.info'); + expect(testCoverage.output, 'custom_lcov'); expect(testCoverage.testScript, 'custom_test'); expect(testCoverage.functionCoverage, isTrue); }); @@ -163,17 +127,12 @@ void main() { final collectedCoverage = parseArgsCollectCoverage([ '--out=coverage.json', '--scope-output=lib', - '--connect-timeout=10', '--no-function-coverage', '--branch-coverage', ], configuredOptions); final formattedCoverage = parseArgsFormatCoverage([ - '--in=data.json', '--out=out_test.info', - '--report-on=src', - '--report-on=src2', - '--ignore-files=bin', - '--workers=4', + '--package=code_builder', ], configuredOptions); final testCoverage = await parseArgsTestWithCoverage([ '--package-name=test', @@ -187,14 +146,10 @@ void main() { expect(collectedCoverage.scopeOutput, ['lib']); expect(collectedCoverage.functionCoverage, isFalse); expect(collectedCoverage.branchCoverage, isTrue); - expect(collectedCoverage.connectTimeout, 10); // Verify format coverage command line args - expect(formattedCoverage.input, 'data.json'); expect(formattedCoverage.output, 'out_test.info'); - expect(formattedCoverage.reportOn, ['src', 'src2']); - expect(formattedCoverage.ignoreFiles, ['bin']); - expect(formattedCoverage.workers, 4); + expect(formattedCoverage.packagePath, 'code_builder'); // Verify test with coverage command line args expect(testCoverage.packageName, 'test'); @@ -211,33 +166,23 @@ void main() { // Parse arguments with empty command line args final collectedCoverage = parseArgsCollectCoverage([], configuredOptions); final formattedCoverage = - parseArgsFormatCoverage(defaultInputArgs, configuredOptions); + parseArgsFormatCoverage([], configuredOptions); final testCoverage = await parseArgsTestWithCoverage([], configuredOptions); // Verify collect coverage defaults expect(collectedCoverage.scopeOutput, isEmpty); - expect(collectedCoverage.resumeIsolates, isFalse); expect(collectedCoverage.functionCoverage, isFalse); expect(collectedCoverage.branchCoverage, isFalse); - expect(collectedCoverage.connectTimeout, isNull); expect(collectedCoverage.output, 'stdout'); // Verify format coverage defaults - expect(formattedCoverage.baseDirectory, '.'); - expect(formattedCoverage.input, 'coverage.json'); - expect(formattedCoverage.lcov, isFalse); expect(formattedCoverage.output, 'stdout'); expect(formattedCoverage.packagePath, '.'); - expect(formattedCoverage.prettyPrint, isFalse); - expect(formattedCoverage.reportOn, isNull); - expect(formattedCoverage.ignoreFiles, isEmpty); - expect(formattedCoverage.verbose, isFalse); - expect(formattedCoverage.workers, 1); // Verify test with coverage defaults expect(testCoverage.packagePath, getPackageDir('.')); expect(testCoverage.packageName, 'coverage'); - expect(testCoverage.output, 'stdout'); + expect(testCoverage.output, 'coverage'); expect(testCoverage.testScript, 'test'); expect(testCoverage.functionCoverage, isFalse); expect(testCoverage.branchCoverage, isFalse); diff --git a/pkgs/coverage/test/test_coverage_options/all_field.yaml b/pkgs/coverage/test/test_coverage_options/all_field.yaml index 8554bf56b..57f1cd41a 100644 --- a/pkgs/coverage/test/test_coverage_options/all_field.yaml +++ b/pkgs/coverage/test/test_coverage_options/all_field.yaml @@ -1,16 +1,7 @@ out: "coverage" -connect-timeout: 30 scope-output: ["lib", "src"] function-coverage: true branch-coverage: false -base-directory: "." -in: "coverage.json" package: "." package-name: "My Dart Package" -report-on: ["lib", "bin"] -ignore-files: ["test"] -workers: 2 -verbose: true -lcov: true -pretty-print: false test: "test" diff --git a/pkgs/coverage/test/test_coverage_options/partial_fields1.yaml b/pkgs/coverage/test/test_coverage_options/partial_fields1.yaml index 3da3ed1ca..137c0b355 100644 --- a/pkgs/coverage/test/test_coverage_options/partial_fields1.yaml +++ b/pkgs/coverage/test/test_coverage_options/partial_fields1.yaml @@ -1,14 +1,5 @@ -out: 'custom_coverage.json' +out: 'custom_coverage' scope-output: - 'lib' - 'test' -connect-timeout: 20 -lcov: false -verbose: false -base-directory: 'src' -ignore-files: - - 'example' -report-on: - - 'lib' -pretty-print: true package-name: 'Custom Dart Package' \ No newline at end of file diff --git a/pkgs/coverage/test/test_coverage_options/partial_fields2.yaml b/pkgs/coverage/test/test_coverage_options/partial_fields2.yaml index 36efc2fb4..1df32004d 100644 --- a/pkgs/coverage/test/test_coverage_options/partial_fields2.yaml +++ b/pkgs/coverage/test/test_coverage_options/partial_fields2.yaml @@ -2,14 +2,7 @@ scope-output: - 'lib' - 'tools' branch-coverage: false -connect-timeout: 15 - -in: 'custom_coverage.json' -out: 'custom_lcov.info' +out: 'custom_lcov' package: '.' -report-on: - - 'src' - - 'scripts' - test: 'custom_test' function-coverage: true \ No newline at end of file diff --git a/pkgs/coverage/test/test_util.dart b/pkgs/coverage/test/test_util.dart index 50aab8d2f..271e45727 100644 --- a/pkgs/coverage/test/test_util.dart +++ b/pkgs/coverage/test/test_util.dart @@ -96,89 +96,56 @@ extension ListTestExtension on List { CoverageOptions parseArgsCollectCoverage( List arguments, CoverageOptions defaultOptions) { final parser = ArgParser() - ..addOption('host', abbr: 'H') - ..addOption('port', abbr: 'p') - ..addOption('uri', abbr: 'u') - ..addOption('out', abbr: 'o', defaultsTo: defaultOptions.output) - ..addOption('connect-timeout', - abbr: 't', defaultsTo: defaultOptions.connectTimeout?.toString()) + ..addOption('out', abbr: 'o') ..addMultiOption('scope-output', defaultsTo: defaultOptions.scopeOutput) - ..addFlag('resume-isolates', - abbr: 'r', defaultsTo: defaultOptions.resumeIsolates) ..addFlag('function-coverage', abbr: 'f', defaultsTo: defaultOptions.functionCoverage) ..addFlag('branch-coverage', - abbr: 'b', defaultsTo: defaultOptions.branchCoverage) - ..addFlag('help', abbr: 'h', negatable: false); + abbr: 'b', defaultsTo: defaultOptions.branchCoverage); final args = parser.parse(arguments); + String out; + final outPath = args['out'] as String?; + if (outPath == null && defaultOptions.output == null) { + out = 'stdout'; + } else { + out = outPath ?? '${defaultOptions.output}/coverage.json'; + } + return CoverageOptions( - output: args['out'] as String, - connectTimeout: args['connect-timeout'] == null - ? defaultOptions.connectTimeout - : int.parse(args['connect-timeout'] as String), + output: out, scopeOutput: args['scope-output'] as List, - resumeIsolates: args['resume-isolates'] as bool, functionCoverage: args['function-coverage'] as bool, branchCoverage: args['branch-coverage'] as bool, - baseDirectory: defaultOptions.baseDirectory, - ignoreFiles: defaultOptions.ignoreFiles, - input: defaultOptions.input, - lcov: defaultOptions.lcov, packagePath: defaultOptions.packagePath, packageName: defaultOptions.packageName, - prettyPrint: defaultOptions.prettyPrint, - reportOn: defaultOptions.reportOn, testScript: defaultOptions.testScript, - verbose: defaultOptions.verbose, - workers: defaultOptions.workers, ); } CoverageOptions parseArgsFormatCoverage( List arguments, CoverageOptions defaultOptions) { final parser = ArgParser() - ..addOption('packages') ..addOption('package', defaultsTo: defaultOptions.packagePath) - ..addOption('in', abbr: 'i', defaultsTo: defaultOptions.input) - ..addOption('out', abbr: 'o', defaultsTo: defaultOptions.output) - ..addMultiOption('report-on', defaultsTo: defaultOptions.reportOn) - ..addOption('workers', - abbr: 'j', defaultsTo: defaultOptions.workers.toString()) - ..addOption('base-directory', - abbr: 'b', defaultsTo: defaultOptions.baseDirectory) - ..addFlag('pretty-print', - abbr: 'r', defaultsTo: defaultOptions.prettyPrint, negatable: false) - ..addFlag('lcov', - abbr: 'l', defaultsTo: defaultOptions.lcov, negatable: false) - ..addFlag('verbose', - abbr: 'v', defaultsTo: defaultOptions.verbose, negatable: false) - ..addMultiOption('ignore-files', defaultsTo: defaultOptions.ignoreFiles) - ..addFlag('help', abbr: 'h', negatable: false); + ..addOption('out', abbr: 'o'); final args = parser.parse(arguments); - if (args['in'] == null) throw ArgumentError('Missing required argument: in'); + String out; + final outPath = args['out'] as String?; + if (outPath == null && defaultOptions.output == null) { + out = 'stdout'; + } else { + out = outPath ?? '${defaultOptions.output}/lcov.info'; + } return CoverageOptions( - baseDirectory: args['base-directory'] as String?, - input: args['in'] as String, - lcov: args['lcov'] as bool, - output: args['out'] as String, + output: out, packagePath: args['package'] as String, - prettyPrint: args['lcov'] as bool ? false : args['pretty-print'] as bool, - reportOn: (args['report-on'] as List).isNotEmpty - ? args['report-on'] as List - : null, - ignoreFiles: args['ignore-files'] as List, - verbose: args['verbose'] as bool, - workers: int.parse(args['workers'] as String), branchCoverage: defaultOptions.branchCoverage, functionCoverage: defaultOptions.functionCoverage, - connectTimeout: defaultOptions.connectTimeout, packageName: defaultOptions.packageName, - resumeIsolates: defaultOptions.resumeIsolates, scopeOutput: defaultOptions.scopeOutput, testScript: defaultOptions.testScript, ); @@ -195,7 +162,6 @@ Future parseArgsTestWithCoverage( 'package-name', defaultsTo: defaultOptions.packageName, ) - ..addOption('port') ..addOption( 'out', defaultsTo: defaultOptions.output, @@ -212,8 +178,7 @@ Future parseArgsTestWithCoverage( abbr: 'b', defaultsTo: defaultOptions.branchCoverage, ) - ..addMultiOption('scope-output', defaultsTo: defaultOptions.scopeOutput) - ..addFlag('help', abbr: 'h', negatable: false); + ..addMultiOption('scope-output', defaultsTo: defaultOptions.scopeOutput); final args = parser.parse(arguments); @@ -236,16 +201,6 @@ Future parseArgsTestWithCoverage( functionCoverage: args['function-coverage'] as bool, branchCoverage: args['branch-coverage'] as bool, scopeOutput: args['scope-output'] as List, - baseDirectory: defaultOptions.baseDirectory, - connectTimeout: defaultOptions.connectTimeout, - ignoreFiles: defaultOptions.ignoreFiles, - input: defaultOptions.input, - lcov: defaultOptions.lcov, - prettyPrint: defaultOptions.prettyPrint, - reportOn: defaultOptions.reportOn, - resumeIsolates: defaultOptions.resumeIsolates, - verbose: defaultOptions.verbose, - workers: defaultOptions.workers, ); }