| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | ** EPITECH PROJECT, 2024 | ||
| 3 | ** 42sh | ||
| 4 | ** File description: | ||
| 5 | ** The redirections.ini | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "criterion/criterion.h" | ||
| 9 | #include "criterion/redirect.h" | ||
| 10 | #include "../include/myshell.h" | ||
| 11 | |||
| 12 | 4 | Test(redirections1, 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, "cat -e < Makefile\n"); | |
| 18 | 2 | fprintf(file, "exit\n"); | |
| 19 | 2 | fclose(file); | |
| 20 | 2 | freopen("test_input.txt", "r", stdin); | |
| 21 | 2 | shell(env); | |
| 22 | ✗ | } | |
| 23 | |||
| 24 | 4 | Test(redirections2, full_gcorv) | |
| 25 | { | ||
| 26 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 27 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 28 | |||
| 29 | 2 | fprintf(file, "cat -e << 42sh\n"); | |
| 30 | 2 | fprintf(file, "Welcome\n"); | |
| 31 | 2 | fprintf(file, "to\n"); | |
| 32 | 2 | fprintf(file, "the\n"); | |
| 33 | 2 | fprintf(file, "42sh\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(redirections3, 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, "ls > redirection\n"); | |
| 46 | 2 | fprintf(file, "cat redirection\n"); | |
| 47 | 2 | fprintf(file, "ls > redirection\n"); | |
| 48 | 2 | fprintf(file, "cat redirection\n"); | |
| 49 | 2 | fprintf(file, "rm -rf redirection\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(redirections4, 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, "ls >> redirection\n"); | |
| 62 | 2 | fprintf(file, "cat redirection\n"); | |
| 63 | 2 | fprintf(file, "ls >> redirection\n"); | |
| 64 | 2 | fprintf(file, "cat redirection\n"); | |
| 65 | 2 | fprintf(file, "rm -rf redirection\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(redirections5, 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, "cat -e < Makefile > redirection\n"); | |
| 78 | 2 | fprintf(file, "cat redirection\n"); | |
| 79 | 2 | fprintf(file, "cat < Makefile -e > redirection\n"); | |
| 80 | 2 | fprintf(file, "cat redirection\n"); | |
| 81 | 2 | fprintf(file, "< Makefile cat -e > redirection\n"); | |
| 82 | 2 | fprintf(file, "cat redirection\n"); | |
| 83 | 2 | fprintf(file, "< Makefile cat > redirection -e\n"); | |
| 84 | 2 | fprintf(file, "cat redirection\n"); | |
| 85 | 2 | fprintf(file, "< Makefile > redirection cat -e\n"); | |
| 86 | 2 | fprintf(file, "cat redirection\n"); | |
| 87 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 88 | 2 | fprintf(file, "exit\n"); | |
| 89 | 2 | fclose(file); | |
| 90 | 2 | freopen("test_input.txt", "r", stdin); | |
| 91 | 2 | shell(env); | |
| 92 | ✗ | } | |
| 93 | |||
| 94 | 4 | Test(redirections6, full_gcorv) | |
| 95 | { | ||
| 96 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 97 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 98 | |||
| 99 | 2 | fprintf(file, "cat -e < Makefile >> redirection\n"); | |
| 100 | 2 | fprintf(file, "cat redirection\n"); | |
| 101 | 2 | fprintf(file, "cat < Makefile -e >> redirection\n"); | |
| 102 | 2 | fprintf(file, "cat redirection\n"); | |
| 103 | 2 | fprintf(file, "< Makefile cat -e >> redirection\n"); | |
| 104 | 2 | fprintf(file, "cat redirection\n"); | |
| 105 | 2 | fprintf(file, "< Makefile cat >> redirection -e\n"); | |
| 106 | 2 | fprintf(file, "cat redirection\n"); | |
| 107 | 2 | fprintf(file, "< Makefile >> redirection cat -e\n"); | |
| 108 | 2 | fprintf(file, "cat redirection\n"); | |
| 109 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 110 | 2 | fprintf(file, "exit\n"); | |
| 111 | 2 | fclose(file); | |
| 112 | 2 | freopen("test_input.txt", "r", stdin); | |
| 113 | 2 | shell(env); | |
| 114 | ✗ | } | |
| 115 | |||
| 116 | 4 | Test(redirections7, full_gcorv) | |
| 117 | { | ||
| 118 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 119 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 120 | |||
| 121 | 2 | fprintf(file, "ls > redirection ; ls >> redirection\n"); | |
| 122 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 123 | 2 | fprintf(file, "exit\n"); | |
| 124 | 2 | fclose(file); | |
| 125 | 2 | freopen("test_input.txt", "r", stdin); | |
| 126 | 2 | shell(env); | |
| 127 | ✗ | } | |
| 128 | |||
| 129 | 4 | Test(redirections8, full_gcorv) | |
| 130 | { | ||
| 131 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 132 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 133 | |||
| 134 | 2 | fprintf(file, "< Makefile cat -e|>redirection\n"); | |
| 135 | 2 | fprintf(file, "cat redirection\n"); | |
| 136 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 137 | 2 | fprintf(file, "exit\n"); | |
| 138 | 2 | fclose(file); | |
| 139 | 2 | freopen("test_input.txt", "r", stdin); | |
| 140 | 2 | shell(env); | |
| 141 | ✗ | } | |
| 142 | |||
| 143 | 4 | Test(redirections9, full_gcorv) | |
| 144 | { | ||
| 145 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 146 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 147 | |||
| 148 | 2 | fprintf(file, "cat -e << Makefile < Makefile\n"); | |
| 149 | 2 | fprintf(file, "exit\n"); | |
| 150 | 2 | fclose(file); | |
| 151 | 2 | freopen("test_input.txt", "r", stdin); | |
| 152 | 2 | shell(env); | |
| 153 | ✗ | } | |
| 154 | |||
| 155 | 4 | Test(redirections11, full_gcorv) | |
| 156 | { | ||
| 157 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 158 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 159 | |||
| 160 | 2 | fprintf(file, "cat -e < redirection\n"); | |
| 161 | 2 | fprintf(file, " < redirection\n"); | |
| 162 | 2 | fprintf(file, "exit\n"); | |
| 163 | 2 | fclose(file); | |
| 164 | 2 | freopen("test_input.txt", "r", stdin); | |
| 165 | 2 | shell(env); | |
| 166 | ✗ | } | |
| 167 | |||
| 168 | 4 | Test(redirections12, full_gcorv) | |
| 169 | { | ||
| 170 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 171 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 172 | |||
| 173 | 2 | fprintf(file, "< Makefile\n"); | |
| 174 | 2 | fprintf(file, "exit\n"); | |
| 175 | 2 | fclose(file); | |
| 176 | 2 | freopen("test_input.txt", "r", stdin); | |
| 177 | 2 | shell(env); | |
| 178 | ✗ | } | |
| 179 | |||
| 180 | 4 | Test(redirections13, full_gcorv) | |
| 181 | { | ||
| 182 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 183 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 184 | |||
| 185 | 2 | fprintf(file, "> redirection\n"); | |
| 186 | 2 | fprintf(file, "exit\n"); | |
| 187 | 2 | fclose(file); | |
| 188 | 2 | freopen("test_input.txt", "r", stdin); | |
| 189 | 2 | shell(env); | |
| 190 | ✗ | } | |
| 191 | |||
| 192 | 4 | Test(redirections14, full_gcorv) | |
| 193 | { | ||
| 194 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 195 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 196 | |||
| 197 | 2 | fprintf(file, ">> redirection\n"); | |
| 198 | 2 | fprintf(file, "exit\n"); | |
| 199 | 2 | fclose(file); | |
| 200 | 2 | freopen("test_input.txt", "r", stdin); | |
| 201 | 2 | shell(env); | |
| 202 | ✗ | } | |
| 203 | |||
| 204 | 4 | Test(redirections15, full_gcorv) | |
| 205 | { | ||
| 206 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 207 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 208 | |||
| 209 | 2 | fprintf(file, "42sh > redirection\n"); | |
| 210 | 2 | fprintf(file, "42sh >> redirection\n"); | |
| 211 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 212 | 2 | fprintf(file, "exit\n"); | |
| 213 | 2 | fclose(file); | |
| 214 | 2 | freopen("test_input.txt", "r", stdin); | |
| 215 | 2 | shell(env); | |
| 216 | ✗ | } | |
| 217 | |||
| 218 | 4 | Test(redirections18, full_gcorv) | |
| 219 | { | ||
| 220 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 221 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 222 | |||
| 223 | 2 | fprintf(file, "42sh > redirection\n"); | |
| 224 | 2 | fprintf(file, "42sh >> redirection\n"); | |
| 225 | 2 | fprintf(file, "rm -rf redirection\n"); | |
| 226 | 2 | fprintf(file, "exit\n"); | |
| 227 | 2 | fclose(file); | |
| 228 | 2 | freopen("test_input.txt", "r", stdin); | |
| 229 | 2 | shell(env); | |
| 230 | ✗ | } | |
| 231 | |||
| 232 | 4 | Test(redirections19, full_gcorv) | |
| 233 | { | ||
| 234 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 235 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 236 | |||
| 237 | 2 | fprintf(file, "42sh > .\n"); | |
| 238 | 2 | fprintf(file, "42sh >> .\n"); | |
| 239 | 2 | fprintf(file, "exit\n"); | |
| 240 | 2 | fclose(file); | |
| 241 | 2 | freopen("test_input.txt", "r", stdin); | |
| 242 | 2 | shell(env); | |
| 243 | ✗ | } | |
| 244 | |||
| 245 | 4 | Test(redirections20, full_gcorv) | |
| 246 | { | ||
| 247 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 248 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 249 | |||
| 250 | 2 | fprintf(file, "ls > \n"); | |
| 251 | 2 | fprintf(file, "exit\n"); | |
| 252 | 2 | fclose(file); | |
| 253 | 2 | freopen("test_input.txt", "r", stdin); | |
| 254 | 2 | shell(env); | |
| 255 | ✗ | } | |
| 256 | |||
| 257 | 4 | Test(redirections21, full_gcorv) | |
| 258 | { | ||
| 259 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 260 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 261 | |||
| 262 | 2 | fprintf(file, "ls >> \n"); | |
| 263 | 2 | fprintf(file, "exit\n"); | |
| 264 | 2 | fclose(file); | |
| 265 | 2 | freopen("test_input.txt", "r", stdin); | |
| 266 | 2 | shell(env); | |
| 267 | ✗ | } | |
| 268 | |||
| 269 | 4 | Test(redirections22, full_gcorv) | |
| 270 | { | ||
| 271 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 272 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 273 | |||
| 274 | 2 | fprintf(file, "ls > >\n"); | |
| 275 | 2 | fprintf(file, "exit\n"); | |
| 276 | 2 | fclose(file); | |
| 277 | 2 | freopen("test_input.txt", "r", stdin); | |
| 278 | 2 | shell(env); | |
| 279 | ✗ | } | |
| 280 | |||
| 281 | 4 | Test(redirections23, full_gcorv) | |
| 282 | { | ||
| 283 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 284 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 285 | |||
| 286 | 2 | fprintf(file, "ls > >>\n"); | |
| 287 | 2 | fprintf(file, "exit\n"); | |
| 288 | 2 | fclose(file); | |
| 289 | 2 | freopen("test_input.txt", "r", stdin); | |
| 290 | 2 | shell(env); | |
| 291 | ✗ | } | |
| 292 | |||
| 293 | 4 | Test(redirections24, full_gcorv) | |
| 294 | { | ||
| 295 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 296 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 297 | |||
| 298 | 2 | fprintf(file, "ls >> >\n"); | |
| 299 | 2 | fprintf(file, "exit\n"); | |
| 300 | 2 | fclose(file); | |
| 301 | 2 | freopen("test_input.txt", "r", stdin); | |
| 302 | 2 | shell(env); | |
| 303 | ✗ | } | |
| 304 | |||
| 305 | 4 | Test(redirections25, full_gcorv) | |
| 306 | { | ||
| 307 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 308 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 309 | |||
| 310 | 2 | fprintf(file, "ls >> >>\n"); | |
| 311 | 2 | fprintf(file, "exit\n"); | |
| 312 | 2 | fclose(file); | |
| 313 | 2 | freopen("test_input.txt", "r", stdin); | |
| 314 | 2 | shell(env); | |
| 315 | ✗ | } | |
| 316 | |||
| 317 | 4 | Test(redirections26, full_gcorv) | |
| 318 | { | ||
| 319 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 320 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 321 | |||
| 322 | 2 | fprintf(file, "ls > > >\n"); | |
| 323 | 2 | fprintf(file, "exit\n"); | |
| 324 | 2 | fclose(file); | |
| 325 | 2 | freopen("test_input.txt", "r", stdin); | |
| 326 | 2 | shell(env); | |
| 327 | ✗ | } | |
| 328 | |||
| 329 | 4 | Test(redirections27, full_gcorv) | |
| 330 | { | ||
| 331 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 332 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 333 | |||
| 334 | 2 | fprintf(file, "ls > redirection >\n"); | |
| 335 | 2 | fprintf(file, "exit\n"); | |
| 336 | 2 | fclose(file); | |
| 337 | 2 | freopen("test_input.txt", "r", stdin); | |
| 338 | 2 | shell(env); | |
| 339 | ✗ | } | |
| 340 | |||
| 341 | 4 | Test(redirections28, full_gcorv) | |
| 342 | { | ||
| 343 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 344 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 345 | |||
| 346 | 2 | fprintf(file, "ls > redirection >> redirection > \n"); | |
| 347 | 2 | fprintf(file, "exit\n"); | |
| 348 | 2 | fclose(file); | |
| 349 | 2 | freopen("test_input.txt", "r", stdin); | |
| 350 | 2 | shell(env); | |
| 351 | ✗ | } | |
| 352 | |||
| 353 | 4 | Test(redirections29, full_gcorv) | |
| 354 | { | ||
| 355 | 2 | char **env = my_str_to_word_array_select("TERM=xterm ; PATH=/bin:/usr/bin", " ;"); | |
| 356 | 2 | FILE *file = fopen("test_input.txt", "w"); | |
| 357 | |||
| 358 | 2 | fprintf(file, "ls > redirection >> >> redirection\n"); | |
| 359 | 2 | fprintf(file, "exit\n"); | |
| 360 | 2 | fclose(file); | |
| 361 | 2 | freopen("test_input.txt", "r", stdin); | |
| 362 | 2 | shell(env); | |
| 363 | ✗ | } | |
| 364 |