Skip to content

Commit 7f196eb

Browse files
Seluj78Quentin Perez
andcommitted
[FEATURE] Added Maintest to the libft testing suite. This fixes #50 and contributes to #54
Co-Authored-By: Quentin Perez <qperez@staff.42.fr>
1 parent c068ad9 commit 7f196eb

6 files changed

Lines changed: 75 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,6 @@ ENV/
100100
# mypy
101101
.mypy_cache/
102102
.idea/
103-
.my*
103+
.my*
104+
libft_main.c
105+
libft_main.out

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "moulitest"]
55
path = moulitest
66
url = https://github.com/yyang42/moulitest
7+
[submodule "Maintest"]
8+
path = Maintest
9+
url = https://github.com/QuentinPerez/Maintest

42PyChecker.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import glob
44
import subprocess
55
import re
6-
6+
import shutil
77

88
def check_author_file(project_path: str):
99
"""
@@ -323,6 +323,46 @@ def run_moulitest(project_path: str, has_libft_bonuses: bool, project: str):
323323
return 0
324324

325325

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+
326366
def check_libft(project_path: str):
327367
required_functions = ['libft.h', 'ft_strcat.c', 'ft_strncat.c',
328368
'ft_strlcat.c', 'ft_strchr.c', 'ft_strnstr.c',
@@ -373,7 +413,7 @@ def check_libft(project_path: str):
373413
run_libftest(project_path)
374414
run_moulitest(project_path, has_libft_bonuses, "libft")
375415
# @todo add libft-unit-test to the testing suite
376-
# @todo add maintest
416+
run_maintest(project_path)
377417
return 0
378418

379-
sys.exit(run_moulitest("/tmp/libft", False, "libft"))
419+
sys.exit(run_maintest("/tmp/libft"))

Maintest

Submodule Maintest added at 999b91d

check_static.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#@IgnoreInspection BashAddShebang
2+
13
TOTAL=$(find "$1" -type f -name "*.c")
24
OLDIFS=${IFS}
35
IFS=$'\n'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
RMVFUNCTIONS=$1
4+
5+
awk -v RMVFUNCTIONS="^[\t]?(#define)[\t ]*(${RMVFUNCTIONS})" '
6+
BEGIN {
7+
RMV=0
8+
}
9+
$0 ~ RMVFUNCTIONS {
10+
RMV=1
11+
}
12+
{
13+
if (RMV == 0) {
14+
print $0
15+
} else {
16+
printf "//%s\n", $0;
17+
RMV++;
18+
if (RMV == 3) {
19+
RMV=0
20+
}
21+
}
22+
}
23+
' "Maintest/libft/main.c" 1>"libft_main.c" 2>".mymaintest"

0 commit comments

Comments
 (0)