-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cavalry.sh
executable file
·78 lines (67 loc) · 1.9 KB
/
Cavalry.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
#!/usr/bin/bash
source scripts/option.sh
source scripts/format.sh
source scripts/compile.sh
CONTAINERS=()
DIFF_FORMAT="-u"
USER_INCLUDES="-I.. -I../srcs"
# TO-DO: help command and error output
# Check if every container in the argument list can be tested
check_containers()
{
tested_containers=(vector stack map set)
for container in "$@"; do
tested=1
for tested_container in "${tested_containers[@]}"; do
if [ "$container" = "$tested_container" ]; then
tested=0
break
fi
done
if [ $tested -ne 0 ]; then
printf "%s\n" "$container cannot be tested. Tested containers are: vector, stack, map and set"
exit 1
fi
done
}
main()
{
print_header
# Setting up tested containers and options
parse_options "$@"
# Verifying both --leaks and --time options are not activated at the same time
if [ "$LEAKS" -eq 0 ] && [ "$TIME" -eq 0 ]; then
echo "Can't activate both --leaks and --time options at the same time. Deactivate one"
exit 1
fi
# Printing help if requested
if [ "$HELP" -eq 0 ]; then
print_help
fi
# Removing logs and executables if requested
if [ $# -eq 1 ] && [ "$1" = "clean" ]; then
rm -rf *.std *.ft logs/*
echo "Logs cleaned!"
exit 0
fi
# Launching tests
if [ "$FILE" -eq 0 ]; then
if [ ${#CONTAINERS[@]} -eq 0 ]; then
echo "No file selected. Select some files, or deactivate --file option."
exit 1
fi
test_files
printf "\n"
else
if [ "${#CONTAINERS[@]}" -eq 0 ]; then
CONTAINERS=(vector stack map set)
fi
check_containers "${CONTAINERS[@]}"
for container in "${CONTAINERS[@]}"; do
test_container "$container"
printf "\n"
done
fi
exit 0
}
main "$@"