Merge pull request #38 from UB-CSE443/Sprint3-DebugTools-FE-t#NoTask

Sprint3 debug tools fe t#no task
This commit is contained in:
scarlett
2025-03-28 22:24:36 -04:00
committed by GitHub
8 changed files with 242 additions and 32 deletions

View File

@ -6,8 +6,9 @@ CFLAGS :=
YACC := bison
TESTS-S1 := $(wildcard tests/sprint1/test/*.alpha)
TESTS-S3 := $(wildcard tests/sprint3/test/*.alpha)
TESTS-S2 := $(wildcard tests/sprint2/test/*.alpha)
TESTS-S3 := $(wildcard tests/sprint3/test/*.alpha)
TESTS-S4 := $(wildcard tests/sprint4/test/*.alpha)
compiler: clean runner
@ -33,22 +34,38 @@ runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o
debug: CFLAGS += -DDEBUG=1
debug: clean compiler
test: test-s1 test-s2 test-s3
test:
chmod +x ./check.sh
chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) || true);)
./test.sh sp2
./test.sh sp3
./test.sh sp4
./check.sh
test-s1:
chmod +x ./check.sh
for test in $(TESTS-S1); do ./$(EXE) -tok $$test || echo "Test $$test failed but continuing"; done
./check.sh
chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) || true);)
./check.sh sp1
test-s2:
chmod +x ./check.sh
for test in $(TESTS-S2); do ./$(EXE) -st $$test || echo "Test $$test failed but continuing"; done
./check.sh
chmod +x ./test.sh
./test.sh sp2
./check.sh sp2
test-s3:
chmod +x ./check.sh
for test in $(TESTS-S3); do ./$(EXE) -st $$test || echo "Test $$test failed but continuing"; done
./check.sh
chmod +x ./test.sh
./test.sh sp3
./check.sh sp3
test-s4:
chmod +x ./check.sh
chmod +x ./test.sh
./test.sh sp4
./check.sh sp4
clean:
rm -f *.o

View File

@ -5,34 +5,61 @@
# The Translators - Spring 2025 #
TOK_DIR="out"
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
WHITE='\033[0m'
PURPLE='\033[0;35m'
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}"
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 "Directory $TOK_DIR does not exist."
echo -e "${RED}[ERROR] ${YELLOW}Directory $TOK_DIR does not exist.${NOCOLOR}"
exit 1
fi
echo -e "\n"
for file in "$TOK_DIR"/*; do
filename=$(basename -- "$file")
filename="${filename%.*}"
num=${filename:2:1}
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."
else
echo -e "\n${RED}[✘] ${PURPLE}$file ${WHITE}failed with an unexpected value..."
diff --color=always "$file" "$exp"
echo -e ""
fi
else
echo -e "${ORANGE}[-] ${PURPLE}$filename ${WHITE}does not have an expected value."
fi
done
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

View File

@ -1001,4 +1001,4 @@ TableNode *getNextEntry(TableNode *tn) { return tn->next; }
printf("The type of the first entry is %s\n",First_Entry->theType);
return 0;
}
*/
*/

166
test.sh Executable file
View File

@ -0,0 +1,166 @@
#!/bin/bash
# Test Tool #
# The Translators - Spring 2025 #
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'
if [ ! -f "./alpha" ]; then
echo -e "${RED}[ERROR] ${YELLOW}File ./alpha not found!${WHITE}"
exit 1
fi
if [ ! -d "./out" ]; then
mkdir -p out
fi
SWITCH=${YELLOW}
count=0
switchfunc() {
if [ $count -eq 0 ]; then
count=1
SWITCH=${YELLOW}
else
count=0
SWITCH='\033[0;35m'
fi
}
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 "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
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 "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
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 "$file"
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc
fi
done
echo -e ""
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 -st "$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 "$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 "$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 "$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 "$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 -st "$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
fi