Skip to content

Commit

Permalink
Test and coverage the sql parser
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Jul 28, 2019
1 parent b4cdcf0 commit 4c7874d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 8 deletions.
9 changes: 8 additions & 1 deletion .cirrus.yml
Expand Up @@ -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
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
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
**/.idea
**/*.iml

lcov.info
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions moor/tool/format_coverage.dart
Expand Up @@ -9,17 +9,27 @@ 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(
resolver,
reportOn: [
'moor/lib/',
'moor_generator/lib',
'sqlparser/lib',
],
basePath: '.',
).format(coverage);

File('moor/lcov.info').writeAsStringSync(lcov);
File('lcov.info').writeAsStringSync(lcov);
}
2 changes: 2 additions & 0 deletions sqlparser/.gitignore
Expand Up @@ -9,3 +9,5 @@ build/

# Directory created by dartdoc
doc/api/

coverage.json
4 changes: 4 additions & 0 deletions sqlparser/pubspec.yaml
Expand Up @@ -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
12 changes: 12 additions & 0 deletions 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));
}
7 changes: 7 additions & 0 deletions 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...');
}
4 changes: 4 additions & 0 deletions tool/test_sqlparser.sh
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cd sqlparser
dart tool/coverage.dart
10 changes: 6 additions & 4 deletions 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
# 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

0 comments on commit 4c7874d

Please sign in to comment.