This commit is contained in:
Scarlett
2025-05-03 19:25:55 -04:00
parent fbd08c634a
commit ea7c284665
64 changed files with 121 additions and 995 deletions

221
test.sh
View File

@ -20,147 +20,110 @@ LIGHTCYAN='\033[1;36m'
WHITE='\033[1;37m'
if [ ! -f "./alpha" ]; then
echo -e "${RED}[ERROR] ${YELLOW}File ./alpha not found!${WHITE}"
exit 1
echo -e "${RED}[ALERT] ${YELLOW}File ./alpha not found! Generating with 'make'.${WHITE}"
make
fi
if [ ! -d "./out" ]; then
mkdir -p out
fi
SWITCH=${YELLOW}
count=0
if [ $# -eq 0 ]; then
help
fi
switchfunc() {
if [ $count -eq 0 ]; then
count=1
SWITCH=${YELLOW}
else
count=0
SWITCH='\033[0;35m'
fi
help() {
echo -e "${GREEN}[HELP] ${YELLOW}Usage: ./test.sh <file> [-exp] ${WHITE}"
echo -e "${GREEN}[HELP] ${YELLOW}To all tests in a folder: ./test/sh <dir>/* [-exp]${WHITE}"
exit 1
}
if [ $# -eq 0 ]; then
echo -e "${YELLOW}[INFO] ${WHITE}Running all tests...${WHITE}"
echo -e "${YELLOW}[INFO] ${ORANGE}Testing SPRINT-1 ---------------------------\n${WHITE}"
for file in ./tests/sprint1/test/*; do
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
run() {
filename=$(basename -- "$1")
first_line=$(head -n 1 "$1")
if [[ "$first_line" == "\$\$ TEST: ["*"]"* ]]; then
if [ -n "$2" ]; then
if [[ "$2" == "-exp" ]]; then
bracket_content=$(echo "$first_line" | sed -n 's/.*\[\(.*\)\].*/\1/p')
sed -i '1d' "$1"
./alpha ${bracket_content} "$1"
sed -i "1s/^/$first_line\n/" "$1"
path=$(dirname "$1")
filename_noext=${filename:0:${#filename}-6}
echo -e "${YELLOW}[INFO] ${ORANGE}Testing SPRINT-2 ---------------------------\n${WHITE}"
for file in ./tests/sprint2/test/*; do
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
for file in out/${filename_noext}.*; do
if [[ "$file" == *".asc" || "$file" == *".s" || "$file" == *".st" || "$file" == *".tok" || "$file" == *".ir" ]]; then
for_filename=$(basename -- "$file")
for_filename="${for_filename}.exp"
if [ -f "${path}/../expected/${for_filename}" ]; then
echo -e "${RED}[ALERT] ${YELLOW}File ${path}/../expected/${for_filename} already exists! Overwriting...${WHITE}"
fi
cp "$file" "${path}/../expected/${for_filename}"
else
echo -e "${RED}[ALERT] ${YELLOW}Unexpected file found: $file ${WHITE}"
fi
done
else
echo -e "${BLUE}[ERROR] ${YELLOW}Invalid argument $2!${WHITE}"
help
fi
fi
echo -e "${YELLOW}[INFO] ${ORANGE}Testing SPRINT-3 ---------------------------\n${WHITE}"
for file in ./tests/sprint3/test/*; do
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
bracket_content=$(echo "$first_line" | sed -n 's/.*\[\(.*\)\].*/\1/p')
sed -i '1d' "$1"
./alpha ${bracket_content} "$1"
sed -i "1s/^/$first_line\n/" "$1"
else
echo -e "${RED}[ERROR] ${YELLOW}File $1 is not a valid .alpha test file!${WHITE}"
help
fi
}
echo -e "${YELLOW}[INFO] ${ORANGE}Testing SPRINT-4 ---------------------------\n${WHITE}"
for file in ./tests/sprint4/test/*; do
if [ -f "$file" ]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -cg "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}"
switchfunc
fi
done
else
if [ "$1" == "--help" ]; then
echo -e "${YELLOW}[INFO] ${WHITE}Usage: ./test.sh [prefix]"
echo -e "${YELLOW}[INFO] ${WHITE}--help: show this help message"
echo -e "${YELLOW}[INFO] ${WHITE}--file <file>: run test with file"
exit 0
fi
if [[ "$1" == "--file" ]]; then
shift
if [ $# -eq 0 ]; then
echo -e "${RED}[ERROR] ${YELLOW}No file specified!${WHITE}"
exit 1
fi
if [ -f "$1" ]; then
filename=$(basename -- "$1")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$1"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}"
exit 1
else
echo -e "${RED}[ERROR] ${YELLOW}File $1 not found!${WHITE}"
exit 1
fi
fi
if [[ "$1" == "sp1" ]]; then
echo -e "${YELLOW}[INFO] ${WHITE}Running tests with prefix $1..."
for file in ./tests/sprint1/test/*; do
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
elif [[ "$1" == "sp2" ]]; then
echo -e "${YELLOW}[INFO] ${WHITE}Running tests with prefix $1..."
for file in ./tests/sprint2/test/*; do
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
elif [[ "$1" == "sp3" ]]; then
echo -e "${YELLOW}[INFO] ${WHITE}Running tests with prefix $1..."
for file in ./tests/sprint3/test/*; do
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
elif [[ "$1" == "sp4" ]]; then
echo -e "${YELLOW}[INFO] ${WHITE}Running tests with prefix $1..."
for file in ./tests/sprint4/test/*; do
if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -cg -debug "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
else
echo -e "${RED}[ERROR] ${YELLOW}Invalid prefix $1!${WHITE}"
exit 1
fi
if [[ "$1" == *"/" ]]; then
if [ -n $2 ]; then
for file in "$1"/*; do
if [[ "$file" == *.alpha ]]; then
if [[ "$2" == "-exp" ]]; then
run "$file" "$2"
else
echo -e "${RED}[ERROR] ${YELLOW}Invalid argument $2!${WHITE}"
help
fi
else
echo -e "${RED}[ERROR] ${YELLOW}File $file is not a .alpha file!${WHITE}"
help
fi
done
else
for file in "$1"/*; do
if [[ "$file" == *.alpha ]]; then
run "$file"
else
echo -e "${RED}[ERROR] ${YELLOW}File $file is not a .alpha file!${WHITE}"
help
fi
done
fi
exit 0
fi
if [ -f "$1" ]; then
if [[ "$1" == *.alpha ]]; then
if [ -n "$2" ]; then
if [[ "$2" == "-exp" ]]; then
run "$1" "$2"
else
echo -e "${RED}[ERROR] ${YELLOW}Invalid argument $2!${WHITE}"
help
fi
else
run "$1"
fi
else
echo -e "${RED}[ERROR] ${YELLOW}File $1 is not a .alpha file!${WHITE}"
help
fi
fi