|
3 | 3 | import glob |
4 | 4 | import subprocess |
5 | 5 | import re |
6 | | - |
| 6 | +import shutil |
7 | 7 |
|
8 | 8 | def check_author_file(project_path: str): |
9 | 9 | """ |
@@ -323,6 +323,46 @@ def run_moulitest(project_path: str, has_libft_bonuses: bool, project: str): |
323 | 323 | return 0 |
324 | 324 |
|
325 | 325 |
|
| 326 | +def run_maintest(project_path: str): |
| 327 | + maintest_functions = ['memset', 'bzero', 'memcpy', 'memccpy', 'memmove', |
| 328 | + 'memchr', 'memcmp', 'strlen', 'strdup', 'strcpy', |
| 329 | + 'strncpy', 'strcat', 'strncat', 'strlcat', 'strchr', |
| 330 | + 'strrchr', 'strstr', 'strnstr', 'strcmp', 'strncmp', |
| 331 | + 'atoi', 'isalpha', 'isdigit', 'isalnum', 'isascii', |
| 332 | + 'isprint', 'toupper', 'tolower', 'strnew', 'strdel', |
| 333 | + 'strclr', 'striter', 'striteri', 'strmap', 'strmapi', |
| 334 | + 'strequ', 'strnequ', 'strsub', 'strjoin', 'strsplit', |
| 335 | + 'itoa', 'strtrim', 'lstnew', 'lstdelone', 'lstdel', |
| 336 | + 'lstadd', 'lstiter', 'lstmap'] |
| 337 | + missing_functions = [] |
| 338 | + for file in maintest_functions: |
| 339 | + # @todo Add a check to handle libft where file aren't at libft/ but can be in libft/src |
| 340 | + if not os.path.exists(project_path + '/ft_' + file + '.c'): |
| 341 | + missing_functions.append(file) |
| 342 | + # @todo: special case for memalloc and memdel |
| 343 | + missing = "" |
| 344 | + for function in missing_functions: |
| 345 | + missing = missing + '|D_' + function.upper() |
| 346 | + missing = missing[1:] |
| 347 | + # Has to be done, or else the last one is ignored. To be fixed ! |
| 348 | + missing = missing + "|D_NOTHING" |
| 349 | + if missing == "": |
| 350 | + shutil.copy("Maintest/libft/main.c", "libft_main.c") |
| 351 | + else: |
| 352 | + # @todo: Silence error from script maintest. |
| 353 | + subprocess.run(['sh', 'remove_missing_functions_maintest.sh', missing]) |
| 354 | + with open(os.path.dirname(os.path.realpath(__file__)) + "/.mymaintest", 'w+') as file: |
| 355 | + file.write("*------------------------------------------------------*\n") |
| 356 | + file.write("MAINTEST\n") |
| 357 | + file.write("Warning: This file contains escape sequences. Please use `cat' to view it properly.\n") |
| 358 | + file.write("*------------------------------------------------------*\n") |
| 359 | + result = subprocess.run(['gcc', 'libft_main.c', '-L' + project_path, '-I' + project_path, "-I" + project_path + "/include", "-I" + project_path + "/includes", "-lft", "-o", "libft_main.out"], stdout=subprocess.PIPE).stdout.decode('utf-8') |
| 360 | + file.write(result + '\n') |
| 361 | + result = subprocess.run(['./libft_main.out'], stdout=subprocess.PIPE).stdout.decode('utf-8') |
| 362 | + # @todo: Count number of OK and FAILs and yellow tests to get score for maintest |
| 363 | + file.write(result + '\n') |
| 364 | + |
| 365 | + |
326 | 366 | def check_libft(project_path: str): |
327 | 367 | required_functions = ['libft.h', 'ft_strcat.c', 'ft_strncat.c', |
328 | 368 | 'ft_strlcat.c', 'ft_strchr.c', 'ft_strnstr.c', |
@@ -373,7 +413,7 @@ def check_libft(project_path: str): |
373 | 413 | run_libftest(project_path) |
374 | 414 | run_moulitest(project_path, has_libft_bonuses, "libft") |
375 | 415 | # @todo add libft-unit-test to the testing suite |
376 | | - # @todo add maintest |
| 416 | + run_maintest(project_path) |
377 | 417 | return 0 |
378 | 418 |
|
379 | | -sys.exit(run_moulitest("/tmp/libft", False, "libft")) |
| 419 | +sys.exit(run_maintest("/tmp/libft")) |
0 commit comments