mirror of https://github.com/AMT-Cheif/drift.git
Use builtin coverage collection from test package
This commit is contained in:
parent
17210f7bee
commit
623f3212a1
|
@ -1,4 +1,8 @@
|
|||
**/.idea
|
||||
**/*.iml
|
||||
|
||||
lcov.info
|
||||
lcov.info
|
||||
|
||||
.packages
|
||||
pubspec.lock
|
||||
.dart_tool/
|
|
@ -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<File> 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<File>()
|
||||
.where((e) => filePattern.hasMatch(p.basename(e.path)))
|
||||
.toList();
|
||||
}
|
||||
throw AssertionError('Moor subproject at $moorSubproject does not exist');
|
||||
}
|
|
@ -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
|
|
@ -32,8 +32,7 @@ android/
|
|||
ios/
|
||||
|
||||
# coverage
|
||||
test/.test_coverage.dart
|
||||
coverage_badge.svg
|
||||
coverage/
|
||||
|
||||
### Intellij ###
|
||||
.idea/**/*
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -10,4 +10,4 @@ build/
|
|||
# Directory created by dartdoc
|
||||
doc/api/
|
||||
|
||||
coverage.json
|
||||
coverage/
|
|
@ -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
|
|
@ -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));
|
||||
}
|
|
@ -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...');
|
||||
}
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
cd moor
|
||||
pub run build_runner test --delete-conflicting-outputs
|
||||
pub run test_coverage --no-badge
|
||||
pub run test --coverage=coverage
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd sqlparser
|
||||
dart tool/coverage.dart
|
||||
pub run test --coverage=coverage
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue