Skip to content

Commit 89aa851

Browse files
committed
[FEATURE] Added command line command with options to control the program. This fixes #63
This also contributes to #54 as you can now skip test. This also fixes #10 ! Signed-off-by: Jules Lasne (seluj78) <jlasne@student.42.fr>
1 parent 51ee5f8 commit 89aa851

14 files changed

Lines changed: 743 additions & 24 deletions

File tree

.github/LICENSE.lesser

Lines changed: 621 additions & 0 deletions
Large diffs are not rendered by default.

42PyChecker.py

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,81 @@
33
See full notice in `LICENSE'
44
"""
55
import os
6-
from PyChecker.projects import libft
6+
import argparse
7+
from PyChecker.projects import libft, ft_commandements, other
8+
# @todo: Add verbose output
9+
# @todo: Add command line output when ran on --no-gui
710

8-
root_path = os.path.dirname(os.path.realpath(__file__))
9-
libft.check("/tmp/libft", root_path)
11+
12+
def print_header():
13+
print("\t42PyChecker Copyright (C) 2018-present Jules Lasne "
14+
"<jules.lasne@gmail.com>\n\tThis program comes with"
15+
" ABSOLUTELY NO WARRANTY; for details run with `--show-w'.\n\tThis is free"
16+
" software, and you are welcome to redistribute it\n\tunder certain"
17+
" conditions; run with `--show-c' for details.")
18+
19+
20+
def main():
21+
root_path = os.path.dirname(os.path.realpath(__file__))
22+
parser = argparse.ArgumentParser()
23+
parser.add_argument("-v", "--verbose", help="Increases output verbosity",
24+
action="store_true")
25+
parser.add_argument("--no-gui", help="disables the Graphical User Interface",
26+
action="store_true")
27+
parser.add_argument("--project", help="Specifies the type of project you want to check", choices=['libft', '42commandements', 'other'], default=None)
28+
parser.add_argument("--no-libftest", help="Disables Libftest", action="store_true")
29+
parser.add_argument("--no-maintest", help="Disables Maintest", action="store_true")
30+
parser.add_argument("--no-moulitest", help="Disables Moulitest", action="store_true")
31+
parser.add_argument("--no-author", help="Disables author file check", action="store_true")
32+
parser.add_argument("--no-forbidden-functions", help="Disables forbidden functions check", action="store_true")
33+
parser.add_argument("--no-makefile", help="Disables Makefile check", action="store_true")
34+
parser.add_argument("--no-norm", help="Disables norm check", action="store_true")
35+
parser.add_argument("--no-static", help="Disables static functions check", action="store_true")
36+
parser.add_argument("-p", "--path", help="The path of the project you want to test.", default="", type=str)
37+
parser.add_argument("--show-w", help="Displays the warranty warning from the license.", action="store_true")
38+
parser.add_argument("--show-c", help="Displays the conditions warning from the license.", action="store_true")
39+
args = parser.parse_args()
40+
if args.show_w:
41+
print_header()
42+
print("THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY"
43+
" APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING\n"
44+
" THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM"
45+
" “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR\n"
46+
" IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES"
47+
" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE\n"
48+
" ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS"
49+
" WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME\n"
50+
" THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.")
51+
return
52+
if args.show_c:
53+
print_header()
54+
with open(root_path + '/.github/LICENSE.lesser', 'r') as file:
55+
print(file.read())
56+
return
57+
if args.project is None:
58+
parser.error("You need to specify a project.")
59+
if args.path == "":
60+
parser.error("`--path' needs to be specified in order for 42PyChecker"
61+
" to know where your project is.")
62+
if args.no_libftest and args.project != "libft":
63+
parser.error("`--no-libftest' can only be applied if libft is selected "
64+
"with `--project'")
65+
if args.no_maintest and args.project != "libft":
66+
parser.error("`--no-maintest' can only be applied if libft is selected "
67+
"with `--project'")
68+
if args.no_moulitest and args.project != "libft":
69+
parser.error("`--no-moulitest' can only be applied if libft is selected"
70+
" with `--project'")
71+
print_header()
72+
if args.project == "libft":
73+
libft.check(root_path, args)
74+
# @todo: Handle options for 42commandements: No option can be passed (like --no-norm)
75+
if args.project == "42commandements":
76+
ft_commandements.check(args)
77+
# @todo: Handle options for other: No option can be passed (like --no-norm)
78+
if args.project == "other":
79+
other.check(root_path, args)
80+
81+
82+
if __name__ == '__main__':
83+
main()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77

88

9-
def check(project_path:str):
9+
def check(args):
1010
"""
1111
This function will test the 42 commandements project.
1212
:param project_path: The path of the project to check
@@ -15,10 +15,10 @@ def check(project_path:str):
1515
1 if the file doesn't exists,
1616
2 if the file content is different.
1717
"""
18-
if not os.path.exists(project_path + '/rendu'):
18+
if not os.path.exists(args.path + '/rendu'):
1919
print("file `rendu' not found.")
2020
return 1
21-
with open(project_path + '/rendu', 'r') as file:
21+
with open(args.path + '/rendu', 'r') as file:
2222
content = file.read()
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.")

PyChecker/projects/libft.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import os
77
import glob
88
import subprocess
9-
from PyChecker.Utils import author, forbidden_functions, makefile, norme
10-
from PyChecker.Tests import maintest, moulitest, libftest
9+
from PyChecker.utils import author, forbidden_functions, makefile, norme
10+
from PyChecker.testing_suite import maintest, moulitest, libftest
1111

1212

1313
def check_bonuses(project_path: str, required_functions, bonus_functions):
@@ -36,7 +36,7 @@ def count_extras(project_path: str, required_functions, bonus_functions):
3636
return extra_functions
3737

3838

39-
def check(project_path: str, root_path: str):
39+
def check(root_path: str, args):
4040
required_functions = ['libft.h', 'ft_strcat.c', 'ft_strncat.c',
4141
'ft_strlcat.c', 'ft_strchr.c', 'ft_strnstr.c',
4242
'ft_strrchr.c', 'ft_strclr.c', 'ft_strcmp.c',
@@ -58,19 +58,28 @@ def check(project_path: str, root_path: str):
5858
bonus_functions = ['ft_lstnew.c', 'ft_lstdelone.c', 'ft_lstdel.c',
5959
'ft_lstiter.c', 'ft_lstadd.c', 'ft_lstmap.c']
6060
authorized_functions = ['free', 'malloc', 'write', 'main']
61-
extra_functions = count_extras(project_path, required_functions, bonus_functions)
61+
extra_functions = count_extras(args.path, required_functions, bonus_functions)
6262
print("You have {} extra functions.".format(len(extra_functions)))
63-
author.check(project_path)
64-
norme.check(project_path, root_path)
65-
with open(root_path + "/.mystatic", 'w+') as file:
66-
result = subprocess.run(['sh', 'scripts/check_static.sh', project_path],
67-
stdout=subprocess.PIPE).stdout.decode('utf-8')
68-
file.write(result)
69-
makefile.check(project_path, "libft.a", root_path)
70-
forbidden_functions.check(project_path, "libft.a", authorized_functions, root_path)
71-
libftest.run(project_path, root_path)
72-
has_libft_bonuses = check_bonuses(project_path, required_functions, bonus_functions)
73-
moulitest.run(project_path, has_libft_bonuses, "libft", root_path)
74-
maintest.run_libft(project_path, root_path)
63+
64+
if not args.no_author:
65+
author.check(args.path)
66+
if not args.no_norm:
67+
norme.check(args.path, root_path)
68+
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+
if not args.no_makefile:
74+
makefile.check(args.path, "libft.a", root_path)
75+
if not args.no_forbidden_functions:
76+
forbidden_functions.check(args.path, "libft.a", authorized_functions, root_path)
77+
if not args.no_libftest:
78+
libftest.run(args.path, root_path)
79+
if not args.no_moulitest:
80+
has_libft_bonuses = check_bonuses(args.path, required_functions, bonus_functions)
81+
moulitest.run(args.path, has_libft_bonuses, "libft", root_path)
82+
if not args.no_maintest:
83+
maintest.run_libft(args.path, root_path)
7584
# @todo add libft-unit-test to the testing suite
7685
return 0

PyChecker/projects/other.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
from PyChecker.utils import author, norme
6+
7+
8+
def check(root_path: str, args):
9+
if not args.no_author:
10+
author.check(args.path)
11+
if not args.no_norm:
12+
norme.check(args.path, root_path)
13+
# @todo: Add the makefile check and find the binary name itself
14+
# @todo: Add forbidden function check based on assumption of what the project is.
15+
return 0
Lines changed: 2 additions & 2 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/tests"
13+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/testing_suite"
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/tests"
26+
moulitest_libft_tests_path = "testing_suites/moulitest/libft_tests/testing_suite"
2727
files = os.listdir(moulitest_libft_tests_path)
2828
for file in files:
2929
if file[:2] == "02":

0 commit comments

Comments
 (0)