-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathshellfish.bash
More file actions
executable file
·210 lines (199 loc) · 4.86 KB
/
shellfish.bash
File metadata and controls
executable file
·210 lines (199 loc) · 4.86 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
#
# Performing checks on the Holberton School "simple shell" project
#######################################
# Print KO, in red, followed by a new line
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
function print_ko()
{
echo -e "[\033[31mFAIL\033[37m]"
}
#######################################
# Print OK in green, followed by a new line
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
function print_ok()
{
echo -e "[\033[32mPASS\033[37m]"
}
#######################################
# Prints error messages if any
# Globals:
# RED
# ERROROUTPUTFILE
# ERROREXPECTED
# BLACK
# Arguments:
# None
# Returns:
# None
#######################################
function print_error()
{
if [[ -s "$ERROROUTPUTFILE" || -s "$ERROREXPECTED" ]]; then
echo "------------error outputs test--------------"
echo "--------------------------------------------"
if [ -s "$ERROROUTPUTFILE" ]; then
echo "< your error: "
echo "--------------------------------------------"
cat "$ERROROUTPUTFILE"
else
echo -ne "\033[31m"
echo "** your shell has nothing written to stdout **"
echo "** when there is an expected error output **"
fi
if [ -s "$ERROREXPECTED" ]; then
echo "> expected error: "
echo "--------------------------------------------"
cat "$ERROREXPECTED"
else
echo -ne "\033[31m"
echo "** there is no expected error, **"
echo "** but your shell writes to stderr **"
fi
fi
echo -ne "\033[37m"
}
#######################################
# Checks differences
# Globals:
# DIFF
# OUTPUTFILE
# EXPECTED
# Arguments:
# None
# Returns:
# None
#######################################
function check_diff()
{
diff "$OUTPUTFILE" "$EXPECTED" > "$DIFF"
if [ -s "$DIFF" ]; then
print_ko
echo -ne "\033[30m"
echo "--------------------!outputs differ!---------------------"
echo " your shell '<' -- expected output '>'"
echo "---------------------------------------------------------"
echo -ne "\033[31m"
cat "$DIFF"
echo -ne "\033[37m"
else
print_ok
fi
}
#######################################
# Checks for certain functions in your code
# Globals:
# LTRACEOUTPUTFILE
# Arguments:
# None
# Returns:
# None
#######################################
function check_function()
{
if [ -s "$DIFF" ]; then
print_ko
echo -ne "\033[30m"
echo "** ltrace returned these functions from your file:"
echo "% time seconds usecs/call calls function"
echo "------ ----------- ----------- --------- --------------------"
echo -ne "\033[31m"
cat "$DIFF"
echo -ne "\033[37m"
echo "------ ----------- ----------- --------- --------------------"
else
print_ok
fi
}
#######################################
# Kill the shell in a clean way and remove temporary files
# Globals:
# SHELL
# OUTPUTFILE
# EXPECTED
# DIFF
# ERROROUTPUTFILE
# ERROREXPECTED
# LTRACEOUTPUTFILE
# Arguments:
# None
# Returns:
# None
#######################################
function stop_shell()
{
if [ $(pidof "$SHELL" | wc -l) -ne 0 ]; then
killall -9 "$SHELL" > /dev/null 2>&1
fi
> "$OUTPUTFILE" && > "$EXPECTED" && > "$DIFF" && > "$ERROROUTPUTFILE" && > "$ERROREXPECTED"
rm -f "$LTRACEOUTPUTFILE"
rm -f checker_tmp_file_*
}
# Load configuration
source config
# Introduction
echo -ne "\033[34m"
echo " *************************************"
echo " *** ***"
echo -n " *** "
echo -ne "\033[32m"
echo -n "Beginning Test Suite "
echo -ne "\033[34m"
echo "***"
echo -n " *** "
echo -ne "\033[35m"
echo -n "Please be patient "
echo -ne "\033[34m"
echo "***"
echo -n " *** "
echo -ne "\033[36m"
echo -n "...and know the code "
echo -ne "\033[34m"
echo "***"
echo " *** ***"
echo " *************************************"
echo ""
echo -ne "\033[30m"
echo "contributors:"
cat AUTHORS | tail -n +2
echo ""
# Cleanup
echo -ne "\033[37m"
echo "--------------------------------------------"
echo "--------------------------------------------"
> "$OUTPUTFILE" && > "$EXPECTED" && > "$DIFF" && > "$ERROROUTPUTFILE" && > "$ERROREXPECTED"
rm -f "$HOME"/.simple_shell_history
rm -f "$LTRACEOUTPUTFILE"
rm -f checker_tmp_file_*
# Locates all tests and launch them
for dir in $(ls -d "$TESTDIR"/*/)
do
echo "--------------------------------------------"
echo " >> $dir"
echo "--------------------------------------------"
for testname in $(ls "$dir" | grep -v "~$")
do
cat "${dir}${testname}" | head -3 | tail -1
echo -n "test -> $testname: "
source "$dir$testname"
done
done
# Cleanup
> "$OUTPUTFILE" && > "$EXPECTED" && > "$DIFF" && > "$ERROROUTPUTFILE" && > "$ERROREXPECTED"
rm -f "$LTRACEOUTPUTFILE"
rm -f checker_tmp_file_*
rm -f /tmp/.checker_tmp_file_*
rm -f ./*txt
echo -ne "\033[30m"