GCC Code Coverage Report


Directory: ./
File: tests/functional_test_variables.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 259 345 75.1%
Functions: 62 68 91.2%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** 42sh
4 ** File description:
5 ** The variables.ini
6 */
7
8 #include "criterion/criterion.h"
9 #include "criterion/redirect.h"
10 #include "../include/myshell.h"
11
12 4 Test(variables1, 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, "set TEST1 = ls\n");
18 2 fprintf(file, "set TEST2 = include\n");
19 2 fprintf(file, "$TEST1 ./$TEST2\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(variables2, 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, "set TEST1=42sh; set TEST2=mysh; set | grep TEST; unset TEST1; set | grep TEST\n");
32 2 fprintf(file, "set TEST3=42sh; set | grep TEST; set TEST3=mysh; set | grep TEST\n");
33 2 fprintf(file, "set TEST4=42sh; set TEST5=mysh; set TEST4=mysh; set | grep TEST; unset TEST32\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(variables3, 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, "echo $HOME\n");
46 2 fprintf(file, "exit\n");
47 2 fclose(file);
48 2 freopen("test_input.txt", "r", stdin);
49 2 shell(env);
50 }
51
52 4 Test(variables4, full_gcorv)
53 {
54 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
55 2 FILE *file = fopen("test_input.txt", "w");
56
57 2 fprintf(file, "ls \"$HOME\"\n");
58 2 fprintf(file, "exit\n");
59 2 fclose(file);
60 2 freopen("test_input.txt", "r", stdin);
61 2 shell(env);
62 }
63
64 4 Test(variables5, full_gcorv)
65 {
66 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
67 2 FILE *file = fopen("test_input.txt", "w");
68
69 2 fprintf(file, "set test = my\n");
70 2 fprintf(file, "ls ${HOME}\n");
71 2 fprintf(file, "${test}sh\n");
72 2 fprintf(file, "exit\n");
73 2 fclose(file);
74 2 freopen("test_input.txt", "r", stdin);
75 2 shell(env);
76 }
77
78 4 Test(variables6, full_gcorv)
79 {
80 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
81 2 FILE *file = fopen("test_input.txt", "w");
82
83 2 fprintf(file, "ls $ $\n");
84 2 fprintf(file, "echo $\n");
85 2 fprintf(file, "exit\n");
86 2 fclose(file);
87 2 freopen("test_input.txt", "r", stdin);
88 2 shell(env);
89 }
90
91 4 Test(variables7, full_gcorv)
92 {
93 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
94 2 FILE *file = fopen("test_input.txt", "w");
95
96 2 fprintf(file, "${test}\n");
97 2 fprintf(file, "exit\n");
98 2 fclose(file);
99 2 freopen("test_input.txt", "r", stdin);
100 2 shell(env);
101 }
102
103 4 Test(variables8, full_gcorv)
104 {
105 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
106 2 FILE *file = fopen("test_input.txt", "w");
107
108 2 fprintf(file, "$test}\n");
109 2 fprintf(file, "exit\n");
110 2 fclose(file);
111 2 freopen("test_input.txt", "r", stdin);
112 2 shell(env);
113 }
114
115 4 Test(variables9, full_gcorv)
116 {
117 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
118 2 FILE *file = fopen("test_input.txt", "w");
119
120 2 fprintf(file, "${{test}}\n");
121 2 fprintf(file, "exit\n");
122 2 fclose(file);
123 2 freopen("test_input.txt", "r", stdin);
124 2 shell(env);
125 }
126
127 4 Test(variables10, full_gcorv)
128 {
129 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
130 2 FILE *file = fopen("test_input.txt", "w");
131
132 2 fprintf(file, "${ test }\n");
133 2 fprintf(file, "exit\n");
134 2 fclose(file);
135 2 freopen("test_input.txt", "r", stdin);
136 2 shell(env);
137 }
138
139 4 Test(variables11, full_gcorv)
140 {
141 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
142 2 FILE *file = fopen("test_input.txt", "w");
143
144 2 fprintf(file, "${ \n");
145 2 fprintf(file, "exit\n");
146 2 fclose(file);
147 2 freopen("test_input.txt", "r", stdin);
148 2 shell(env);
149 }
150
151 4 Test(variables12, full_gcorv)
152 {
153 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
154 2 FILE *file = fopen("test_input.txt", "w");
155
156 2 fprintf(file, "${ }\n");
157 2 fprintf(file, "exit\n");
158 2 fclose(file);
159 2 freopen("test_input.txt", "r", stdin);
160 2 shell(env);
161 }
162
163 4 Test(variables13, full_gcorv)
164 {
165 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
166 2 FILE *file = fopen("test_input.txt", "w");
167
168 2 fprintf(file, "${}\n");
169 2 fprintf(file, "exit\n");
170 2 fclose(file);
171 2 freopen("test_input.txt", "r", stdin);
172 2 shell(env);
173 }
174
175 4 Test(variables14, full_gcorv)
176 {
177 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
178 2 FILE *file = fopen("test_input.txt", "w");
179
180 2 fprintf(file, "$}\n");
181 2 fprintf(file, "exit\n");
182 2 fclose(file);
183 2 freopen("test_input.txt", "r", stdin);
184 2 shell(env);
185 }
186
187 4 Test(variables15, full_gcorv)
188 {
189 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
190 2 FILE *file = fopen("test_input.txt", "w");
191
192 2 fprintf(file, "${test\n");
193 2 fprintf(file, "exit\n");
194 2 fclose(file);
195 2 freopen("test_input.txt", "r", stdin);
196 2 shell(env);
197 }
198
199 4 Test(variables16, full_gcorv)
200 {
201 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
202 2 FILE *file = fopen("test_input.txt", "w");
203
204 2 fprintf(file, "${test }\n");
205 2 fprintf(file, "exit\n");
206 2 fclose(file);
207 2 freopen("test_input.txt", "r", stdin);
208 2 shell(env);
209 }
210
211 4 Test(variables17, full_gcorv)
212 {
213 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
214 2 FILE *file = fopen("test_input.txt", "w");
215
216 2 fprintf(file, "${\n");
217 2 fprintf(file, "exit\n");
218 2 fclose(file);
219 2 freopen("test_input.txt", "r", stdin);
220 2 shell(env);
221 }
222
223 4 Test(variables18, full_gcorv)
224 {
225 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
226 2 FILE *file = fopen("test_input.txt", "w");
227
228 2 fprintf(file, "echo $?\n");
229 2 fprintf(file, "42sh\n");
230 2 fprintf(file, "echo $?\n");
231 2 fprintf(file, "exit\n");
232 2 fclose(file);
233 2 freopen("test_input.txt", "r", stdin);
234 2 shell(env);
235 }
236
237 4 Test(variables19, full_gcorv)
238 {
239 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
240 2 FILE *file = fopen("test_input.txt", "w");
241
242 2 fprintf(file, "set | grep -\n");
243 2 fprintf(file, "ls\n");
244 2 fprintf(file, "set | grep -\n");
245 2 fprintf(file, "exit\n");
246 2 fclose(file);
247 2 freopen("test_input.txt", "r", stdin);
248 2 shell(env);
249 }
250
251 4 Test(variables20, full_gcorv)
252 {
253 2 char **env = my_str_to_word_array_select("", " ;");
254 2 FILE *file = fopen("test_input.txt", "w");
255
256 2 fprintf(file, "set | grep -\n");
257 2 fprintf(file, "ls\n");
258 2 fprintf(file, "set | grep -\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(variables21, 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, "set | grep cwd\n");
271 2 fprintf(file, "cd ..\n");
272 2 fprintf(file, "set | grep cwd\n");
273 2 fprintf(file, "exit\n");
274 2 fclose(file);
275 2 freopen("test_input.txt", "r", stdin);
276 2 shell(env);
277 }
278
279 Test(variables22, full_gcorv)
280 {
281 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
282 FILE *file = fopen("test_input.txt", "w");
283
284 fprintf(file, "set | grep owd\n");
285 fprintf(file, "cd ..\n");
286 fprintf(file, "set | grep owd\n");
287 fprintf(file, "cd -\n");
288 fprintf(file, "set | grep owd\n");
289 fprintf(file, "exit\n");
290 fclose(file);
291 freopen("test_input.txt", "r", stdin);
292 shell(env);
293 }
294
295 Test(variables23, full_gcorv)
296 {
297 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
298 FILE *file = fopen("test_input.txt", "w");
299
300 fprintf(file, "env | grep path\n");
301 fprintf(file, "set | grep path\n");
302 fprintf(file, "ls\n");
303 fprintf(file, "setenv PATH test\n");
304 fprintf(file, "set | grep path\n");
305 fprintf(file, "ls\n");
306 fprintf(file, "setenv PATH /bin:/usr/bin\n");
307 fprintf(file, "set | grep path\n");
308 fprintf(file, "unsetenv PATH\n");
309 fprintf(file, "set | grep path\n");
310 fprintf(file, "ls\n");
311 fprintf(file, "unset path\n");
312 fprintf(file, "ls\n");
313 fprintf(file, "exit\n");
314 fclose(file);
315 freopen("test_input.txt", "r", stdin);
316 shell(env);
317 }
318
319 Test(variables24, full_gcorv)
320 {
321 char **env = my_str_to_word_array_select("", " ;");
322 FILE *file = fopen("test_input.txt", "w");
323
324 fprintf(file, "env | grep PATH\n");
325 fprintf(file, "set | grep path\n");
326 fprintf(file, "ls\n");
327 fprintf(file, "setenv PATH test\n");
328 fprintf(file, "set | grep path\n");
329 fprintf(file, "ls\n");
330 fprintf(file, "setenv PATH /bin:/usr/bin\n");
331 fprintf(file, "set | grep path\n");
332 fprintf(file, "unsetenv PATH\n");
333 fprintf(file, "set | grep path\n");
334 fprintf(file, "ls\n");
335 fprintf(file, "unset path\n");
336 fprintf(file, "ls\n");
337 fprintf(file, "exit\n");
338 fclose(file);
339 freopen("test_input.txt", "r", stdin);
340 shell(env);
341 }
342
343 4 Test(variables25, full_gcorv)
344 {
345 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
346 2 FILE *file = fopen("test_input.txt", "w");
347
348 2 fprintf(file, "exit\n");
349 2 fclose(file);
350 2 freopen("test_input.txt", "r", stdin);
351 2 shell(env);
352 }
353
354 4 Test(variables26, full_gcorv)
355 {
356 2 char **env = my_str_to_word_array_select("", " ;");
357 2 FILE *file = fopen("test_input.txt", "w");
358
359 2 fprintf(file, "exit\n");
360 2 fclose(file);
361 2 freopen("test_input.txt", "r", stdin);
362 2 shell(env);
363 }
364
365 4 Test(variables27, full_gcorv)
366 {
367 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
368 2 FILE *file = fopen("test_input.txt", "w");
369
370 2 fprintf(file, "set | grep shell > /dev/null\n");
371 2 fprintf(file, "exit\n");
372 2 fclose(file);
373 2 freopen("test_input.txt", "r", stdin);
374 2 shell(env);
375 }
376
377 4 Test(variables28, full_gcorv)
378 {
379 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
380 2 FILE *file = fopen("test_input.txt", "w");
381
382 2 fprintf(file, "set | grep user\n");
383 2 fprintf(file, "exit\n");
384 2 fclose(file);
385 2 freopen("test_input.txt", "r", stdin);
386 2 shell(env);
387 }
388
389 4 Test(variables29, full_gcorv)
390 {
391 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
392 2 FILE *file = fopen("test_input.txt", "w");
393
394 2 fprintf(file, "set | grep uid\n");
395 2 fprintf(file, "exit\n");
396 2 fclose(file);
397 2 freopen("test_input.txt", "r", stdin);
398 2 shell(env);
399 }
400
401 4 Test(variables30, full_gcorv)
402 {
403 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
404 2 FILE *file = fopen("test_input.txt", "w");
405
406 2 fprintf(file, "set | grep ignoreof\n");
407 2 fprintf(file, "set ignoreeof\n");
408 2 fprintf(file, "set | grep ignoreof\n");
409 2 fprintf(file, "exit\n");
410 2 fclose(file);
411 2 freopen("test_input.txt", "r", stdin);
412 2 shell(env);
413 }
414
415 4 Test(variables31, full_gcorv)
416 {
417 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
418 2 FILE *file = fopen("test_input.txt", "w");
419
420 2 fprintf(file, "exit\n");
421 2 fclose(file);
422 2 freopen("test_input.txt", "r", stdin);
423 2 shell(env);
424 }
425
426 4 Test(variables32, full_gcorv)
427 {
428 2 char **env = my_str_to_word_array_select("", " ;");
429 2 FILE *file = fopen("test_input.txt", "w");
430
431 2 fprintf(file, "exit\n");
432 2 fclose(file);
433 2 freopen("test_input.txt", "r", stdin);
434 2 shell(env);
435 }
436
437 4 Test(variables33, full_gcorv)
438 {
439 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
440 2 FILE *file = fopen("test_input.txt", "w");
441
442 2 fprintf(file, "exit\n");
443 2 fclose(file);
444 2 freopen("test_input.txt", "r", stdin);
445 2 shell(env);
446 }
447
448 4 Test(variables34, full_gcorv)
449 {
450 2 char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;");
451 2 FILE *file = fopen("test_input.txt", "w");
452
453 2 fprintf(file, "exit\n");
454 2 fclose(file);
455 2 freopen("test_input.txt", "r", stdin);
456 2 shell(env);
457 }
458