diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 16662dc8b..418a81693 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,6 +8,7 @@ Before you create this PR confirm that it meets all requirements listed below by - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] My PR includes unit or integration tests for *all* changed/updated/fixed behaviors and are passing (See [Contributor Guide]). +- [ ] My PR does not decrease the code coverage, or I have __a very special case__ and explained on the PR description why this PR decreases the coverage. - [ ] I updated/added relevant documentation (doc comments with `///`) and updated/added examples in `doc/examples`. - [ ] I have formatted my code with `./scripts/format.sh` and the Flame analyzer (`./scripts/analyze.sh`) does not report any problems. - [ ] I read and followed the [Flame Style Guide]. diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index b1473ddf8..187ba7002 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -58,5 +58,6 @@ jobs: - uses: subosito/flutter-action@v1 with: channel: 'stable' + - run: sudo apt-get install lcov -y - run: ./scripts/test.sh # END TESTING STAGE diff --git a/.gitignore b/.gitignore index d68342265..6176d9087 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ android/ ios/ desktop/ build/ + +coverage diff --git a/packages/flame/.min_coverage b/packages/flame/.min_coverage new file mode 100644 index 000000000..8744ebcd5 --- /dev/null +++ b/packages/flame/.min_coverage @@ -0,0 +1 @@ +42.7 diff --git a/packages/flame/CHANGELOG.md b/packages/flame/CHANGELOG.md index 075cd0eb4..1d37df671 100644 --- a/packages/flame/CHANGELOG.md +++ b/packages/flame/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix the anchor of SpriteWidget - Add test for re-adding previously removed component - Add onCollisionEnd to make it possible for the user to easily detect when a collision ends + - Adding test coverage to packages ## [1.0.0-rc10] - Updated tutorial documentation to indicate use of new version diff --git a/scripts/check_coverage.dart b/scripts/check_coverage.dart new file mode 100644 index 000000000..987dbf863 --- /dev/null +++ b/scripts/check_coverage.dart @@ -0,0 +1,18 @@ +import 'dart:io'; + +void main(args) { + final coverageSummary = args[0] as String; + final currentRaw = coverageSummary.replaceFirstMapped( + RegExp(r".* (\d+\.\d+)%.*"), + (matches) => '${matches[1]}', + ); + + final current = double.parse(currentRaw); + final min = double.parse(args[1].replaceAll('\n', '')); + + if (current < min) { + exit(1); + } else { + exit(0); + } +} diff --git a/scripts/test.sh b/scripts/test.sh index c96f636df..5c1f5f4f1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -2,16 +2,32 @@ echo "Starting Flame Tester" echo "---------------------" +root_dir="$(realpath $(dirname "$0")/..)" for file in $(find . -type d -name "test"); do dir=$(dirname $file) cd $dir echo "Testing $dir" - flutter test + flutter test --coverage test_result=$? if [ $test_result -ne 0 ]; then exit $test_result fi + + if [ -f ".min_coverage" ]; then + min_coverage=$(cat .min_coverage) + + coverage_summary=$(lcov --summary coverage/lcov.info) + coverage_line=$(echo "$coverage_summary" | grep lines) + echo "$coverage_summary" + + dart "$root_dir/scripts/check_coverage.dart" "$coverage_line" "$min_coverage" + coverage_result=$? + if [ $coverage_result -ne 0 ]; then + echo "Current coverage $current_cov is smaller than min: $min_coverage" + exit $coverage_result + fi + fi cd $(cd -) done -exit 0 \ No newline at end of file +exit 0