Files
compiler-the-translators/check.sh
2025-04-07 15:51:45 -04:00

67 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Diff-Check Tool #
# Checks if outputed TOK = exp #
# The Translators - Spring 2025 #
TOK_DIR="out"
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTGRAY='\033[0;37m'
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
LIGHTPURPLE='\033[1;35m'
LIGHTCYAN='\033[1;36m'
WHITE='\033[1;37m'
compare_files() {
local file="$1"
local filename=$(basename -- "$file")
filename="${filename%.*}"
local num=${filename:2:1}
local exp="./tests/sprint$num/expected/$filename.expected"
if [[ -f "$exp" ]]; then
diff -q "$file" "$exp" > /dev/null
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}[✔] ${PURPLE}$filename ${WHITE}passed.${NOCOLOR}"
elif [[ ! -s "$file" ]]; then
echo -e "${RED}[✘] ${PURPLE}$filename ${WHITE}failed with an empty file. (did it segfault?)${NOCOLOR}"
else
echo -e "\n${RED}[✘] ${PURPLE}$file ${WHITE}failed with an unexpected value...${NOCOLOR}"
diff --color=always "$file" "$exp"
echo -e ""
fi
else
echo -e "${ORANGE}[-] ${PURPLE}$filename ${WHITE}does not have an expected value.${NOCOLOR}"
fi
}
if [[ ! -d "$TOK_DIR" ]]; then
echo -e "${RED}[ERROR] ${YELLOW}Directory $TOK_DIR does not exist.${NOCOLOR}"
exit 1
fi
if [[ $# -eq 0 ]]; then
for file in "$TOK_DIR"/*; do
compare_files "$file"
done
elif [[ $# -eq 1 ]]; then
prefix="$1"
for file in "$TOK_DIR"/"$prefix"*; do
if [[ -f "$file" ]]; then
compare_files "$file"
fi
done
else
echo -e "${LIGHTBLUE}Usage: $0 [sp#]${NOCOLOR}"
exit 1
fi