diff --git a/.gitignore b/.gitignore index e61fb08c..0f1b4a47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ **/.idea **/*.iml -lcov.info \ No newline at end of file +lcov.info + +.packages +pubspec.lock +.dart_tool/ \ No newline at end of file diff --git a/extras/coverage_formatting/bin/coverage.dart b/extras/coverage_formatting/bin/coverage.dart new file mode 100644 index 00000000..8821a7d8 --- /dev/null +++ b/extras/coverage_formatting/bin/coverage.dart @@ -0,0 +1,52 @@ +// Adapted from https://github.com/dart-lang/coverage/blob/master/bin/format_coverage.dart +// because that file doesn't work with the output of the test package. + +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; + +import 'package:coverage/coverage.dart'; +import 'package:path/path.dart' as p; + +final outputFile = File('lcov.info'); + +void main() async { + if (outputFile.existsSync()) { + outputFile.deleteSync(); + } + + await runForProject('moor'); + await runForProject('sqlparser'); +} + +Future runForProject(String projectName) async { + final files = filesToProcess(projectName); + print('$projectName: Collecting across ${files.length} files'); + + final hitmap = await parseCoverage(files, 1); + + final resolver = Resolver(packagesPath: p.join(projectName, '.packages')); + + final output = + await LcovFormatter(resolver, reportOn: [p.join(projectName, 'lib')]) + .format(hitmap); + + await outputFile.writeAsString(output, mode: FileMode.append); +} + +List filesToProcess(String moorSubproject) { + final filePattern = RegExp(r'^.*\.json$'); + final coverageOutput = p.join(moorSubproject, 'coverage', 'test'); + + if (FileSystemEntity.isDirectorySync(coverageOutput)) { + return Directory(coverageOutput) + .listSync(recursive: true) + .whereType() + .where((e) => filePattern.hasMatch(p.basename(e.path))) + .toList(); + } + throw AssertionError('Moor subproject at $moorSubproject does not exist'); +} diff --git a/extras/coverage_formatting/pubspec.yaml b/extras/coverage_formatting/pubspec.yaml new file mode 100644 index 00000000..c13597d6 --- /dev/null +++ b/extras/coverage_formatting/pubspec.yaml @@ -0,0 +1,7 @@ +name: coverage_formatting +publish_to: none +description: Tool used for the CI to format VM coverage jsons to LCOV files + +dependencies: + coverage: '>=0.13.3' + path: ^1.6.4 \ No newline at end of file diff --git a/moor/.gitignore b/moor/.gitignore index 521e2460..dda8392b 100644 --- a/moor/.gitignore +++ b/moor/.gitignore @@ -32,8 +32,7 @@ android/ ios/ # coverage -test/.test_coverage.dart -coverage_badge.svg +coverage/ ### Intellij ### .idea/**/* diff --git a/moor/pubspec.yaml b/moor/pubspec.yaml index 7c74d6ee..3e411f4f 100644 --- a/moor/pubspec.yaml +++ b/moor/pubspec.yaml @@ -24,11 +24,9 @@ dev_dependencies: path: ../moor_ffi build_runner: '>=1.3.0 <2.0.0' build_test: ^0.10.8 - test: ^1.6.4 + test: ^1.9.0 mockito: ^4.1.0 grinder: ^0.8.3 - coverage: any # will be determined by test_coverage - test_coverage: ^0.3.0 dependency_overrides: moor_generator: diff --git a/moor/tool/format_coverage.dart b/moor/tool/format_coverage.dart deleted file mode 100644 index 17559106..00000000 --- a/moor/tool/format_coverage.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'dart:io'; - -import 'package:coverage/coverage.dart'; - -// note that this script will be run from the parent directory (the root of the -// moor repo) -Future main() async { - // the lcov file generated by test_coverage has wrong file paths - final moorLcov = File('moor/coverage/lcov.info').readAsLinesSync(); - final moorWithFixesPaths = moorLcov.map((line) { - if (line.startsWith('SF:')) { - final path = line.split(':')[1]; - return 'SF:moor/$path'; - } else { - return line; - } - }).toList(); - - final sqlCoverage = await parseCoverage([File('sqlparser/coverage.json')], 1); - final resolver = Resolver(packagesPath: 'sqlparser/.packages'); - - // report coverage for the moor and moor_generator package - final lcov = await LcovFormatter( - resolver, - reportOn: ['sqlparser/lib'], - basePath: '.', - ).format(sqlCoverage); - - // ignore: prefer_interpolation_to_compose_strings - final output = moorWithFixesPaths.join('\n') + '\n' + lcov; - File('lcov.info').writeAsStringSync(output); -} diff --git a/sqlparser/.gitignore b/sqlparser/.gitignore index d937c1e0..81cc7efd 100644 --- a/sqlparser/.gitignore +++ b/sqlparser/.gitignore @@ -10,4 +10,4 @@ build/ # Directory created by dartdoc doc/api/ -coverage.json \ No newline at end of file +coverage/ \ No newline at end of file diff --git a/sqlparser/pubspec.yaml b/sqlparser/pubspec.yaml index 4f99d3d5..767e3ef0 100644 --- a/sqlparser/pubspec.yaml +++ b/sqlparser/pubspec.yaml @@ -15,8 +15,5 @@ dependencies: source_span: ^1.5.5 dev_dependencies: - test: ^1.6.0 - test_core: any # version will be determined by "test" + test: ^1.9.0 path: ^1.6.0 - coverage: - git: https://github.com/simolus3/coverage.git \ No newline at end of file diff --git a/sqlparser/tool/coverage.dart b/sqlparser/tool/coverage.dart deleted file mode 100644 index c6ff4979..00000000 --- a/sqlparser/tool/coverage.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:coverage/coverage.dart'; -import 'package:path/path.dart'; - -void main() async { - final tests = join(File.fromUri(Platform.script).parent.path, 'tester.dart'); - final coverage = await runAndCollect(tests, onExit: true, printOutput: true); - - File('coverage.json').writeAsStringSync(json.encode(coverage)); -} diff --git a/sqlparser/tool/tester.dart b/sqlparser/tool/tester.dart deleted file mode 100644 index 916c6f55..00000000 --- a/sqlparser/tool/tester.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:test_core/src/executable.dart' as test; - -void main() async { - await test.main([]); - - print('Tests ran, now collecting coverage...'); -} diff --git a/tool/test_moor.sh b/tool/test_moor.sh index 90616ea5..429ff017 100755 --- a/tool/test_moor.sh +++ b/tool/test_moor.sh @@ -2,4 +2,4 @@ cd moor pub run build_runner test --delete-conflicting-outputs -pub run test_coverage --no-badge \ No newline at end of file +pub run test --coverage=coverage \ No newline at end of file diff --git a/tool/test_sqlparser.sh b/tool/test_sqlparser.sh index f3638da3..44376ee9 100755 --- a/tool/test_sqlparser.sh +++ b/tool/test_sqlparser.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash cd sqlparser -dart tool/coverage.dart +pub run test --coverage=coverage \ No newline at end of file diff --git a/tool/upload_coverage.sh b/tool/upload_coverage.sh index 12cc7633..8d2a3f83 100755 --- a/tool/upload_coverage.sh +++ b/tool/upload_coverage.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash -dart moor/tool/format_coverage.dart --packages=moor/.packages +pushd extras/coverage_formatting +pub upgrade +popd + +dart extras/coverage_formatting/bin/coverage.dart bash <(curl -s https://codecov.io/bash) -f lcov.info