-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshellgame.bash
executable file
·96 lines (83 loc) · 1.63 KB
/
shellgame.bash
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
#!/bin/bash
function print_fail()
{
echo -en ""$RED"FAIL"$RESET"\n"
}
function print_pass()
{
echo -en ""$GREEN"PASS"$RESET"\n"
}
function check_output()
{
diff_output
print_diff $OUTPUT_DIFF
}
function diff_output()
{
diff "$YOUR_OUTPUT" "$EXPECTED_OUTPUT" > "$OUTPUT_DIFF"
}
function check_error()
{
diff_error
print_diff $ERROR_DIFF
}
function diff_error()
{
diff "$YOUR_ERROR" "$EXPECTED_ERROR" > "$ERROR_DIFF"
}
function print_diff()
{
if [ "$1" == "$OUTPUT_DIFF" ]; then
if [ -s "$1" ]; then
print_fail
echo "The output between your shell and 'sh' differ"
cat "$OUTPUT_DIFF"
else
print_pass
fi
elif [ "$1" == "$ERROR_DIFF" ]; then
if [ -s "$1" ]; then
print_fail
echo "The errors between your shell and 'sh' differ"
cat "$ERROR_DIFF"
else
print_pass
fi
else
echo -n "What are you diffing dude?\n"
fi
}
function clean_up()
{
> "$YOUR_OUTPUT" && > "$EXPECTED_OUTPUT"
> "$YOUR_ERROR" && > "$EXPECTED_ERROR"
> "$OUTPUT_DIFF" && > "$ERROR_DIFF"
rm -f "$HOME"/.simple_shell_history
rm -f "$LTRACEOUTPUTFILE"
rm -f checker_tmp_file_*
rm -f checker_cat_file_*
}
function stop_shell()
{
if [ $(pidof "$SHELL" | wc -l) -gt 0 ]; then
killall -9 "$SHELL" > /dev/null 2>&1
fi
clean_up
}
function launch_tests()
{
for dir in $(ls -d "$TESTDIR"/*/)
do
for testname in $(ls "$dir" | grep -v "~$")
do
echo "---------------------------------"
echo "Test for $dir$testname: "
source "$dir$testname"
echo "---------------------------------"
done
done
}
source config
clean_up
launch_tests
clean_up