Skip to content

Commit 6b7febe

Browse files
committed
[FIX/FEATURE] Added in-script clone and status check of 'submodules' which aren't modules anymore. This fixes #97
1 parent 716bce5 commit 6b7febe

File tree

15 files changed

+89
-28
lines changed

15 files changed

+89
-28
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ ENV/
103103
.my*
104104
libft_main.c
105105
libft_main.out
106-
deepthought
106+
deepthought
107+
testing_suites

.gitmodules

Lines changed: 0 additions & 15 deletions
This file was deleted.

42PyChecker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ def main():
179179

180180
check_args_rules(parser, args)
181181

182+
# Here we create the directory where the testing suites will be cloned
183+
if not os.path.exists(root_path + '/testing_suites'):
184+
os.makedirs(root_path + '/testing_suites')
185+
182186
# Here we select the project and start the check based on the argument `--project`
183187
if args.project == "libft":
184188
libft.check(root_path, args)

PyChecker/projects/libft.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def check(root_path: str, args):
118118
print("Libft Part two: " + libftest_results[1])
119119
print("Libft Bonuses: " + libftest_results[2] + '\n')
120120
if not args.no_maintest:
121-
print("Maintest: \n{} OKs and {} FAILs.".format(maintest_ok, maintest_fail))
121+
print("Maintest: \n{} OKs and {} FAILs.".format(maintest_ok, maintest_fail) + '\n')
122122
if not args.no_libft_unit_test:
123123
if args.do_benchmark:
124124
# @todo: Strip useless chars from benchmark results
125-
print('libft-unit-test: \n' + libft_unit_test_results + '\n\n' + benchmark_results)
125+
print('libft-unit-test: \n' + libft_unit_test_results + '\n\n' + benchmark_results + '\n')
126126
else:
127-
print('libft-unit-test: \n' + libft_unit_test_results)
127+
print('libft-unit-test: \n' + libft_unit_test_results + '\n')
128128
return 0

PyChecker/testing_suite/fillit_checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import subprocess
7-
7+
from PyChecker.utils import git
88

99
def run(root_path: str, project_path: str):
1010
"""
@@ -16,6 +16,11 @@ def run(root_path: str, project_path: str):
1616
print("*-------------------------fillit_checker------------------------*")
1717
print("*---------------------------------------------------------------*")
1818

19+
if "fatal: Not a git repository" in git.status(root_path + '/testing_suites/fillit_checker'):
20+
git.clone("https://github.com/anisg/fillit_checker", root_path + '/testing_suites/fillit_checker')
21+
else:
22+
git.reset(root_path + '/testing_suites/fillit_checker')
23+
1924
# @todo: Find a way to supress colors from output
2025
result = subprocess.run(['bash', root_path + "/testing_suites/fillit_checker/test.sh", project_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
2126
print(result)

PyChecker/testing_suite/libft_unit_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import subprocess
88
import os
99
import io
10+
from PyChecker.utils import git
1011

1112

1213
def run(root_path: str, args):
14+
15+
1316
print("*---------------------------------------------------------------*")
1417
print("*------------------------libft-unit-test------------------------*")
1518
print("*---------------------------------------------------------------*")
@@ -20,6 +23,11 @@ def run(root_path: str, args):
2023
file.write("Sorry, this testing suite can only be ran on Darwin computers (MacOS)\n")
2124
return "Sorry, this testing suite can only be ran on Darwin computers (MacOS)"
2225

26+
if "fatal: Not a git repository" in git.status(root_path + '/testing_suites/libft-unit-test'):
27+
git.clone("https://github.com/alelievr/libft-unit-test.git", root_path + '/testing_suites/libft-unit-test')
28+
else:
29+
git.reset(root_path + '/testing_suites/libft-unit-test')
30+
2331
with open(root_path + '/.mylibftunittest', 'w+') as file:
2432
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')
2533
file.write(result)

PyChecker/testing_suite/libftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import os
77
import subprocess
8-
8+
from PyChecker.utils import git
99

1010
def replace_my_config(root_path: str, project_path: str):
1111
with open(root_path + "/testing_suites/libftest/my_config.sh", 'w+') as file:
@@ -28,6 +28,12 @@ def run(project_path: str, root_path: str):
2828
2929
:param project_path: The path of the project you want to test.
3030
"""
31+
32+
if "fatal: Not a git repository" in git.status(root_path + '/testing_suites/libftest'):
33+
git.clone("https://github.com/jtoty/libftest.git", root_path + '/testing_suites/libftest')
34+
else:
35+
git.reset(root_path + '/testing_suites/libftest')
36+
3137
print("*---------------------------------------------------------------*")
3238
print("*----------------------------Libftest---------------------------*")
3339
print("*---------------------------------------------------------------*")

PyChecker/testing_suite/maintest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import re
88
import subprocess
99
import platform
10-
10+
from PyChecker.utils import git
1111

1212
def comment_define(source, destination, tokens):
1313
"""
@@ -32,6 +32,12 @@ def run_libft(project_path: str, root_path: str):
3232
3333
:param project_path: The path of the project you want to test.
3434
"""
35+
36+
if "fatal: Not a git repository" in git.status(root_path + '/testing_suites/Maintest'):
37+
git.clone("https://github.com/QuentinPerez/Maintest.git", root_path + '/testing_suites/Maintest')
38+
else:
39+
git.reset(root_path + '/testing_suites/Maintest')
40+
3541
print("*---------------------------------------------------------------*")
3642
print("*----------------------------Maintest---------------------------*")
3743
print("*---------------------------------------------------------------*")

PyChecker/testing_suite/moulitest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import os
77
import subprocess
8+
from PyChecker.utils import git
9+
810

911
def include_libft_bonuses(root_path: str):
1012
"""
@@ -59,11 +61,16 @@ def execute_test(test_name: str, root_path: str):
5961

6062

6163
def run(project_path: str, has_libft_bonuses: bool, project: str, root_path: str):
64+
65+
if "fatal: Not a git repository" in git.status(root_path + '/testing_suites/moulitest'):
66+
git.clone("https://github.com/yyang42/moulitest.git", root_path + '/testing_suites/moulitest')
67+
else:
68+
git.reset(root_path + '/testing_suites/moulitest')
69+
6270
print("*---------------------------------------------------------------*")
6371
print("*--------------------------Moulitest----------------------------*")
6472
print("*---------------------------------------------------------------*")
6573
available_projects = ['ft_ls', 'ft_printf', 'gnl', 'libft', 'libftasm']
66-
6774
# Available projects checks if the given project corresponds to one the moulitest tests.
6875
if project not in available_projects:
6976
raise ValueError("given project not in moulitest available projects.")

PyChecker/utils/git.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import subprocess
7+
import shutil
8+
9+
10+
def clone(repo: str, path: str):
11+
result = subprocess.run(['git', 'clone', repo, path, '--recursive'],
12+
stdout=subprocess.PIPE,
13+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
14+
return result
15+
16+
17+
def status(path: str):
18+
result = subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'status'],
19+
stdout=subprocess.PIPE,
20+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
21+
# @todo: Parse git's output and return like 0/1
22+
return result
23+
24+
25+
def reset(path: str):
26+
result = subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'fetch', 'origin'],
27+
stdout=subprocess.PIPE,
28+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
29+
result += subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'reset', '--hard', 'origin/master'],
30+
stdout=subprocess.PIPE,
31+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
32+
result += subprocess.run(['git', '--git-dir=' + path + '/.git', '--work-tree=' + path, 'clean', '-f'],
33+
stdout=subprocess.PIPE,
34+
stderr=subprocess.STDOUT).stdout.decode('utf-8')
35+
return result
36+
37+
38+
def delete(path: str):
39+
shutil.rmtree(path)
40+
return
41+
42+
43+
def remove(path: str):
44+
delete(path)

0 commit comments

Comments
 (0)