130 lines
3.8 KiB
Bash
Executable File
130 lines
3.8 KiB
Bash
Executable File
#!/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}[ALERT] ${YELLOW}File ./alpha not found! Generating with 'make'.${WHITE}"
|
|
make
|
|
fi
|
|
|
|
if [ ! -d "./out" ]; then
|
|
mkdir -p out
|
|
fi
|
|
|
|
if [ $# -eq 0 ]; then
|
|
help
|
|
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
|
|
}
|
|
|
|
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}
|
|
|
|
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
|
|
|
|
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
|
|
}
|
|
|
|
|
|
|
|
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
|