Skip to content

Commit

Permalink
Merge pull request #376 from Raleksan/master
Browse files Browse the repository at this point in the history
#238 metrics grouping for report generation
  • Loading branch information
yegor256 authored Oct 8, 2024
2 parents ab23bb1 + 0da2399 commit a13ecb4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
34 changes: 31 additions & 3 deletions steps/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ if ! tlmgr --version >/dev/null 2>&1; then
export PATH
fi

if [ -z "${LOCAL_METRICS}" ]; then
LOCAL_METRICS=${LOCAL}/metrics
fi

list=${TARGET}/temp/list-of-metrics.tex
rm -f "${list}"
touch "${list}"

java=${TARGET}/temp/Foo.java
mkdir -p "$(dirname "${java}")"
find "${LOCAL}/metrics" -type f -exec test -x {} \; -exec basename {} \; | while IFS= read -r m; do
find "${LOCAL_METRICS}" -type f -exec test -x {} \; -exec basename {} \; | while IFS= read -r m; do
echo "class Foo {}" > "${java}"
metric=${TARGET}/temp/Foo.${m}.m
rm -f "${metric}"
"${LOCAL}/metrics/${m}" "${java}" "${metric}"
"${LOCAL_METRICS}/${m}" "${java}" "${metric}"
awk '{ s= "\\item\\ff{" $1 "}: "; for (i = 3; i <= NF; i++) s = s $i " "; print s; }' < "${metric}" >> "${list}"
echo "$(wc -l < "${metric}" | xargs) metrics from ${m}"
done
Expand All @@ -48,7 +52,31 @@ if [ ! -s "${list}" ]; then
exit 1
fi

sort -o "${list}" "${list}"
st_list=${TARGET}/temp/structured-list-of-metrics.tex
rm -f "${st_list}"
touch "${st_list}"

groups=()
while IFS='' read -r line; do
groups+=("$line")
done < <(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' | sort -u || : ; echo "Ungrouped metrics")
for idx in "${!groups[@]}"; do
if [ "$idx" -eq $(( ${#groups[@]} - 1 )) ]; then
group_metrics=$(grep -oP "^[^\[]*$" "${list}" || :)
else
group_metrics=$(grep -oP ".*\[\b${groups[$idx]}\b\].*" "${list}" || :)
fi
if [[ $(printf "%s\n" "${group_metrics[@]}" | grep -c "item") -eq 0 ]]; then continue; fi
printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}"
printf "\\\\begin{itemize}\n" >> "${st_list}"
while IFS= read -r metric; do
clean_metric="${metric//\[*\]/}"
printf "\t%s\n" "${clean_metric}" >> "${st_list}"
done <<< "$group_metrics"
printf "\\\\end{itemize}\n" >> "${st_list}"
done
cp "${list}" "${list}.unstructured"
mv "${st_list}" "${list}"

# It's important to make sure the path is absolute, for LaTeX
t=$(realpath "${TARGET}")
Expand Down
35 changes: 34 additions & 1 deletion tests/steps/test-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ echo "👍🏻 A PDF report generated correctly"
while IFS= read -r t; do
metric=$(echo "${t}" | cut -f1 -d' ')
echo "${metric}" | grep '^\\item\\ff{[a-zA-Z0-9-]\+}:$' > /dev/null
done < "${TARGET}/temp/list-of-metrics.tex"
done < "${TARGET}/temp/list-of-metrics.tex.unstructured"
} > "${stdout}" 2>&1
echo "👍🏻 A list of metrics is properly formatted"

{
mkdir -p "${TARGET}/temp/test_metric"
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" > "${TARGET}/temp/test_metric/group_test.sh"
chmod +x "${TARGET}/temp/test_metric/group_test.sh"
LOCAL_METRICS="${TARGET}/temp/test_metric" "${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 a13ecb4

Please sign in to comment.