-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun.sh
executable file
·79 lines (71 loc) · 1.72 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
BASE_FOLDER="~/joaonette"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
if [[ -z $LIST ]]
then
echo "Either export LIST or add the list name before calling the script"
exit 1
fi
check_names()
{
EX_COUNT=$(ls */* | wc -l)
USER_FILES=$(ls */*)
EXPECTED_NAMES=$(cat ~/joaonette/$LIST/expected_files | head -n $EX_COUNT)
echo "====== filenames ======"
if [[ $(diff <(echo $USER_FILES) <(echo $EXPECTED_NAMES)) ]]; then
echo -e "KO ${RED}✖${NC}"
echo -e "\n--- EXPECTED ---"
echo -e $EXPECTED_NAMES
echo -e "\n--- USER FILES ---"
echo -e $USER_FILES
else
echo -e "OK ${GREEN}✓${NC}"
fi
}
check_exercise()
{
ERROR=""
cp -f ~/joaonette/$LIST/$DIR/* ./
gcc -Wall -Wextra -Werror -lbsd *.c -o test.out || ERROR=true
DIFF=$(diff <(./test.out) ~/joaonette/$LIST/$DIR/expected_output) || ERROR=true
if [[ $(basename $PWD) == ex* ]]; then
if [[ -n "$DIFF" ]]; then
echo -e "\n--- EXPECTED OUTPUT ---"
cat ~/joaonette/$LIST/$DIR/expected_output
echo -e "\n--- USER OUTPUT ---"
./test.out
fi
fi
if [[ "$DIFF" == "" && "$ERROR" == "" ]]; then
echo -e "OK ${GREEN}✓${NC}"
else
echo -e "KO ${RED}✖${NC}"
fi
if [ "$UPDATE" = "true" ] ; then
echo -e "\nUpdating expected_output..."
./test.out > ~/joaonette/$LIST/$DIR/expected_output
fi
rm ./expected_output
rm ./main.c
rm ./test.out
}
# If you are inside an exercise folder (starting with ex)
# check the current exercise
if [[ $(basename $PWD) == ex* ]]; then
DIR=$(basename $PWD)
echo "====== $LIST/$DIR ======"
LOCAL=$PWD
check_exercise
# If you are not in an exercise folder, correct the entire list
else
check_names
for DIR in * ; do
echo "====== $LIST/$DIR ======"
LOCAL="$DIR"
cd $DIR
check_exercise
cd ..
done
fi