-
Notifications
You must be signed in to change notification settings - Fork 14
Test/coverage check #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Test/coverage check #464
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4f55dfd
chore: add script to check diff coverage
josefinalliende 72fc152
test: improve coverage of theme provider
josefinalliende 2ab1304
test: add unit test for profile ready card visibility provider
josefinalliende 6fb398a
chore: remove unused toast messages methods
josefinalliende 78b4c1d
test: improve coverage for toast message provider
josefinalliende 5c8c834
chore: adding coverage in ci step
josefinalliende 856cb8c
fixup! test: add unit test for profile ready card visibility provider
josefinalliende 48325d0
fixup! chore: add script to check diff coverage
josefinalliende File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,3 +54,6 @@ rust/.cargo/config.toml | |
| # AI | ||
| **/.repomix-* | ||
| .goose/** | ||
|
|
||
| # Coverage | ||
| coverage/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| MIN_COVERAGE=100 | ||
| FILE_PATTERN="provider" | ||
| BASE_BRANCH="master" | ||
|
|
||
| print_error() { | ||
| red_color="\e[31;1m%s\e[0m\n" | ||
| printf "${red_color}" "$1" | ||
| } | ||
|
|
||
| print_success() { | ||
| green_color="\e[32;1m%s\e[0m\n" | ||
| printf "${green_color}" "$1" | ||
| } | ||
|
|
||
| raise_error() { | ||
| print_error "$1" | ||
| exit 1 | ||
| } | ||
|
|
||
| check_prerequisites() { | ||
| local missing_tools | ||
| missing_tools=() | ||
|
|
||
| command -v git >/dev/null 2>&1 || missing_tools+=("git") | ||
| command -v lcov >/dev/null 2>&1 || missing_tools+=("lcov") | ||
| command -v bc >/dev/null 2>&1 || missing_tools+=("bc") | ||
|
|
||
| if [ ${#missing_tools[@]} -gt 0 ]; then | ||
| local tools_list | ||
| tools_list=$(printf ", %s" "${missing_tools[@]}") | ||
| tools_list=${tools_list:2} # Remove leading ", " | ||
| raise_error "Missing required tools: ${tools_list}. Please install them first." | ||
| fi | ||
| } | ||
|
|
||
| check_coverage_file_presence() { | ||
| if [ ! -f "coverage/lcov.info" ]; then | ||
| raise_error "Coverage file not found. Run 'flutter test --coverage' first." | ||
| fi | ||
| } | ||
|
|
||
| fetch_base_branch() { | ||
| local base_branch | ||
| base_branch=$1 | ||
| printf "Fetching latest ${base_branch}...\n" | ||
| git fetch --no-tags --prune origin +refs/heads/${base_branch}:refs/remotes/origin/${base_branch} | ||
| } | ||
|
|
||
| get_merge_base() { | ||
| local base_branch | ||
| base_branch=$1 | ||
| merge_base=$(git merge-base HEAD "origin/${base_branch}" 2>/dev/null || git merge-base HEAD "${base_branch}" 2>/dev/null || echo "") | ||
| echo "$merge_base" | ||
| } | ||
|
|
||
| check_merge_base() { | ||
| local base_branch | ||
| base_branch=$1 | ||
| local merge_base | ||
| merge_base=$2 | ||
| if [ -z "$merge_base" ]; then | ||
| raise_error "Could not find common ancestor with ${base_branch}. Ensure the branch exists and has shared history." | ||
| fi | ||
| } | ||
|
|
||
| get_changed_files() { | ||
| local merge_base | ||
| merge_base=$1 | ||
| local file_pattern | ||
| file_pattern=$2 | ||
| changed_files=$(git diff --name-only "$merge_base" HEAD | grep '^lib/.*\.dart$' | grep "${file_pattern}" || true) | ||
|
|
||
| if [ -z "$changed_files" ]; then | ||
| print_success "No lib/ Dart files matching '${file_pattern}' changed. Skipping coverage check." | ||
| exit 0 | ||
| fi | ||
| printf "Changed files detected:\n%s\n" "$changed_files" >&2 | ||
| echo "$changed_files" | ||
| } | ||
|
|
||
| make_temp_file() { | ||
| mktemp | ||
| } | ||
|
|
||
| calculate_coverage() { | ||
| local changed_files | ||
| changed_files=$1 | ||
| local temp_lcov | ||
| temp_lcov=$2 | ||
|
|
||
| # Convert newline-separated files to array to avoid word splitting issues | ||
| local -a files_array | ||
| while IFS= read -r file; do | ||
| files_array+=("$file") | ||
| done <<< "$changed_files" | ||
| lcov --extract coverage/lcov.info "${files_array[@]}" --output-file "$temp_lcov" | ||
| } | ||
|
|
||
| extract_coverage_percentage() { | ||
| local temp_lcov | ||
| temp_lcov=$1 | ||
| local coverage_percentage | ||
| coverage_percentage="0" | ||
| local total_lines hit_lines | ||
| total_lines=$(grep "^LF:" "$temp_lcov" | awk -F: '{sum += $2} END {print sum}' || echo "0") | ||
| hit_lines=$(grep "^LH:" "$temp_lcov" | awk -F: '{sum += $2} END {print sum}' || echo "0") | ||
| if [ "$total_lines" -gt 0 ]; then | ||
| coverage_percentage=$(echo "scale=1; $hit_lines * 100 / $total_lines" | bc -l) | ||
| fi | ||
| coverage_percentage=$(printf "%.0f" "$coverage_percentage" 2>/dev/null || echo "0") | ||
| echo "$coverage_percentage" | ||
| } | ||
|
|
||
| print_files_with_low_coverage() { | ||
| local temp_lcov | ||
| temp_lcov=$1 | ||
| local min_coverage | ||
| min_coverage=$2 | ||
|
|
||
| lcov --quiet --list "$temp_lcov" 2>/dev/null | grep -v "Message summary" | grep -E "^[^|]*\|" | grep -v "Total:" | grep -v "Filename" | grep -v "====" | grep "\.dart" | while IFS='|' read -r file coverage rest; do | ||
| file_coverage=$(echo "$coverage" | sed 's/^[[:space:]]*\([0-9.]*\)%.*/\1/') | ||
| if [[ "$file_coverage" =~ ^[0-9]+\.?[0-9]*$ ]]; then | ||
| if [ "$(echo "$file_coverage < $min_coverage" | bc -l)" = "1" ]; then | ||
| print_error " - $file" | ||
| else | ||
| print_success " - $file" | ||
| fi | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| handle_coverage_failure() { | ||
| local temp_lcov | ||
| temp_lcov=$1 | ||
| local coverage_percentage | ||
| coverage_percentage=$2 | ||
| local min_coverage | ||
| min_coverage=$3 | ||
| print_error "Oops! Coverage ${coverage_percentage}% < ${min_coverage}% for changed files" | ||
| print_error "Check the coverage report for these files:" | ||
| print_files_with_low_coverage "$temp_lcov" "$min_coverage" | ||
| exit 1 | ||
| } | ||
|
|
||
| check_coverage_result() { | ||
| local temp_lcov | ||
| temp_lcov=$1 | ||
| local coverage_percentage | ||
| coverage_percentage=$2 | ||
| local min_coverage | ||
| min_coverage=$3 | ||
|
|
||
| if ! check_coverage_threshold "$coverage_percentage" "$min_coverage"; then | ||
| handle_coverage_failure "$temp_lcov" "$coverage_percentage" "$min_coverage" | ||
| fi | ||
|
|
||
| print_success "Coverage ${coverage_percentage}% ✓" | ||
| } | ||
|
|
||
| check_coverage_threshold() { | ||
| local coverage_percentage | ||
| coverage_percentage=$1 | ||
| local min_coverage | ||
| min_coverage=$2 | ||
| if [ -n "$coverage_percentage" ] && (($(echo "$coverage_percentage >= $min_coverage" | bc -l))); then | ||
| return 0 | ||
| else | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| check_diff_coverage() { | ||
| printf "Checking coverage for changed files...\n" | ||
| local base_branch | ||
| base_branch=$1 | ||
| local file_pattern | ||
| file_pattern=$2 | ||
| local min_coverage | ||
| min_coverage=$3 | ||
| check_prerequisites | ||
| check_coverage_file_presence | ||
| fetch_base_branch "$base_branch" | ||
| merge_base=$(get_merge_base "$base_branch") | ||
| check_merge_base "$base_branch" "$merge_base" | ||
| changed_files=$(get_changed_files "$merge_base" "$file_pattern") | ||
| temp_file=$(make_temp_file) | ||
| trap "rm -f $temp_file" EXIT | ||
| calculate_coverage "$changed_files" "$temp_file" | ||
| coverage_percentage=$(extract_coverage_percentage "$temp_file") | ||
| check_coverage_result "$temp_file" "$coverage_percentage" "$min_coverage" | ||
| } | ||
|
|
||
| check_diff_coverage "$BASE_BRANCH" "$FILE_PATTERN" "$MIN_COVERAGE" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
show some love to windows 😅 they should get the lcov treatment too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG, I don't know how to install anything on windows 😓 ...
Also me right now:

...
Chatgpt says
choco install lcov... is this correct? Do you have a windows to check it out?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't own a windows myself which i probably should when we begin desktop rollout.
but after searching the internet i also found out choco works to install lcov.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so I'll add the choco 🍫 instructions haha