Use package:test_coverage for moor subproject

This commit is contained in:
Simon Binder 2019-09-29 11:27:35 +02:00
parent 234a96cd5e
commit 5a0c0d9212
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
6 changed files with 25 additions and 45 deletions

4
moor/.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -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<void> main(List<String> 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));
}

View File

@ -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);
}

View File

@ -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');
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
cd moor
dart tool/coverage.dart
#pub run build_runner test --delete-conflicting-outputs
pub run build_runner test --delete-conflicting-outputs
pub run test_coverage --no-badge