Created
December 16, 2022 16:23
-
-
Save lhimo/553fb82704ef9bc8914f7046d7b3b593 to your computer and use it in GitHub Desktop.
Extract a test list from flutter drive log file
This file contains 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
#!/bin/bash | |
# extract the test list from flutter drive log and creates a file with [E] marking the failed ones | |
file="flutter-drive.log" | |
# get lines containing test titles (assuming they all contain a "TESTKEY-" string and titles are unique) | |
grep "^I/flutter .*TESTKEY-" "$file" > test-list | |
# remove extra lines related to failures | |
grep -v "The test description was:" test-list > tmpfile && mv tmpfile test-list | |
# get lines with skipped tests | |
awk '/~/ {print}' test-list > skip-list | |
# get column where skipped counter is | |
column=$(awk 'NR==1{ for (i=1; i<=NF; ++i) { if ($i ~ "~") { print i } } }' skip-list) | |
# remove colon if any | |
awk -v column="$column" '{gsub(/:/," :",$column)}1' skip-list > tmpskip && mv tmpskip skip-list | |
# extract only lines where skipped counter is increased | |
awk -v column="$column" '!skipped[$column]++' skip-list > tmpskip && mv tmpskip skip-list | |
# get only test titles in the skip-list file | |
cut -d ":" -f 4- skip-list > tmpskip && mv tmpskip skip-list | |
# remove heading space in skip-list file | |
sed 's/ //' skip-list > tmpskip && mv tmpskip skip-list | |
# get only test titles in the test-list file | |
cut -d ":" -f 4- test-list > tmpfile && mv tmpfile test-list | |
# remove heading space in test-list file | |
sed 's/ //' test-list > tmpfile && mv tmpfile test-list | |
# remove duplicate lines which flutter adds sometimes | |
cat -n test-list | sort -uk2 | sort -nk1 | cut -f2- > tmpfile && mv tmpfile test-list | |
# remove tests before the lines where skipped counter was incremented | |
while read -r line; do | |
awk -v line="$line" '$0 == line {for(x=NR-1;x<NR;x++)d[x];}{a[NR]=$0}END{for(i=1;i<=NR;i++)if(!(i in d))print a[i]}' test-list > tmpfile && mv tmpfile test-list | |
done < skip-list | |
# remove duplicate lines for failing tests (leave only the [E] ones) | |
awk '/\[E\]/{for(x=NR-1;x<NR;x++)d[x];}{a[NR]=$0}END{for(i=1;i<=NR;i++)if(!(i in d))print a[i]}' test-list > tmpfile && mv tmpfile test-list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment