GCC Code Coverage Report


Directory: ./
File: tests/functional_test_scripting.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 193 214 90.2%
Functions: 42 42 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** 42sh
4 ** File description:
5 ** The scripting.ini
6 */
7
8 #include "criterion/criterion.h"
9 #include "criterion/redirect.h"
10 #include "../include/myshell.h"
11
12 4 Test(scripting1, full_gcorv)
13 {
14 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
15 2 FILE *file = fopen("test_input.txt", "w");
16
17 2 fprintf(file, "echo \"echo Hello World\" > script\n");
18 2 fprintf(file, "echo \"ls ; pwd\" >> script\n");
19 2 fprintf(file, "./script\n");
20 2 fprintf(file, "exit\n");
21 2 fclose(file);
22 2 freopen("test_input.txt", "r", stdin);
23 2 shell(env);
24 }
25
26 4 Test(scripting2, full_gcorv)
27 {
28 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
29 2 FILE *file = fopen("test_input.txt", "w");
30
31 2 fprintf(file, "if 1 ls\n");
32 2 fprintf(file, "if 1 then\n");
33 2 fprintf(file, " ls\n");
34 2 fprintf(file, "exit\n");
35 2 fclose(file);
36 2 freopen("test_input.txt", "r", stdin);
37 2 shell(env);
38 }
39
40 4 Test(scripting3, full_gcorv)
41 {
42 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
43 2 FILE *file = fopen("test_input.txt", "w");
44
45 2 fprintf(file, "if 1 then\n");
46 2 fprintf(file, " ls\n");
47 2 fprintf(file, "else\n");
48 2 fprintf(file, " pwd\n");
49 2 fprintf(file, "endif\n");
50 2 fprintf(file, "exit\n");
51 2 fclose(file);
52 2 freopen("test_input.txt", "r", stdin);
53 2 shell(env);
54 }
55
56 4 Test(scripting4, full_gcorv)
57 {
58 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
59 2 FILE *file = fopen("test_input.txt", "w");
60
61 2 fprintf(file, "if 0 then\n");
62 2 fprintf(file, " ls\n");
63 2 fprintf(file, "else\n");
64 2 fprintf(file, " pwd\n");
65 2 fprintf(file, "endif\n");
66 2 fprintf(file, "exit\n");
67 2 fclose(file);
68 2 freopen("test_input.txt", "r", stdin);
69 2 shell(env);
70 }
71
72 4 Test(scripting5, full_gcorv)
73 {
74 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
75 2 FILE *file = fopen("test_input.txt", "w");
76
77 2 fprintf(file, "if (0 > 1 || 0 > 2 || 0 < 1) then\n");
78 2 fprintf(file, " ls\n");
79 2 fprintf(file, "exit\n");
80 2 fclose(file);
81 2 freopen("test_input.txt", "r", stdin);
82 2 shell(env);
83 }
84
85 4 Test(scripting6, full_gcorv)
86 {
87 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
88 2 FILE *file = fopen("test_input.txt", "w");
89
90 2 fprintf(file, "if 0 then\n");
91 2 fprintf(file, " ls\n");
92 2 fprintf(file, "exit\n");
93 2 fclose(file);
94 2 freopen("test_input.txt", "r", stdin);
95 2 shell(env);
96 }
97
98 4 Test(scripting7, full_gcorv)
99 {
100 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
101 2 FILE *file = fopen("test_input.txt", "w");
102
103 2 fprintf(file, "else\n");
104 2 fprintf(file, " ls\n");
105 2 fprintf(file, "pwd\n");
106 2 fprintf(file, "exit\n");
107 2 fclose(file);
108 2 freopen("test_input.txt", "r", stdin);
109 2 shell(env);
110 }
111
112 4 Test(scripting8, full_gcorv)
113 {
114 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
115 2 FILE *file = fopen("test_input.txt", "w");
116
117 2 fprintf(file, "if (0) then\n");
118 2 fprintf(file, " echo \"1!\"\n");
119 2 fprintf(file, "else if (((1 > 2) || (2 > 1)) && 1 + 1) then\n");
120 2 fprintf(file, " echo \"2!\"\n");
121 2 fprintf(file, "else\n");
122 2 fprintf(file, " echo \"3!\"\n");
123 2 fprintf(file, "endif\n");
124 2 fprintf(file, "pwd\n");
125 2 fprintf(file, "exit\n");
126 2 fclose(file);
127 2 freopen("test_input.txt", "r", stdin);
128 2 shell(env);
129 }
130
131 4 Test(scripting9, full_gcorv)
132 {
133 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
134 2 FILE *file = fopen("test_input.txt", "w");
135
136 2 fprintf(file, "if (0 > 1) then\n");
137 2 fprintf(file, " ls\n");
138 2 fprintf(file, "exit\n");
139 2 fclose(file);
140 2 freopen("test_input.txt", "r", stdin);
141 2 shell(env);
142 }
143
144 4 Test(scripting10, full_gcorv)
145 {
146 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
147 2 FILE *file = fopen("test_input.txt", "w");
148
149 2 fprintf(file, "else\n");
150 2 fprintf(file, " ls\n");
151 2 fprintf(file, "exit\n");
152 2 fclose(file);
153 2 freopen("test_input.txt", "r", stdin);
154 2 shell(env);
155 }
156
157 4 Test(scripting11, full_gcorv)
158 {
159 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
160 2 FILE *file = fopen("test_input.txt", "w");
161
162 2 fprintf(file, "if\n");
163 2 fprintf(file, "exit\n");
164 2 fclose(file);
165 2 freopen("test_input.txt", "r", stdin);
166 2 shell(env);
167 }
168
169 4 Test(scripting12, full_gcorv)
170 {
171 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
172 2 FILE *file = fopen("test_input.txt", "w");
173
174 2 fprintf(file, "if 1\n");
175 2 fprintf(file, "exit\n");
176 2 fclose(file);
177 2 freopen("test_input.txt", "r", stdin);
178 2 shell(env);
179 }
180
181 4 Test(scripting13, full_gcorv)
182 {
183 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
184 2 FILE *file = fopen("test_input.txt", "w");
185
186 2 fprintf(file, "endif\n");
187 2 fprintf(file, "exit\n");
188 2 fclose(file);
189 2 freopen("test_input.txt", "r", stdin);
190 2 shell(env);
191 }
192
193 4 Test(scripting14, full_gcorv)
194 {
195 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
196 2 FILE *file = fopen("test_input.txt", "w");
197
198 2 fprintf(file, "endif 42sh\n");
199 2 fprintf(file, "exit\n");
200 2 fclose(file);
201 2 freopen("test_input.txt", "r", stdin);
202 2 shell(env);
203 }
204
205 4 Test(scripting15, full_gcorv)
206 {
207 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
208 2 FILE *file = fopen("test_input.txt", "w");
209
210 2 fprintf(file, "if true\n");
211 2 fprintf(file, "exit\n");
212 2 fclose(file);
213 2 freopen("test_input.txt", "r", stdin);
214 2 shell(env);
215 }
216
217 4 Test(scripting16, full_gcorv)
218 {
219 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
220 2 FILE *file = fopen("test_input.txt", "w");
221
222 2 fprintf(file, "foreach f (1 543 5) \\n echo $f \\n end\n");
223 2 fprintf(file, "exit\n");
224 2 fclose(file);
225 2 freopen("test_input.txt", "r", stdin);
226 2 shell(env);
227 }
228
229 4 Test(scripting17, full_gcorv)
230 {
231 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
232 2 FILE *file = fopen("test_input.txt", "w");
233
234 2 fprintf(file, "foreach f (1) \\n if ($f) ls \\n end\n");
235 2 fprintf(file, "exit\n");
236 2 fclose(file);
237 2 freopen("test_input.txt", "r", stdin);
238 2 shell(env);
239 }
240
241 4 Test(scripting18, full_gcorv)
242 {
243 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
244 2 FILE *file = fopen("test_input.txt", "w");
245
246 2 fprintf(file, "foreach f () \\n ls \\n end\n");
247 2 fprintf(file, "exit\n");
248 2 fclose(file);
249 2 freopen("test_input.txt", "r", stdin);
250 2 shell(env);
251 }
252
253 4 Test(scripting19, full_gcorv)
254 {
255 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
256 2 FILE *file = fopen("test_input.txt", "w");
257
258 2 fprintf(file, "foreach\n");
259 2 fprintf(file, "exit\n");
260 2 fclose(file);
261 2 freopen("test_input.txt", "r", stdin);
262 2 shell(env);
263 }
264
265 4 Test(scripting20, full_gcorv)
266 {
267 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
268 2 FILE *file = fopen("test_input.txt", "w");
269
270 2 fprintf(file, "foreach f f ( 1 ) ( 2 ) \\n ls \\n end\n");
271 2 fprintf(file, "exit\n");
272 2 fclose(file);
273 2 freopen("test_input.txt", "r", stdin);
274 2 shell(env);
275 }
276
277 4 Test(scripting21, full_gcorv)
278 {
279 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
280 2 FILE *file = fopen("test_input.txt", "w");
281
282 2 fprintf(file, "foreach (f) ( 2 ) \\n ls \\n end\n");
283 2 fprintf(file, "exit\n");
284 2 fclose(file);
285 2 freopen("test_input.txt", "r", stdin);
286 2 shell(env);
287 }
288