Skip to content

Commit

Permalink
Add metric grouping test
Browse files Browse the repository at this point in the history
  • Loading branch information
Raleksan committed Oct 4, 2024
1 parent 7ad9a49 commit 81871bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion steps/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ touch "${st_list}"
groups=()
while IFS='' read -r line; do
groups+=("$line")
done < <(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ; echo "Ungrouped metrics")
done < <(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' | sort -u || : ; echo "Ungrouped metrics")
for idx in "${!groups[@]}"; do
printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}"
printf "\\\\begin{itemize}\n" >> "${st_list}"
Expand Down
32 changes: 32 additions & 0 deletions tests/steps/test-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,35 @@ echo "👍🏻 A PDF report generated correctly"
done < "${TARGET}/temp/list-of-metrics.tex.unstructured"
} > "${stdout}" 2>&1
echo "👍🏻 A list of metrics is properly formatted"

{
test_metric_sh="#!/bin/bash\n\n"
test_metric_sh+="output=\$(realpath \"\$2\")\n"
test_metric_sh+="for idx in {2..5}; do\n"
test_metric_sh+=" echo \"Test-\${idx} 0 [Test group \$((idx % 2))] Test metrics\" >> \"\${output}\"\n"
test_metric_sh+="done\n"
printf "%b" "$test_metric_sh" > "${LOCAL}/metrics/group_test.sh"
chmod +x "${LOCAL}/metrics/group_test.sh"
"${LOCAL}/steps/report.sh"
test -e "${TARGET}/report.pdf"
pdftotext "${TARGET}/report.pdf" "${TARGET}/report.txt"
txt=$(cat "${TARGET}/report.txt")
actual=$(echo "${txt}" | grep -c '.*Test group [0-9]\+')
if [ "$actual" != "2" ]; then
echo "Exactly 2 test group names were expected, but ${actual} were actually found"
exit 1
fi
awk '
/Test group 0/ { in_group_0 = 1; in_group_1 = 0 }
/Test group 1/ { in_group_0 = 0; in_group_1 = 1 }
in_group_0 && /Test-(2|4): Test metrics/ { group_0_valid++ }
in_group_1 && /Test-(3|5): Test metrics/ { group_1_valid++ }
END {
if (group_0_valid != 2 || group_1_valid != 2) {
printf "Expected 2 valid metrics in each group, but found %d in group 0 and %d in group 1\n", group_0_valid, group_1_valid
exit 1
}
}
' <<< "$txt"
} > "${stdout}" 2>&1
echo "👍🏻 Grouping is properly formatted for the list of metrics."

0 comments on commit 81871bc

Please sign in to comment.