Skip to content

Commit 4c62d19

Browse files
committed
[FEATURE] Added stdout output when script ran in --no-gui. Fixes #64
Signed-off-by: Jules Lasne (seluj78) <jlasne@student.42.fr>
1 parent 4a718bf commit 4c62d19

12 files changed

Lines changed: 151 additions & 46 deletions

File tree

42PyChecker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def main():
3333
parser.add_argument("--no-makefile", help="Disables Makefile check", action="store_true")
3434
parser.add_argument("--no-norm", help="Disables norm check", action="store_true")
3535
parser.add_argument("--no-static", help="Disables static functions check", action="store_true")
36+
parser.add_argument("--no-extra", help="Disables stats and checks on your extra functions", action="store_true")
3637
parser.add_argument("-p", "--path", help="The path of the project you want to test.", default="", type=str)
3738
parser.add_argument("--show-w", help="Displays the warranty warning from the license.", action="store_true")
3839
parser.add_argument("--show-c", help="Displays the conditions warning from the license.", action="store_true")

PyChecker/projects/libft.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
33
See full notice in `LICENSE'
44
"""
5-
65
import os
76
import glob
8-
import subprocess
9-
from PyChecker.utils import author, forbidden_functions, makefile, norme
7+
from PyChecker.utils import author, forbidden_functions, makefile, norme, static
108
from PyChecker.testing_suite import maintest, moulitest, libftest
119

1210

@@ -33,6 +31,12 @@ def count_extras(project_path: str, required_functions, bonus_functions):
3331
for file in glob.glob(project_path + '/*.c'):
3432
file_list.append(file.replace(project_path + '/', ''))
3533
extra_functions = [item for item in file_list if item not in required_functions and item not in bonus_functions]
34+
print("*---------------------------------------------------------------*")
35+
print("*------------------------Extra functions:-----------------------*")
36+
print("*---------------------------------------------------------------*")
37+
print("You have {} extra functions.".format(len(extra_functions)))
38+
for function in extra_functions:
39+
print(function)
3640
return extra_functions
3741

3842

@@ -58,18 +62,15 @@ def check(root_path: str, args):
5862
bonus_functions = ['ft_lstnew.c', 'ft_lstdelone.c', 'ft_lstdel.c',
5963
'ft_lstiter.c', 'ft_lstadd.c', 'ft_lstmap.c']
6064
authorized_functions = ['free', 'malloc', 'write', 'main']
61-
extra_functions = count_extras(args.path, required_functions, bonus_functions)
62-
print("You have {} extra functions.".format(len(extra_functions)))
63-
65+
if not args.no_extra:
66+
# @todo Stats on all c/h files of project, like with `cloc' ?
67+
count_extras(args.path, required_functions, bonus_functions)
6468
if not args.no_author:
6569
author.check(args.path)
6670
if not args.no_norm:
6771
norme.check(args.path, root_path)
6872
if not args.no_static:
69-
with open(root_path + "/.mystatic", 'w+') as file:
70-
result = subprocess.run(['sh', 'scripts/check_static.sh', args.path],
71-
stdout=subprocess.PIPE).stdout.decode('utf-8')
72-
file.write(result)
73+
static.check(root_path, args)
7374
if not args.no_makefile:
7475
makefile.check(args.path, "libft.a", root_path)
7576
if not args.no_forbidden_functions:

PyChecker/testing_suite/libftest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def run(project_path: str, root_path: str):
1313
1414
:param project_path: The path of the project you want to test.
1515
"""
16+
print("*---------------------------------------------------------------*")
17+
print("*----------------------------Libftest---------------------------*")
18+
print("*---------------------------------------------------------------*")
1619
try:
1720
open("testing_suites/libftest/my_config.sh", 'r')
1821
except FileNotFoundError:
@@ -28,12 +31,14 @@ def run(project_path: str, root_path: str):
2831
result = subprocess.run(['bash', "testing_suites/libftest/grademe.sh",
2932
"-l -s -f -n -u"], stdout=subprocess.PIPE,
3033
stderr=subprocess.STDOUT).stdout.decode('utf-8')
31-
os.rename("deepthought", ".mylibftest")
32-
with open(root_path + "/.mylibftest", 'a') as file:
34+
os.rename("deepthought", ".mylibftest-deepthought")
35+
print("Deepthought file too big. Not printed. See `.mylibftest-deepthought'.")
36+
with open(root_path + "/.mylibftest", 'w+') as file:
3337
file.write("*------------------------------------------------------*\n")
3438
file.write("LIBFTEST\n")
3539
file.write("Warning: This file contains escape sequences. Please use "
3640
"`cat' to view it properly.\n")
3741
file.write("*------------------------------------------------------*\n")
3842
file.write(result)
39-
return 0
43+
print(result)
44+
return 0

PyChecker/testing_suite/maintest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def run_libft(project_path: str, root_path: str):
1414
1515
:param project_path: The path of the project you want to test.
1616
"""
17+
print("*---------------------------------------------------------------*")
18+
print("*----------------------------Maintest---------------------------*")
19+
print("*---------------------------------------------------------------*")
1720
# These are the functions that the maintest tests for the libft.
1821
maintest_functions = ['memset', 'bzero', 'memcpy', 'memccpy', 'memmove',
1922
'memchr', 'memcmp', 'strlen', 'strdup', 'strcpy',
@@ -55,9 +58,11 @@ def run_libft(project_path: str, root_path: str):
5558
stdout=subprocess.PIPE,
5659
stderr=subprocess.STDOUT).stdout.decode('utf-8')
5760
file.write(result + '\n')
61+
print(result)
5862
result = subprocess.run(['./libft_main.out'], stdout=subprocess.PIPE,
5963
stderr=subprocess.STDOUT).stdout.decode('utf-8')
6064
# @todo: Count number of OK and FAILs and yellow tests to get score for maintest
6165
file.write(result + '\n')
66+
print(result)
6267
os.remove("libft_main.c")
6368
os.remove("libft_main.out")

PyChecker/testing_suite/moulitest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def include_libft_bonuses():
1010
"""
1111
This method removes the `.exclude` extention to the libft bonuses files.
1212
"""
13-
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/testing_suite"
13+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/tests"
1414
files = os.listdir(moulitest_libft_tests_path)
1515
for file in files:
1616
if file[:2] == "02":
@@ -23,7 +23,7 @@ def exclude_libft_bonuses():
2323
"""
2424
This method Adds the `.exclude` extention to the libft bonuses files.
2525
"""
26-
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/testing_suite"
26+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/tests"
2727
files = os.listdir(moulitest_libft_tests_path)
2828
for file in files:
2929
if file[:2] == "02":
@@ -45,9 +45,13 @@ def execute_test(test_name: str, root_path: str):
4545
stdout=subprocess.PIPE,
4646
stderr=subprocess.STDOUT).stdout.decode('utf-8')
4747
file.write(result + '\n')
48+
print(result)
4849

4950

5051
def run(project_path: str, has_libft_bonuses: bool, project: str, root_path: str):
52+
print("*---------------------------------------------------------------*")
53+
print("*--------------------------Moulitest----------------------------*")
54+
print("*---------------------------------------------------------------*")
5155
available_projects = ['ft_ls', 'ft_printf', 'gnl', 'libft', 'libftasm']
5256
# Available projects checks if the given project corresponds to one the moulitest tests.
5357
if project not in available_projects:
@@ -63,4 +67,4 @@ def run(project_path: str, has_libft_bonuses: bool, project: str, root_path: str
6367
include_libft_bonuses()
6468
else:
6569
execute_test("libft_bonus", root_path)
66-
return 0
70+
return 0

PyChecker/utils/author.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def check(project_path: str):
1818
3 if the newline char is missing in the end of line
1919
"""
2020
# @todo message and handle multiple authors
21+
print("*---------------------------------------------------------------*")
22+
print("*--------------------------Author file--------------------------*")
23+
print("*---------------------------------------------------------------*")
2124
author_fr = project_path + "/auteur"
2225
author_us = project_path + "/author"
2326
if os.path.exists(author_fr):
@@ -27,21 +30,22 @@ def check(project_path: str):
2730
count = len(open(author_us).readlines())
2831
author = "us"
2932
else:
30-
print("Author file not found")
33+
print("--> Error: Author file not found")
3134
return 1
3235
if count != 1:
33-
print("Too many lines in author file (Or the file is empty)")
36+
print("--> Error: Too many lines in author file (Or the file is empty)")
3437
return 2
3538
if author == "fr":
3639
with open(author_fr, 'r') as file:
3740
content = file.read()
3841
if "\n" not in content:
39-
print("Missing <newline> character at the end of line")
42+
print("--> Error: Missing <newline> character at the end of line")
4043
return 3
4144
elif author == "us":
4245
with open(author_us, 'r') as file:
4346
content = file.read()
4447
if "\n" not in content:
45-
print("Missing <newline> character at the end of line")
48+
print("--> Error: Missing <newline> character at the end of line")
4649
return 3
50+
print("-- NTR (Nothing to Report)")
4751
return 0

PyChecker/utils/forbidden_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def check(project_path: str, binary: 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+
print("*---------------------------------------------------------------*")
20+
print("*----------------------Forbidden functions:---------------------*")
21+
print("*---------------------------------------------------------------*")
1922
functions_called = []
2023
# @todo Check difference between Darwin and Linux `nm'
2124
result = subprocess.run(['nm', project_path + '/' + binary],
@@ -32,4 +35,5 @@ def check(project_path: str, binary: str, authorized_func, root_path: str):
3235
# This is to ignore functions like `__stack_chk_fail'
3336
if not item.startswith("__"):
3437
file.write("You should justify the use of this function: `{}'\n".format(item))
38+
print("You should justify the use of this function: `{}'".format(item))
3539
return 0

0 commit comments

Comments
 (0)