-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.sh
More file actions
executable file
·160 lines (138 loc) · 4.65 KB
/
check.sh
File metadata and controls
executable file
·160 lines (138 loc) · 4.65 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
#!/bin/bash
# Usage : ./check.sh | less -r
# copy this file inside your project folder and run ./checker.sh | less -r
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh
function run_check()
{
echo "--> [" $1 "] <--"
chars1=$(wc -m < 1a2b3c4d5e6f7g8h9i)
chars2=$(wc -m < 1a2b3c4d5e6f7g8h9b)
if diff 1a2b3c4d5e6f7g8h9i 1a2b3c4d5e6f7g8h9b >/dev/null; then
echo -e "\e[32mSuccess\e[0m"
else
echo -e "\e[31mFailed\e[0m"
echo -e "\e[0m[Got]\e[31m"
cat 1a2b3c4d5e6f7g8h9i
echo -e "\e[0m[" $chars1 "Chars]\e[31m"
echo -e "\e[0m[Expected]\e[31m"
cat 1a2b3c4d5e6f7g8h9b
echo -e "\e[0m[" $chars2 "Chars]\e[0m"
fi
rm 1a2b3c4d5e6f7g8h9i 1a2b3c4d5e6f7g8h9b;
echo "************************************"
}
######### case 1
command1=$(echo "ls" | ./hsh 2>&1)
command2=$(echo "ls" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls""
######### case 2
command1=$(echo "/bin/ls" | ./hsh 2>&1)
command2=$(echo "/bin/ls" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""/bin/ls""
######### case 3
command1=$(echo "/bin/ls -l" | ./hsh 2>&1)
command2=$(echo "/bin/ls -l" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" with "-l" option"
######### case 4
command1=$(echo "/bin/ls -l /tmp" | ./hsh 2>&1)
command2=$(echo "/bin/ls -l /tmp" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" with "-l" and "/tmp" option"
######### case 5
command1=$(echo " /bin/ls" | ./hsh 2>&1)
command2=$(echo " /bin/ls" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" with "spaces" before"
######### case 6
command1=$(echo "/bin/ls " | ./hsh 2>&1)
command2=$(echo "/bin/ls " | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""/bin/ls" with "spaces" after"
######### case 7
command1=$(echo " /bin/ls " | ./hsh 2>&1)
command2=$(echo " /bin/ls " | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""/bin/ls" with "spaces" before and after"
######### case 8
command1=$(echo "echo hello world" | ./hsh 2>&1)
command2=$(echo "echo hello world" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""echo" "
######### case 9
command1=$(echo "/bin/ls /home /usr" | ./hsh 2>&1)
command2=$(echo "/bin/ls /home /usr" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""/bin/ls" multiple dir"
######### case 10
command1=$(echo "ls /home /usr" | ./hsh 2>&1)
command2=$(echo "ls /home /usr" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" multiple dir"
######### case 11
command1=$(echo "ls /home /usr /bin /home" | ./hsh 2>&1)
command2=$(echo "ls /home /usr /bin /home" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" multiple dir"
######### case 12
command1=$(echo "ls /homezzz" | ./hsh 2>&1)
command2=$(echo "ls /homezzz" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""ls" non existing dir"
######### case 13
command1=$(echo "mkdir my_testDir22" | ./hsh 2>&1)
command2=$(echo "mkdir my_testDir23" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""mkdir" "
######### case 14
command1=$(echo "rmdir my_testDir22" | ./hsh 2>&1)
command2=$(echo "rmdir my_testDir23" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""rmdir" "
######### case 15
command1=$(echo "exit" | ./hsh 2>&1)
command2=$(echo "exit" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""exit" "
######### case 16
command1=$(echo "" | ./hsh 2>&1)
command2=$(echo "" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""empty line" "
######### case 17
command1=$(echo " " | ./hsh 2>&1)
command2=$(echo " " | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check ""spaces line" "
######### case 15
command1=$(echo "./RUNME" | ./hsh 2>&1)
command2=$(echo "./RUNME" | sh 2>&1)
echo "$command1" > 1a2b3c4d5e6f7g8h9i
echo "$command2" > 1a2b3c4d5e6f7g8h9b
run_check "run exe in "./" cwd"
rm ./RUNME
#>>>> betty testing <<<<<<
#remove the hashs below to enable betty testing
echo "-->" Check documentation
betty-doc *.c *.h
echo "-->" Check style
betty-style *.c *.h