Mohammed Niyaz
Mohammed Niyaz

Reputation: 179

Ignore freezed.dart and .g.dart files from lcov.info in flutter

Im trying to get a code coverage report following the below steps.

I want the generated files to be removed from the report. i treid..

lcov --remove coverage/lcov.info \ 'lib/*/*.freezed.dart'  \ -o coverage/lcov.info

But this does nothing. Still shows the report with generated files. I don't know whether if i'm doing this the right way.

Upvotes: 1

Views: 1392

Answers (1)

Kamel Elrifai
Kamel Elrifai

Reputation: 1

You can use a shell script to dynamically generate a list of files to exclude, based on their file extension, and then pass that list to lcov using the --remove option. Here's how you could do it for excluding .g.dart files:

# Build an array of exclude patterns
exclude_patterns=()
while IFS= read -r pattern; do
    exclude_patterns+=("$pattern")
done < <(find . -name "*.g.dart" | sed 's|^\./||')

# Now use the array when invoking lcov
lcov --remove lcov.info "${exclude_patterns[@]}" -o lcov_filtered.info

Explanation:

  1. We first initialize an empty array called exclude_patterns to hold the list of files to exclude.
  2. We use a while loop to read each line of output from the find command, which searches for all files ending in .g.dart in the current directory and its subdirectories.
  3. The sed command is used to remove the ./ prefix from the paths returned by find.
  4. Each file path is then added to the exclude_patterns array.
  5. Finally, we invoke lcov with the --remove option, passing the exclude_patterns array to specify the files to exclude. The -o option specifies the output file for the filtered lcov report.

Now, when you run this script, lcov will generate a report that excludes all .g.dart files.

Upvotes: 0

Related Questions