Skip to content

Commit 51ee5f8

Browse files
committed
[CHORE] Moved code in separate folders for ease of use.
LICENSE Updated to GNU (Not Apache anymore.) contributes to #54 Signed-off-by: Jules Lasne (seluj78) <jlasne@student.42.fr>
1 parent 277e789 commit 51ee5f8

21 files changed

Lines changed: 1272 additions & 639 deletions

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[submodule "libftest"]
2-
path = libftest
2+
path = testing_suites/libftest
33
url = https://github.com/jtoty/libftest
44
[submodule "Maintest"]
5-
path = Maintest
5+
path = testing_suites/Maintest
66
url = https://github.com/QuentinPerez/Maintest
77
[submodule "moulitest"]
8-
path = moulitest
8+
path = testing_suites/moulitest
99
url = https://github.com/yyang42/moulitest

42PyChecker.py

Lines changed: 7 additions & 431 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 675 additions & 201 deletions
Large diffs are not rendered by default.

Maintest

Lines changed: 0 additions & 1 deletion
This file was deleted.

PyChecker/Tests/__init__.py

Whitespace-only changes.

PyChecker/Tests/libftest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import os
7+
import subprocess
8+
9+
10+
def run(project_path: str, root_path: str):
11+
"""
12+
This function runs the libftest to the given project.
13+
14+
:param project_path: The path of the project you want to test.
15+
"""
16+
try:
17+
open("testing_suites/libftest/my_config.sh", 'r')
18+
except FileNotFoundError:
19+
subprocess.run(['bash', "testing_suites/libftest/grademe.sh"])
20+
with open('testing_suites/libftest/my_config.sh', 'r') as file:
21+
filedata = file.read()
22+
filedata = filedata.replace('PATH_LIBFT=~/libft', "PATH_LIBFT=" + project_path)
23+
filedata = filedata.replace('PATH_DEEPTHOUGHT=${PATH_TEST}',
24+
"PATH_DEEPTHOUGHT=" + root_path)
25+
with open('testing_suites/libftest/my_config.sh', 'w') as file:
26+
file.write(filedata)
27+
# @todo Parse libftest output for UI and parse score for display and return values.
28+
result = subprocess.run(['bash', "testing_suites/libftest/grademe.sh",
29+
"-l -s -f -n -u"], stdout=subprocess.PIPE,
30+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
31+
os.rename("deepthought", ".mylibftest")
32+
with open(root_path + "/.mylibftest", 'a') as file:
33+
file.write("*------------------------------------------------------*\n")
34+
file.write("LIBFTEST\n")
35+
file.write("Warning: This file contains escape sequences. Please use "
36+
"`cat' to view it properly.\n")
37+
file.write("*------------------------------------------------------*\n")
38+
file.write(result)
39+
return 0

PyChecker/Tests/maintest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import os
7+
import subprocess
8+
import shutil
9+
10+
11+
def run_libft(project_path: str, root_path: str):
12+
"""
13+
This function will run the `maintest` to the given project.
14+
15+
:param project_path: The path of the project you want to test.
16+
"""
17+
# These are the functions that the maintest tests for the libft.
18+
maintest_functions = ['memset', 'bzero', 'memcpy', 'memccpy', 'memmove',
19+
'memchr', 'memcmp', 'strlen', 'strdup', 'strcpy',
20+
'strncpy', 'strcat', 'strncat', 'strlcat', 'strchr',
21+
'strrchr', 'strstr', 'strnstr', 'strcmp', 'strncmp',
22+
'atoi', 'isalpha', 'isdigit', 'isalnum', 'isascii',
23+
'isprint', 'toupper', 'tolower', 'strnew', 'strdel',
24+
'strclr', 'striter', 'striteri', 'strmap', 'strmapi',
25+
'strequ', 'strnequ', 'strsub', 'strjoin', 'strsplit',
26+
'itoa', 'strtrim', 'lstnew', 'lstdelone', 'lstdel',
27+
'lstadd', 'lstiter', 'lstmap']
28+
missing_functions = []
29+
for file in maintest_functions:
30+
# @todo Add a check to handle libft where file aren't at libft/ but can be in libft/src
31+
if not os.path.exists(project_path + '/ft_' + file + '.c'):
32+
missing_functions.append(file)
33+
# @todo: special case for memalloc and memdel
34+
missing = ""
35+
for function in missing_functions:
36+
missing = missing + '|D_' + function.upper()
37+
missing = missing[1:]
38+
# Has to be done, or else the last one is ignored. To be fixed !
39+
missing = missing + "|D_NOTHING"
40+
if missing == "":
41+
shutil.copy("testing_suites/Maintest/libft/main.c", "libft_main.c")
42+
else:
43+
# @todo: Silence error from script maintest.
44+
subprocess.run(['sh', 'scripts/remove_missing_functions_maintest.sh', missing])
45+
with open(root_path + "/.mymaintest", 'w+') as file:
46+
file.write("*------------------------------------------------------*\n")
47+
file.write("MAINTEST\n")
48+
file.write("Warning: This file contains escape sequences. Please use "
49+
"`cat' to view it properly.\n")
50+
file.write("*------------------------------------------------------*\n")
51+
result = subprocess.run(['gcc', 'libft_main.c', '-L' + project_path,
52+
'-I' + project_path, "-I" + project_path +
53+
"/include", "-I" + project_path + "/includes",
54+
"-lft", "-o", "libft_main.out"],
55+
stdout=subprocess.PIPE,
56+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
57+
file.write(result + '\n')
58+
result = subprocess.run(['./libft_main.out'], stdout=subprocess.PIPE,
59+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
60+
# @todo: Count number of OK and FAILs and yellow tests to get score for maintest
61+
file.write(result + '\n')
62+
os.remove("libft_main.c")
63+
os.remove("libft_main.out")

PyChecker/Tests/moulitest.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import os
7+
import subprocess
8+
9+
def include_libft_bonuses():
10+
"""
11+
This method removes the `.exclude` extention to the libft bonuses files.
12+
"""
13+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/tests"
14+
files = os.listdir(moulitest_libft_tests_path)
15+
for file in files:
16+
if file[:2] == "02":
17+
if file.endswith(".exclude"):
18+
os.rename(os.path.join(moulitest_libft_tests_path, file),
19+
os.path.join(moulitest_libft_tests_path, file[:-8]))
20+
21+
22+
def exclude_libft_bonuses():
23+
"""
24+
This method Adds the `.exclude` extention to the libft bonuses files.
25+
"""
26+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/tests"
27+
files = os.listdir(moulitest_libft_tests_path)
28+
for file in files:
29+
if file[:2] == "02":
30+
os.rename(os.path.join(moulitest_libft_tests_path, file),
31+
os.path.join(moulitest_libft_tests_path, file + '.exclude'))
32+
33+
34+
def execute_test(test_name: str, root_path: str):
35+
# @todo add a protection if test_name isn't compatible with the current project and if not in list of available test for moulitest
36+
with open(root_path + "/.mymoulitest", 'w+') as file:
37+
file.write("*------------------------------------------------------*\n")
38+
file.write("MOULITEST\n")
39+
file.write("Warning: This file contains escape sequences. Please use"
40+
" `cat' to view it properly.\n")
41+
file.write("*------------------------------------------------------*\n")
42+
# @todo Get the result line of moulitest and parse it.
43+
result = subprocess.run('make ' + test_name + ' -C ' +
44+
'testing_suites/moulitest', shell=True,
45+
stdout=subprocess.PIPE,
46+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
47+
file.write(result + '\n')
48+
49+
50+
def run(project_path: str, has_libft_bonuses: bool, project: str, root_path: str):
51+
available_projects = ['ft_ls', 'ft_printf', 'gnl', 'libft', 'libftasm']
52+
# Available projects checks if the given project corresponds to one the moulitest tests.
53+
if project not in available_projects:
54+
raise ValueError("given project not in moulitest available projects.")
55+
if project == "libft":
56+
with open("testing_suites/moulitest/config.ini", 'w+') as file:
57+
file.write("LIBFT_PATH = " + project_path)
58+
include_libft_bonuses()
59+
# @todo Fix moulitest makefile (it starts the bonus even when not asked.)
60+
if not has_libft_bonuses:
61+
exclude_libft_bonuses()
62+
execute_test("libft_bonus", root_path)
63+
include_libft_bonuses()
64+
else:
65+
execute_test("libft_bonus", root_path)
66+
return 0

PyChecker/Utils/__init__.py

Whitespace-only changes.

PyChecker/Utils/author.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import os
7+
8+
9+
def check(project_path: str):
10+
"""
11+
This function will check the author file for the given project.
12+
13+
:param project_path: The path of the project where you want to check the author file
14+
15+
:return: This function will return 0 if everything is ok,
16+
1 if file not found,
17+
2 if there's too many lines in the file,
18+
3 if the newline char is missing in the end of line
19+
"""
20+
# @todo Add a skip + message and handle multiple authors
21+
author_fr = project_path + "/auteur"
22+
author_us = project_path + "/author"
23+
if os.path.exists(author_fr):
24+
count = len(open(author_fr).readlines())
25+
author = "fr"
26+
elif os.path.exists(author_us):
27+
count = len(open(author_us).readlines())
28+
author = "us"
29+
else:
30+
print("Author file not found")
31+
return 1
32+
if count != 1:
33+
print("Too many lines in author file (Or the file is empty)")
34+
return 2
35+
if author == "fr":
36+
with open(author_fr, 'r') as file:
37+
content = file.read()
38+
if "\n" not in content:
39+
print("Missing <newline> character at the end of line")
40+
return 3
41+
elif author == "us":
42+
with open(author_us, 'r') as file:
43+
content = file.read()
44+
if "\n" not in content:
45+
print("Missing <newline> character at the end of line")
46+
return 3
47+
return 0

0 commit comments

Comments
 (0)