Skip to content

Commit 74ce4bb

Browse files
committed
[CHORE] Added some doc. From now on, We close #54 and start fillit.
1 parent e492e6f commit 74ce4bb

File tree

9 files changed

+48
-14
lines changed

9 files changed

+48
-14
lines changed

PyChecker/projects/ft_commandements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def check(args):
2323
if content != "En choisissant d'effectuer ma scolarite a 42, je declare adherer a ces regles ainsi qu'aux valeurs morales qu'elles vehiculent.\n":
2424
print("Error: The `rendu' file content is different from what is expected.")
2525
return 2
26-
return 0
26+
return 0

PyChecker/projects/libft.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def check(root_path: str, args):
9191
libft_unit_test_results, benchmark_results = libft_unit_test.run(root_path, args)
9292
else:
9393
libft_unit_test_results = libft_unit_test.run(root_path, args)
94+
9495
print("\n\n\nThe results are in:\n")
9596
if not args.no_author:
9697
print("Author File: \n" + author_results + '\n')

PyChecker/testing_suite/libft_unit_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ def run(root_path: str, args):
1313
print("*---------------------------------------------------------------*")
1414
print("*------------------------libft-unit-test------------------------*")
1515
print("*---------------------------------------------------------------*")
16+
1617
if platform.system() != 'Darwin':
1718
print("Sorry, this testing suite can only be ran on Darwin computers (MacOS)")
1819
with open(root_path + '/.mylibftunittest', 'w+') as file:
1920
file.write("Sorry, this testing suite can only be ran on Darwin computers (MacOS)\n")
2021
return "Sorry, this testing suite can only be ran on Darwin computers (MacOS)"
22+
2123
with open(root_path + '/.mylibftunittest', 'w+') as file:
2224
result = subprocess.run(['make', 're', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
2325
file.write(result)
@@ -26,6 +28,7 @@ def run(root_path: str, args):
2628
print(result)
2729
file.write(result)
2830
os.rename(root_path + '/testing_suites/libft-unit-test/result.log', root_path + '/.mylibftunittest-results')
31+
# Starts benchmark if asked
2932
if args.do_benchmark:
3033
oldpwd = os.getcwd()
3134
os.chdir(root_path + '/testing_suites/libft-unit-test/')
@@ -37,6 +40,7 @@ def run(root_path: str, args):
3740
for line in file2:
3841
if "WINNER:" in line:
3942
benchmark_results = line
43+
# Open result file with correct encoding
4044
with io.open(root_path + '/.mylibftunittest-results', "r", encoding="ISO-8859-1") as file:
4145
data = file.read()
4246
results = 'OKs: ' + str(data.count('OK')) + '\n'
@@ -46,7 +50,8 @@ def run(root_path: str, args):
4650
results += 'protected: ' + str(data.count('protected')) + '\n'
4751
results += 'not protected:' + str(data.count('not protected'))
4852
print(results)
53+
# Send results back
4954
if args.do_benchmark:
5055
return results, benchmark_results
5156
else:
52-
return results
57+
return results

PyChecker/testing_suite/libftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from shutil import move
1111
from os import fdopen, remove
1212

13+
1314
def replace_my_config(root_path: str, project_path: str):
1415
with open(root_path + "/testing_suites/libftest/my_config.sh", 'w+') as file:
1516
file.write('# !/bin/bash' + '\n')
@@ -24,6 +25,7 @@ def replace_my_config(root_path: str, project_path: str):
2425
file.write('COLOR_TOTAL="${BOLD}${YELLOW}"' + '\n')
2526
file.write('COLOR_DEEPTHOUGHT_PATH="${BOLD}${PURPLE}"' + '\n')
2627

28+
2729
def run(project_path: str, root_path: str):
2830
"""
2931
This function runs the libftest to the given project.
@@ -33,25 +35,27 @@ def run(project_path: str, root_path: str):
3335
print("*---------------------------------------------------------------*")
3436
print("*----------------------------Libftest---------------------------*")
3537
print("*---------------------------------------------------------------*")
38+
3639
replace_my_config(root_path, project_path)
3740
result = subprocess.run(['bash', root_path + "/testing_suites/libftest/grademe.sh",
3841
"-l -s -f -n -u"], stdout=subprocess.PIPE,
3942
stderr=subprocess.STDOUT).stdout.decode('utf-8')
4043
os.rename(root_path + "/deepthought", root_path + "/.mylibftest-deepthought")
4144
print("Deepthought file too big. Not printed. See `.mylibftest-deepthought'.")
45+
4246
with open(root_path + "/.mylibftest", 'w+') as file:
4347
file.write("*------------------------------------------------------*\n")
4448
file.write("LIBFTEST\n")
4549
file.write("Warning: This file contains escape sequences. Please use "
4650
"`cat' to view it properly.\n")
4751
file.write("*------------------------------------------------------*\n")
4852
file.write(result)
53+
4954
print(result)
5055
with open(root_path + "/.mylibftest", 'r') as file:
5156
res = ""
5257
for line in file:
5358
if "Total : " in line:
5459
res += line
55-
totals = []
5660
totals = res.split('\n')
5761
return totals

PyChecker/testing_suite/maintest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111

1212
def comment_define(source, destination, tokens):
13+
"""
14+
This function will comment defines set in tokens.
15+
16+
:param source: The file you want to seek from
17+
:param destination: The file you want to write in
18+
:param tokens: The tokens you want commented
19+
"""
1320
with open(source, 'r') as src, open(destination, 'w+') as dst:
1421
for line in src:
1522
for token in tokens:
@@ -40,10 +47,12 @@ def run_libft(project_path: str, root_path: str):
4047
'itoa', 'strtrim', 'lstnew', 'lstdelone', 'lstdel',
4148
'lstadd', 'lstiter', 'lstmap']
4249
missing_functions = []
50+
4351
for file in maintest_functions:
4452
# @todo: Add a check to handle libft where file aren't at libft/ but can be in libft/src
4553
if not os.path.exists(project_path + '/ft_' + file + '.c'):
4654
missing_functions.append(file)
55+
4756
# @todo: special case for memalloc and memdel
4857
comment_define(root_path + '/testing_suites/Maintest/libft/main.c', root_path + '/libft_main.c', missing_functions)
4958
with open(root_path + "/.mymaintest", 'w+') as file:
@@ -52,6 +61,7 @@ def run_libft(project_path: str, root_path: str):
5261
file.write("Warning: This file contains escape sequences. Please use "
5362
"`cat' to view it properly.\n")
5463
file.write("*------------------------------------------------------*\n")
64+
5565
result = subprocess.run(['gcc', root_path + '/libft_main.c', '-L' + project_path,
5666
'-I' + project_path, "-I" + project_path +
5767
"/include", "-I" + project_path + "/includes",
@@ -62,11 +72,13 @@ def run_libft(project_path: str, root_path: str):
6272
print(result)
6373
result = subprocess.run([root_path + '/libft_main.out'], stdout=subprocess.PIPE,
6474
stderr=subprocess.STDOUT).stdout.decode('utf-8')
75+
6576
# @todo: Count number of OK and FAILs and yellow tests to get score for maintest
6677
file.write(result + '\n')
6778
print(result)
6879
if platform.system() == "Linux":
6980
print("-- Disclaimer: Some of these test may fail where they woudn't on Darwin. (Because Linux ?)")
81+
# Cleanup and return
7082
os.remove(root_path + "/libft_main.c")
7183
os.remove(root_path + "/libft_main.out")
7284
# @todo: Check if FAIL is the right keyword.

PyChecker/testing_suite/moulitest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def include_libft_bonuses(root_path: str):
1010
"""
11-
This method removes the `.exclude` extention to the libft bonuses files.
11+
This function removes the `.exclude` extention to the libft bonuses files.
1212
"""
1313
moulitest_libft_tests_path = root_path + "/testing_suites/moulitest/libft_tests/tests"
1414
files = os.listdir(moulitest_libft_tests_path)
@@ -21,7 +21,7 @@ def include_libft_bonuses(root_path: str):
2121

2222
def exclude_libft_bonuses(root_path: str):
2323
"""
24-
This method Adds the `.exclude` extention to the libft bonuses files.
24+
This function Adds the `.exclude` extention to the libft bonuses files.
2525
"""
2626
moulitest_libft_tests_path = root_path + "/testing_suites/moulitest/libft_tests/tests"
2727
files = os.listdir(moulitest_libft_tests_path)
@@ -32,22 +32,25 @@ def exclude_libft_bonuses(root_path: str):
3232

3333

3434
def execute_test(test_name: str, root_path: str):
35-
available_tests = ['libft_part1', 'libft_part2', 'libft_bonus', 'get_next_line', 'gnl', 'ft_ls', 'ft_printf']
35+
available_tests = ['libft_part1', 'libft_part2', 'libft_bonus',
36+
'get_next_line', 'gnl', 'ft_ls', 'ft_printf']
3637
if test_name not in available_tests:
3738
raise ValueError("Given test not in moulitest available tests.")
39+
3840
with open(root_path + "/.mymoulitest", 'w+') as file:
3941
file.write("*------------------------------------------------------*\n")
4042
file.write("MOULITEST\n")
4143
file.write("Warning: This file contains escape sequences. Please use"
4244
" `cat' to view it properly.\n")
4345
file.write("*------------------------------------------------------*\n")
44-
# @todo: Get the result line of moulitest and parse it.
46+
# Run moulitest
4547
result = subprocess.run('make ' + test_name + ' -C ' + root_path +
4648
'/testing_suites/moulitest', shell=True,
4749
stdout=subprocess.PIPE,
4850
stderr=subprocess.STDOUT).stdout.decode('utf-8')
4951
file.write(result + '\n')
5052
print(result)
53+
# Parse the result
5154
with open(root_path + "/.mymoulitest", 'r') as file:
5255
for line in file:
5356
if "(dots)." in line:
@@ -60,9 +63,11 @@ def run(project_path: str, has_libft_bonuses: bool, project: str, root_path: str
6063
print("*--------------------------Moulitest----------------------------*")
6164
print("*---------------------------------------------------------------*")
6265
available_projects = ['ft_ls', 'ft_printf', 'gnl', 'libft', 'libftasm']
66+
6367
# Available projects checks if the given project corresponds to one the moulitest tests.
6468
if project not in available_projects:
6569
raise ValueError("given project not in moulitest available projects.")
70+
6671
if project == "libft":
6772
with open(root_path + "/testing_suites/moulitest/config.ini", 'w+') as file:
6873
file.write("LIBFT_PATH = " + project_path)

PyChecker/utils/forbidden_functions.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,33 @@ def check(project_path: str, authorized_func, root_path: str):
1616
:param binary_name: The binary that you want to analyze
1717
:param authorized_func: The functions authorized by the project.
1818
"""
19-
with open(project_path + '/Makefile', 'r') as file:
20-
data = file.read()
21-
binary = re.findall("NAME[\s]*=[\s]*(.*)", data)[0]
2219
print("*---------------------------------------------------------------*")
2320
print("*----------------------Forbidden functions:---------------------*")
2421
print("*---------------------------------------------------------------*")
2522
ret = ""
2623
functions_called = []
27-
# @todo: Check difference between Darwin and Linux `nm'
28-
subprocess.run(['make', '-C', project_path, 'all'], stdout=subprocess.PIPE,
29-
stderr=subprocess.STDOUT)
24+
25+
# Get binary name
26+
with open(project_path + '/Makefile', 'r') as file:
27+
data = file.read()
28+
binary = re.findall("NAME[\s]*=[\s]*(.*)", data)[0]
29+
30+
subprocess.run(['make', '-C', project_path, 'all'])
3031
result = subprocess.run(['nm', project_path + '/' + binary],
3132
stdout=subprocess.PIPE,
3233
stderr=subprocess.STDOUT).stdout.decode('utf-8')
3334
for line in result.splitlines():
3435
if "U " in line:
3536
functions_called.append(re.sub(' +', ' ', line))
37+
38+
# Os check for nm differences
3639
if platform.system() == "Darwin":
3740
sys_calls = {func.replace(' U _', '') for func in functions_called}
3841
elif platform.system() == "Linux":
3942
sys_calls = {func.replace(' U ', '') for func in functions_called}
4043
else:
4144
sys_calls = ['Error']
45+
4246
sys_calls = [item for item in sys_calls if not item.startswith("ft_")]
4347
extra_function_call = [item for item in sys_calls if item not in authorized_func]
4448
with open(root_path + "/.myforbiddenfunctions", 'w+') as file:

PyChecker/utils/makefile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,15 @@ def check(project_path: str, root_path: str):
393393
print("*---------------------------------------------------------------*")
394394
print("*----------------------------Makefile---------------------------*")
395395
print("*---------------------------------------------------------------*")
396+
396397
makefile_path = project_path + '/Makefile'
397398
if not os.path.exists(makefile_path):
398399
print("--> Error: Makefile not found.")
399400
return "--> Error: Makefile not found."
400401
with open(makefile_path, 'r') as file:
401402
data = file.read()
402403
binary_name = re.findall("NAME[\s]*=[\s]*(.*)", data)[0]
404+
403405
error_count = 0
404406
error_count += check_makefile_clean_dir(project_path, binary_name, root_path)
405407
error_count += check_makefile_all(project_path, binary_name, root_path)
@@ -408,6 +410,7 @@ def check(project_path: str, root_path: str):
408410
error_count += check_makefile_fclean(project_path, binary_name, root_path)
409411
error_count += check_makefile_name(project_path, binary_name, root_path)
410412
error_count += check_makefile_phony(project_path, binary_name, root_path)
413+
411414
print("\n\n\t\tFound {} errors on your makefile".format(error_count))
412415
with open(root_path + "/.mymakefile", 'a') as file:
413416
file.write("\n\n\t\tFound {} errors on your makefile\n".format(error_count))

PyChecker/utils/norme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def check(project_path: str, root_path: str):
2929
if files == "":
3030
print("-- No source file (.c) or header (.h) to check")
3131
return "-- No source file (.c) or header (.h) to check"
32+
3233
with open(root_path + "/.mynorme", 'w+') as file:
3334
try:
3435
# Run the norminette on those files
@@ -43,7 +44,6 @@ def check(project_path: str, root_path: str):
4344
file.write(result)
4445
error_count = 0
4546
warning_count = 0
46-
# Count the results
4747
error_count = result.count('Error')
4848
warning_count = result.count('Warning')
4949
if error_count != 0 or warning_count != 0:

0 commit comments

Comments
 (0)