From 4c7874dd91422f6a6ec08c13e825f7cdaf83e963 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 28 Jul 2019 09:49:14 +0200 Subject: [PATCH] Test and coverage the sql parser --- .cirrus.yml | 9 ++++++++- .gitignore | 2 ++ .travis.yml | 2 +- moor/tool/format_coverage.dart | 14 ++++++++++++-- sqlparser/.gitignore | 2 ++ sqlparser/pubspec.yaml | 4 ++++ sqlparser/tool/coverage.dart | 12 ++++++++++++ sqlparser/tool/tester.dart | 7 +++++++ tool/test_sqlparser.sh | 4 ++++ tool/upload_coverage.sh | 10 ++++++---- 10 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 sqlparser/tool/coverage.dart create mode 100644 sqlparser/tool/tester.dart create mode 100755 tool/test_sqlparser.sh diff --git a/.cirrus.yml b/.cirrus.yml index 820eb93f..98e24147 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -3,8 +3,15 @@ container: image: "google/dart:latest" task: + name: Analysis and Tests pub_cache: folder: $HOME/.pub-cache pub_get_script: tool/pub_get.sh analyze_script: tool/analyze.sh - test_moor_script: tool/test_moor.sh \ No newline at end of file + test_moor_script: tool/test_moor.sh + test_sqlparser_script: tool/test_sqlparser.sh + +upload_coverage_task: + name: Upload coverage + depends_on: [task] + format_coverage_task: tool/upload_coverage.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0789022d..e61fb08c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ **/.idea **/*.iml + +lcov.info \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5e75137d..8f4ecece 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ env: - PKG="sqlparser" script: ./tool/mono_repo_wrapper.sh -after_success: ./tool/upload_coverage.sh +#after_success: ./tool/upload_coverage.sh cache: directories: diff --git a/moor/tool/format_coverage.dart b/moor/tool/format_coverage.dart index 0a1037e0..29dd6d60 100644 --- a/moor/tool/format_coverage.dart +++ b/moor/tool/format_coverage.dart @@ -9,7 +9,16 @@ Future main() async { packagesPath: 'moor/.packages', ); - final coverage = await parseCoverage([File('moor/coverage.json')], 1); + final potentialFiles = [ + File('moor/coverage.json'), + File('sqlparser/coverage.json'), + ]; + + final existingFiles = [ + for (var file in potentialFiles) if (file.existsSync()) file + ]; + + final coverage = await parseCoverage(existingFiles, 1); // report coverage for the moor and moor_generator package final lcov = await LcovFormatter( @@ -17,9 +26,10 @@ Future main() async { reportOn: [ 'moor/lib/', 'moor_generator/lib', + 'sqlparser/lib', ], basePath: '.', ).format(coverage); - File('moor/lcov.info').writeAsStringSync(lcov); + File('lcov.info').writeAsStringSync(lcov); } diff --git a/sqlparser/.gitignore b/sqlparser/.gitignore index 50602ac6..d937c1e0 100644 --- a/sqlparser/.gitignore +++ b/sqlparser/.gitignore @@ -9,3 +9,5 @@ build/ # Directory created by dartdoc doc/api/ + +coverage.json \ No newline at end of file diff --git a/sqlparser/pubspec.yaml b/sqlparser/pubspec.yaml index 505e2394..60d45c55 100644 --- a/sqlparser/pubspec.yaml +++ b/sqlparser/pubspec.yaml @@ -16,3 +16,7 @@ dependencies: dev_dependencies: test: ^1.6.0 + test_core: any # version will be determined by "test" + 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 new file mode 100644 index 00000000..c6ff4979 --- /dev/null +++ b/sqlparser/tool/coverage.dart @@ -0,0 +1,12 @@ +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 new file mode 100644 index 00000000..916c6f55 --- /dev/null +++ b/sqlparser/tool/tester.dart @@ -0,0 +1,7 @@ +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_sqlparser.sh b/tool/test_sqlparser.sh new file mode 100755 index 00000000..bede92e6 --- /dev/null +++ b/tool/test_sqlparser.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +cd sqlparser +dart tool/coverage.dart \ No newline at end of file diff --git a/tool/upload_coverage.sh b/tool/upload_coverage.sh index 1141fb46..ce6af79d 100755 --- a/tool/upload_coverage.sh +++ b/tool/upload_coverage.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -if [ "$PKG" == "moor" ]; then - pushd moor - bash <(curl -s https://codecov.io/bash) -f lcov.info -fi \ No newline at end of file +# The formatter is in the moor directory +pushd moor +dart tool/format_coverage.dart +popd + +bash <(curl -s https://codecov.io/bash) -f lcov.info