#!/bin/bash # Check if a start directory is provided if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi start_dir="${1%/}" reverse_path() { local original_path=$1 IFS='/' read -ra ADDR <<< "$original_path" local reversed_path="" for (( i=${#ADDR[@]}-1 ; i>=0 ; i-- )) ; do reversed_path+="${ADDR[i]}" if [ $i -gt 0 ]; then reversed_path+="/" fi done echo "$reversed_path" } convert_path() { local path=${1#./} local modified_path=${path#*/} echo "$modified_path" } temp_file=$(mktemp) find "$start_dir" -type d -not -path '*/__pycache__*' | while read -r dir; do slash_count=$(tr -cd '/' <<< "$dir" | wc -c) echo "$dir $slash_count" >> "$temp_file" done echo "Test Results" echo "" sort -k1,1r -k2,2nr "$temp_file" | while read -r dir slash_count; do total_pass=0 total_fail=0 files_no_totals=0 had_files=false while read -r file; do pass=$(tac "$file" | grep -oP 'Successes: \K\d+' | head -n 1 | bc || echo 0) fail=$(tac "$file" | grep -oP 'Failures: \K\d+' | head -n 1 | bc || echo 0) total_pass=$((total_pass + pass)) total_fail=$((total_fail + fail)) had_files=true done < <(find "$dir" -name "*.metta.html" -type f) if [ "$had_files" = true ]; then dir_percent=0 total_tests=$((total_pass + total_fail + files_no_totals)) if [ "$total_tests" -gt 0 ]; then dir_percent=$((100 * total_pass / total_tests)) mdir="$(convert_path "$dir")" printf "\n" "$total_pass" "$total_fail" "$files_no_totals" "$dir_percent" "$(reverse_path "$mdir")" "$mdir" fi fi done # Closing the initial table echo "
PassFailMissPercentModuleDirectory
%d%d%s%d%%%s%s



" base_url="https://logicmoo.org/public/metta/" sort -k2,2n "$temp_file" | while read -r dir slash_count; do total_pass=0 total_fail=0 had_files=false cat /dev/null > file_info.tmp while read -r file; do if [[ -f "$file" ]]; then pass=$(tac "$file" | grep -oP 'Successes: \K\d+' | head -n 1 | bc || echo 0) fail=$(tac "$file" | grep -oP 'Failures: \K\d+' | head -n 1 | bc || echo 0) total_pass=$((total_pass + pass)) total_fail=$((total_fail + fail)) had_files=true file_percent=0 total_file_tests=$((pass + fail)) if [ "$total_file_tests" -gt 0 ]; then file_percent=$((100 * pass / total_file_tests)) fi relative_path=$(echo "$file" | sed 's/^\.\///' | sed -e 's|examples|reports|g' -e 's|-reports|-examples|g') github_link="${base_url}${relative_path}" printf "%d%d%d%%%s\n" "$pass" "$fail" "$file_percent" "$github_link" "$(basename "${file%.html}")" >> file_info.tmp fi done < <(find "$dir" -name "*.metta.html" -type f -maxdepth 1) if [ "$had_files" = true ]; then total_tests=$((total_pass + total_fail)) dir_percent=0 if [ "$total_tests" -gt 0 ]; then dir_percent=$((100 * total_pass / total_tests)) mdir="$(convert_path "$dir")" echo "" echo "" cat file_info.tmp # Adding a total summary row for the directory echo "" echo "
Directory: ./$mdir
PassFailPercentFile/Module/Directory
$total_pass$total_fail$dir_percent%Total

" fi fi done echo "" rm "$temp_file" # Clean up the temporary file rm file_info.tmp # Clean up temporary file