diff --git a/moor/.gitignore b/moor/.gitignore index 2fdc2959..521e2460 100644 --- a/moor/.gitignore +++ b/moor/.gitignore @@ -31,6 +31,10 @@ doc/api/ android/ ios/ +# coverage +test/.test_coverage.dart +coverage_badge.svg + ### Intellij ### .idea/**/* # End of https://www.gitignore.io/api/dart,intellij diff --git a/moor/pubspec.yaml b/moor/pubspec.yaml index 5c4f3fa8..65c0729b 100644 --- a/moor/pubspec.yaml +++ b/moor/pubspec.yaml @@ -22,16 +22,13 @@ dev_dependencies: build_runner: '>=1.3.0 <2.0.0' build_test: ^0.10.8 test: ^1.6.4 - test_core: '>=0.2.0 <1.0.0' mockito: ^4.1.0 grinder: ^0.8.3 - coverage: ^0.12.4 + coverage: any # will be determined by test_coverage + test_coverage: ^0.3.0 dependency_overrides: moor_generator: path: ../moor_generator sqlparser: - path: ../sqlparser - # Temporarily use my fork because it can collect coverage when running tests with the test runner - coverage: - git: https://github.com/simolus3/coverage.git \ No newline at end of file + path: ../sqlparser \ No newline at end of file diff --git a/moor/tool/coverage.dart b/moor/tool/coverage.dart deleted file mode 100644 index 9faaf77c..00000000 --- a/moor/tool/coverage.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; - -import 'package:grinder/grinder_sdk.dart'; -import 'package:coverage/coverage.dart'; -import 'package:path/path.dart'; - -Future main(List args) async { - Pub.run('build_runner', arguments: ['build', '--delete-conflicting-outputs']); - - // Next, run the test script in another dart process that has the vm services - // enabled. - 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/moor/tool/format_coverage.dart b/moor/tool/format_coverage.dart index c77d6936..b8732900 100644 --- a/moor/tool/format_coverage.dart +++ b/moor/tool/format_coverage.dart @@ -5,22 +5,27 @@ 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 { - final resolver = Resolver(packagesPath: 'moor/.packages'); + // 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 coverage = await parseCoverage([ - File('moor/coverage.json'), - File('sqlparser/coverage.json'), - ], 1); + 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: [ - 'moor/lib/', - 'sqlparser/lib', - ], + reportOn: ['sqlparser/lib'], basePath: '.', - ).format(coverage); + ).format(sqlCoverage); - File('lcov.info').writeAsStringSync(lcov); + final output = moorWithFixesPaths.join('\n') + lcov; + File('lcov.info').writeAsStringSync(output); } diff --git a/moor/tool/tester.dart b/moor/tool/tester.dart deleted file mode 100644 index 5c415044..00000000 --- a/moor/tool/tester.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:test_core/src/executable.dart' as test; - -void main() async { - print('inside test file'); - // Run tests - await test.main([]); - print('done, script should terminate after coverage is collected'); -} diff --git a/tool/test_moor.sh b/tool/test_moor.sh index 0a717ae0..90616ea5 100755 --- a/tool/test_moor.sh +++ b/tool/test_moor.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash cd moor -dart tool/coverage.dart -#pub run build_runner test --delete-conflicting-outputs \ No newline at end of file +pub run build_runner test --delete-conflicting-outputs +pub run test_coverage --no-badge \ No newline at end of file