Skip to content

Commit c068ad9

Browse files
committed
[FEATURE] Added the moulitest testing suite for the libft.
1 parent bd52341 commit c068ad9

3 files changed

Lines changed: 63 additions & 5 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "libftest"]
22
path = libftest
33
url = https://github.com/jtoty/libftest
4+
[submodule "moulitest"]
5+
path = moulitest
6+
url = https://github.com/yyang42/moulitest

42PyChecker.py

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,59 @@ def run_libftest(project_path: str):
270270
return 0
271271

272272

273+
def moulitest_include_libft_bonuses():
274+
"""
275+
This method removes the `.exclude` extention to the libft bonuses files.
276+
"""
277+
moulitest_libft_tests_path = "moulitest/libft_tests/tests"
278+
files = os.listdir(moulitest_libft_tests_path)
279+
for file in files:
280+
if file[:2] == "02":
281+
if file.endswith(".exclude"):
282+
os.rename(os.path.join(moulitest_libft_tests_path, file), os.path.join(moulitest_libft_tests_path, file[:-8]))
283+
284+
285+
def moulitest_exclude_libft_bonuses():
286+
"""
287+
This method Adds the `.exclude` extention to the libft bonuses files.
288+
"""
289+
moulitest_libft_tests_path = "moulitest/libft_tests/tests"
290+
files = os.listdir(moulitest_libft_tests_path)
291+
for file in files:
292+
if file[:2] == "02":
293+
os.rename(os.path.join(moulitest_libft_tests_path, file), os.path.join(moulitest_libft_tests_path, file + '.exclude'))
294+
295+
296+
def exec_moulitest(test_name: str):
297+
# @todo add a protection if test_name isn't compatible with the current project and if not in list of available test for moulitest
298+
with open(os.path.dirname(os.path.realpath(__file__)) + "/.mymoulitest", 'w+') as file:
299+
file.write("*------------------------------------------------------*\n")
300+
file.write("MOULITEST\n")
301+
file.write("Warning: This file contains escape sequences. Please use `cat' to view it properly.\n")
302+
file.write("*------------------------------------------------------*\n")
303+
# @todo Get the result line of moulitest and parse it.
304+
result = subprocess.run('make ' + test_name + ' -C ' + 'moulitest' + ' 2>&1', shell=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
305+
file.write(result + '\n')
306+
307+
308+
def run_moulitest(project_path: str, has_libft_bonuses: bool, project: str):
309+
available_projects = ['ft_ls', 'ft_printf', 'gnl', 'libft', 'libftasm']
310+
if project not in available_projects:
311+
raise ValueError("given project not in moulitest available projects.")
312+
if project == "libft":
313+
with open("moulitest/config.ini", 'w+') as file:
314+
file.write("LIBFT_PATH = " + project_path)
315+
moulitest_include_libft_bonuses()
316+
# @todo Fix moulitest makefile (it starts the bonus even when not asked.)
317+
if not has_libft_bonuses:
318+
moulitest_exclude_libft_bonuses()
319+
exec_moulitest("libft_bonus")
320+
moulitest_include_libft_bonuses()
321+
else:
322+
exec_moulitest("libft_bonus")
323+
return 0
324+
325+
273326
def check_libft(project_path: str):
274327
required_functions = ['libft.h', 'ft_strcat.c', 'ft_strncat.c',
275328
'ft_strlcat.c', 'ft_strchr.c', 'ft_strnstr.c',
@@ -292,6 +345,7 @@ def check_libft(project_path: str):
292345
bonus_functions = ['ft_lstnew.c', 'ft_lstdelone.c', 'ft_lstdel.c',
293346
'ft_lstiter.c', 'ft_lstadd.c', 'ft_lstmap.c']
294347
authorized_functions = ['free', 'malloc', 'write', 'main']
348+
has_libft_bonuses = True
295349
while True:
296350
if all([os.path.isfile(project_path + '/' + function) for function in required_functions]):
297351
break
@@ -302,6 +356,7 @@ def check_libft(project_path: str):
302356
if all([os.path.isfile(project_path + '/' + function) for function in bonus_functions]):
303357
break
304358
else:
359+
has_libft_bonuses = False
305360
print("Warning: not all bonus files are here")
306361
break
307362
file_list = []
@@ -316,10 +371,9 @@ def check_libft(project_path: str):
316371
check_makefile(project_path, "libft.a")
317372
check_forbidden_functions(project_path, "libft.a", authorized_functions)
318373
run_libftest(project_path)
319-
# moulitest
320-
# libft-unit-test
321-
# maintest
374+
run_moulitest(project_path, has_libft_bonuses, "libft")
375+
# @todo add libft-unit-test to the testing suite
376+
# @todo add maintest
322377
return 0
323378

324-
325-
sys.exit(check_libft("/tmp/libft"))
379+
sys.exit(run_moulitest("/tmp/libft", False, "libft"))

moulitest

Submodule moulitest added at 205892c

0 commit comments

Comments
 (0)