From 2595606f143087f8bf73a12f13cafb5d6c21d064 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Tue, 1 Oct 2024 21:17:28 +0300 Subject: [PATCH 01/15] First version of metrics grouping for report generation --- metrics/ast.py | 8 ++++---- steps/report.sh | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/metrics/ast.py b/metrics/ast.py index 8312991d..58d989a7 100755 --- a/metrics/ast.py +++ b/metrics/ast.py @@ -457,13 +457,13 @@ class NotClassError(Exception): if not (tree_class := list((value for value in tree))): raise NotClassError('This is not a class') with open(metrics, 'a', encoding='utf-8') as metric: - metric.write(f'NoOA {attrs(tree_class)} ' + metric.write(f'NoOA {attrs(tree_class)} [CAM]' f'Number of Non-Static (Object) Attributes\n') - metric.write(f'NoSA {sattrs(tree_class)} ' + metric.write(f'NoSA {sattrs(tree_class)} [CAMt]' f'Number of Static Attributes\n') - metric.write(f'NoCC {ctors(tree_class)} ' + metric.write(f'NoCC {ctors(tree_class)} [CAMtt]' f'Number of Class Constructors\n') - metric.write(f'NoOM {methods(tree_class)} ' + metric.write(f'NoOM {methods(tree_class)} [CAMttt]' f'Number of Non-Static (Object) Methods\n') metric.write(f'NoCM {smethods(tree_class)} ' f'Number of Static (Class) Methods\n') diff --git a/steps/report.sh b/steps/report.sh index 366d190c..2fdca151 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -48,7 +48,40 @@ if [ ! -s "${list}" ]; then exit 1 fi -sort -o "${list}" "${list}" +groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g') "") + +st_list=${TARGET}/temp/structured-list-of-metrics.tex +rm -f "${st_list}" +touch "${st_list}" + +for group in "${groups[@]}"; do + + if [[ -z "$group" ]]; then + echo "\item Ungrouped Metrics" >> "${st_list}" + else + echo "\item $group" >> "${st_list}" + fi + + echo " \begin{itemize}" >> "${st_list}" + + if [[ -z "$group" ]]; then + group_metrics=$(grep -oP "^[^\[]*$" "${list}") + else + group_metrics=$(grep -oP ".*\[\b${group}\b\].*" "${list}") + fi + + for metric in "${group_metrics[@]}"; do + printf "\t%s\n" "$metric" >> "${st_list}" + done + + echo " \end{itemize}" >> "${st_list}" + +done + +sed -i 's/\[[^]]*\]//g' "${st_list}" + +mv "${st_list}" "${list}" + # It's important to make sure the path is absolute, for LaTeX t=$(realpath "${TARGET}") From fb1ca87c2d99146b331d07af6a0ae7ac60ea508f Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Wed, 2 Oct 2024 20:05:56 +0300 Subject: [PATCH 02/15] Correcting empty lines --- steps/report.sh | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index 2fdca151..11d08052 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -48,41 +48,32 @@ if [ ! -s "${list}" ]; then exit 1 fi -groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g') "") - st_list=${TARGET}/temp/structured-list-of-metrics.tex rm -f "${st_list}" touch "${st_list}" +groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g') "") for group in "${groups[@]}"; do - if [[ -z "$group" ]]; then echo "\item Ungrouped Metrics" >> "${st_list}" else echo "\item $group" >> "${st_list}" fi - echo " \begin{itemize}" >> "${st_list}" - if [[ -z "$group" ]]; then group_metrics=$(grep -oP "^[^\[]*$" "${list}") else group_metrics=$(grep -oP ".*\[\b${group}\b\].*" "${list}") fi - for metric in "${group_metrics[@]}"; do printf "\t%s\n" "$metric" >> "${st_list}" done - echo " \end{itemize}" >> "${st_list}" - done sed -i 's/\[[^]]*\]//g' "${st_list}" - mv "${st_list}" "${list}" - # It's important to make sure the path is absolute, for LaTeX t=$(realpath "${TARGET}") From e49376716004081e496e898a400c1eb5f1adffc4 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Wed, 2 Oct 2024 20:38:40 +0300 Subject: [PATCH 03/15] Fixes a linting issue with the 'echo' command --- steps/report.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index 11d08052..23e669e7 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -59,7 +59,7 @@ for group in "${groups[@]}"; do else echo "\item $group" >> "${st_list}" fi - echo " \begin{itemize}" >> "${st_list}" + echo "\begin{itemize}" >> "${st_list}" if [[ -z "$group" ]]; then group_metrics=$(grep -oP "^[^\[]*$" "${list}") else @@ -68,7 +68,7 @@ for group in "${groups[@]}"; do for metric in "${group_metrics[@]}"; do printf "\t%s\n" "$metric" >> "${st_list}" done - echo " \end{itemize}" >> "${st_list}" + echo "\end{itemize}" >> "${st_list}" done sed -i 's/\[[^]]*\]//g' "${st_list}" From 99dd940a6b6ec1fb278da66382375b1fa5f16d50 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Wed, 2 Oct 2024 20:54:29 +0300 Subject: [PATCH 04/15] Updating a test for the metric format and adding a new test for the group format --- tests/steps/test-report.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/steps/test-report.sh b/tests/steps/test-report.sh index 99a7b7c0..2d535b64 100755 --- a/tests/steps/test-report.sh +++ b/tests/steps/test-report.sh @@ -55,9 +55,23 @@ echo "👍🏻 Dependencies are available" 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 + while IFS= read -r line; do + if [[ "$line" =~ ^[[:space:]]*\\item\\ff\{[a-zA-Z0-9-]+\}: ]]; then + printf "Valid metric: %s\n" "$line" + else + printf "Invalid metric format: %s\n" "$line" + fi done < "${TARGET}/temp/list-of-metrics.tex" } > "${stdout}" 2>&1 echo "👍🏻 A list of metrics is properly formatted" + +{ + while IFS= read -r line; do + if [[ "$line" =~ ^\\item[[:space:]]* ]]; then + printf "Valid group: %s\n" "$line" + else + printf "Invalid group format: %s\n" "$line" + fi + done < "${TARGET}/temp/list-of-metrics.tex" +} > "${stdout}" 2>&1 +echo "👍🏻 Groups are properly formatted" \ No newline at end of file From 5f7050de84fa5d46b4c14ff6cfedf7ef42f8a029 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Wed, 2 Oct 2024 21:18:30 +0300 Subject: [PATCH 05/15] Revert changes for metrics and fix report generation when no groups are present --- metrics/ast.py | 8 ++++---- steps/report.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/metrics/ast.py b/metrics/ast.py index 58d989a7..d1508d5e 100755 --- a/metrics/ast.py +++ b/metrics/ast.py @@ -457,13 +457,13 @@ class NotClassError(Exception): if not (tree_class := list((value for value in tree))): raise NotClassError('This is not a class') with open(metrics, 'a', encoding='utf-8') as metric: - metric.write(f'NoOA {attrs(tree_class)} [CAM]' + metric.write(f'NoOA {attrs(tree_class)}' f'Number of Non-Static (Object) Attributes\n') - metric.write(f'NoSA {sattrs(tree_class)} [CAMt]' + metric.write(f'NoSA {sattrs(tree_class)}' f'Number of Static Attributes\n') - metric.write(f'NoCC {ctors(tree_class)} [CAMtt]' + metric.write(f'NoCC {ctors(tree_class)}' f'Number of Class Constructors\n') - metric.write(f'NoOM {methods(tree_class)} [CAMttt]' + metric.write(f'NoOM {methods(tree_class)}' f'Number of Non-Static (Object) Methods\n') metric.write(f'NoCM {smethods(tree_class)} ' f'Number of Static (Class) Methods\n') diff --git a/steps/report.sh b/steps/report.sh index 23e669e7..cb8feba7 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -52,7 +52,7 @@ st_list=${TARGET}/temp/structured-list-of-metrics.tex rm -f "${st_list}" touch "${st_list}" -groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g') "") +groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ) "") for group in "${groups[@]}"; do if [[ -z "$group" ]]; then echo "\item Ungrouped Metrics" >> "${st_list}" From 9491c2e6fcb3d5e54259577c25a3c3940b689da8 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Wed, 2 Oct 2024 21:22:40 +0300 Subject: [PATCH 06/15] Trying to fix shellcheck again --- steps/report.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index cb8feba7..2e7b053a 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -55,11 +55,11 @@ touch "${st_list}" groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ) "") for group in "${groups[@]}"; do if [[ -z "$group" ]]; then - echo "\item Ungrouped Metrics" >> "${st_list}" + echo "\\item Ungrouped Metrics" >> "${st_list}" else - echo "\item $group" >> "${st_list}" + echo "\\item $group" >> "${st_list}" fi - echo "\begin{itemize}" >> "${st_list}" + echo "\\begin{itemize}" >> "${st_list}" if [[ -z "$group" ]]; then group_metrics=$(grep -oP "^[^\[]*$" "${list}") else @@ -68,7 +68,7 @@ for group in "${groups[@]}"; do for metric in "${group_metrics[@]}"; do printf "\t%s\n" "$metric" >> "${st_list}" done - echo "\end{itemize}" >> "${st_list}" + echo "\\end{itemize}" >> "${st_list}" done sed -i 's/\[[^]]*\]//g' "${st_list}" From 54ac2a372a84f39c9408317b879b6ec581eea077 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 21:31:32 +0300 Subject: [PATCH 07/15] Completed grouping of metrics for report generation --- steps/report.sh | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index 2e7b053a..520de9cb 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -52,26 +52,22 @@ st_list=${TARGET}/temp/structured-list-of-metrics.tex rm -f "${st_list}" touch "${st_list}" -groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ) "") -for group in "${groups[@]}"; do - if [[ -z "$group" ]]; then - echo "\\item Ungrouped Metrics" >> "${st_list}" - else - echo "\\item $group" >> "${st_list}" - fi - echo "\\begin{itemize}" >> "${st_list}" - if [[ -z "$group" ]]; then +groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ) "Ungrouped metrics") +for idx in ${!groups[@]}; do + printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}" + printf "\\\\begin{itemize}\n" >> "${st_list}" + if [ "$idx" -eq $(( ${#groups[@]} - 1 )) ]; then group_metrics=$(grep -oP "^[^\[]*$" "${list}") else - group_metrics=$(grep -oP ".*\[\b${group}\b\].*" "${list}") + group_metrics=$(grep -oP ".*\[\b${groups[$idx]}\b\].*" "${list}") fi - for metric in "${group_metrics[@]}"; do - printf "\t%s\n" "$metric" >> "${st_list}" - done - echo "\\end{itemize}" >> "${st_list}" + while IFS= read -r metric; do + clean_metric=$(echo "$metric" | sed 's/\[[^]]*\]//g') + printf "\t%s\n" "$clean_metric" >> "${st_list}" + done <<< "$group_metrics" + printf "\\\\end{itemize}\n" >> "${st_list}" done - -sed -i 's/\[[^]]*\]//g' "${st_list}" +cp "${list}" "${list}.unstructured" mv "${st_list}" "${list}" # It's important to make sure the path is absolute, for LaTeX From 31121beab7ef3cfc724b75801c8575da3bec52be Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 22:07:21 +0300 Subject: [PATCH 08/15] Revert to the old test for report generation --- tests/steps/test-report.sh | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/tests/steps/test-report.sh b/tests/steps/test-report.sh index 2d535b64..d3e84a05 100755 --- a/tests/steps/test-report.sh +++ b/tests/steps/test-report.sh @@ -55,23 +55,9 @@ echo "👍🏻 Dependencies are available" echo "👍🏻 A PDF report generated correctly" { - while IFS= read -r line; do - if [[ "$line" =~ ^[[:space:]]*\\item\\ff\{[a-zA-Z0-9-]+\}: ]]; then - printf "Valid metric: %s\n" "$line" - else - printf "Invalid metric format: %s\n" "$line" - fi - done < "${TARGET}/temp/list-of-metrics.tex" + 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.unstructured" } > "${stdout}" 2>&1 echo "👍🏻 A list of metrics is properly formatted" - -{ - while IFS= read -r line; do - if [[ "$line" =~ ^\\item[[:space:]]* ]]; then - printf "Valid group: %s\n" "$line" - else - printf "Invalid group format: %s\n" "$line" - fi - done < "${TARGET}/temp/list-of-metrics.tex" -} > "${stdout}" 2>&1 -echo "👍🏻 Groups are properly formatted" \ No newline at end of file From a16a41bf85f7fd5e3b622a5c37d29043b5f3d01b Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 22:17:41 +0300 Subject: [PATCH 09/15] Fix shellcheck issue with array --- steps/report.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index 520de9cb..cd3af589 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -52,8 +52,11 @@ st_list=${TARGET}/temp/structured-list-of-metrics.tex rm -f "${st_list}" touch "${st_list}" -groups=($(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ) "Ungrouped metrics") -for idx in ${!groups[@]}; do +groups=() +while IFS='' read -r line; do + groups+=("$line") +done < <(grep -oP '\[.*?\]' "${list}" | sed 's/[][]//g' || : ; echo "Ungrouped metrics") +for idx in "${!groups[@]}"; do printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}" printf "\\\\begin{itemize}\n" >> "${st_list}" if [ "$idx" -eq $(( ${#groups[@]} - 1 )) ]; then From bbe243f899d86418bd3d8709d1b2881383e86d05 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 22:30:57 +0300 Subject: [PATCH 10/15] Fix shellcheck issue with variable usage --- steps/report.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steps/report.sh b/steps/report.sh index cd3af589..b1d23843 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -65,7 +65,7 @@ for idx in "${!groups[@]}"; do group_metrics=$(grep -oP ".*\[\b${groups[$idx]}\b\].*" "${list}") fi while IFS= read -r metric; do - clean_metric=$(echo "$metric" | sed 's/\[[^]]*\]//g') + clean_metric=$(echo "${metric}" | sed 's/\[[^]]*\]//g') printf "\t%s\n" "$clean_metric" >> "${st_list}" done <<< "$group_metrics" printf "\\\\end{itemize}\n" >> "${st_list}" From 0362472ef28686ff3e69c093c8debda92606e10d Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 22:39:07 +0300 Subject: [PATCH 11/15] Remembered about the local linter. All problems fixed --- steps/report.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index b1d23843..b430df1f 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -65,8 +65,8 @@ for idx in "${!groups[@]}"; do group_metrics=$(grep -oP ".*\[\b${groups[$idx]}\b\].*" "${list}") fi while IFS= read -r metric; do - clean_metric=$(echo "${metric}" | sed 's/\[[^]]*\]//g') - printf "\t%s\n" "$clean_metric" >> "${st_list}" + clean_metric="${metric//\[*\]/}" + printf "\t%s\n" "${clean_metric}" >> "${st_list}" done <<< "$group_metrics" printf "\\\\end{itemize}\n" >> "${st_list}" done From 7ad9a49ead88e4a575295d54d1d730387f813b6d Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Thu, 3 Oct 2024 22:41:37 +0300 Subject: [PATCH 12/15] Revert changes for metrics/ast.py --- metrics/ast.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/metrics/ast.py b/metrics/ast.py index d1508d5e..8312991d 100755 --- a/metrics/ast.py +++ b/metrics/ast.py @@ -457,13 +457,13 @@ class NotClassError(Exception): if not (tree_class := list((value for value in tree))): raise NotClassError('This is not a class') with open(metrics, 'a', encoding='utf-8') as metric: - metric.write(f'NoOA {attrs(tree_class)}' + metric.write(f'NoOA {attrs(tree_class)} ' f'Number of Non-Static (Object) Attributes\n') - metric.write(f'NoSA {sattrs(tree_class)}' + metric.write(f'NoSA {sattrs(tree_class)} ' f'Number of Static Attributes\n') - metric.write(f'NoCC {ctors(tree_class)}' + metric.write(f'NoCC {ctors(tree_class)} ' f'Number of Class Constructors\n') - metric.write(f'NoOM {methods(tree_class)}' + metric.write(f'NoOM {methods(tree_class)} ' f'Number of Non-Static (Object) Methods\n') metric.write(f'NoCM {smethods(tree_class)} ' f'Number of Static (Class) Methods\n') From 81871bc6c0bec0534433b836f289a6b8565d03e6 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Fri, 4 Oct 2024 19:38:46 +0300 Subject: [PATCH 13/15] Add metric grouping test --- steps/report.sh | 2 +- tests/steps/test-report.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/steps/report.sh b/steps/report.sh index b430df1f..1649cdc2 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -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}" diff --git a/tests/steps/test-report.sh b/tests/steps/test-report.sh index d3e84a05..d7607545 100755 --- a/tests/steps/test-report.sh +++ b/tests/steps/test-report.sh @@ -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." \ No newline at end of file From 6fb885053146cd05a1660a0a824ce82ffa6a2051 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Tue, 8 Oct 2024 19:00:35 +0300 Subject: [PATCH 14/15] Adding metrics directory overrides --- steps/report.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/steps/report.sh b/steps/report.sh index 1649cdc2..07897eb0 100755 --- a/steps/report.sh +++ b/steps/report.sh @@ -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 @@ -57,13 +61,14 @@ 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 - printf "\\item %s\n" "${groups[$idx]}" >> "${st_list}" - printf "\\\\begin{itemize}\n" >> "${st_list}" if [ "$idx" -eq $(( ${#groups[@]} - 1 )) ]; then - group_metrics=$(grep -oP "^[^\[]*$" "${list}") + group_metrics=$(grep -oP "^[^\[]*$" "${list}" || :) else - group_metrics=$(grep -oP ".*\[\b${groups[$idx]}\b\].*" "${list}") + 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}" From 0da23996e7164ec6604f2a8b0ba1848024645004 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabov Date: Tue, 8 Oct 2024 19:02:01 +0300 Subject: [PATCH 15/15] Moving a group formatting test to a separate folder --- tests/steps/test-report.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/steps/test-report.sh b/tests/steps/test-report.sh index d7607545..09d17592 100755 --- a/tests/steps/test-report.sh +++ b/tests/steps/test-report.sh @@ -63,14 +63,15 @@ echo "👍🏻 A PDF report generated correctly" 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" > "${LOCAL}/metrics/group_test.sh" - chmod +x "${LOCAL}/metrics/group_test.sh" - "${LOCAL}/steps/report.sh" + 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")