Skip to content

Commit 5594d66

Browse files
committed
[STAGE] Started adding libft-unit-test (for #51)
1 parent 2b2740e commit 5594d66

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "moulitest"]
88
path = testing_suites/moulitest
99
url = https://github.com/yyang42/moulitest
10+
[submodule "libft-unit-test"]
11+
path = testing_suites/libft-unit-test
12+
url = https://github.com/alelievr/libft-unit-test.git

42PyChecker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def main():
4040
parser.add_argument("--no-tests", help="Disables all the testing suites for the project.", action="store_true")
4141
# @todo Check what option is given based on the selected project.
4242
parser.add_argument("--no-required", help="Disables required functions check", action="store_true")
43+
parser.add_argument("--no-libft-unit-test", help="Disables libft-unit-test", action="store_true")
44+
parser.add_argument("--no-benchmark", help="Disables libft-unit-test benchmarking", action="store_false")
45+
4346
args = parser.parse_args()
4447
if args.show_w:
4548
print_header()

PyChecker/projects/libft.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
from PyChecker.utils import author, forbidden_functions, makefile, norme, static
88
from PyChecker.testing_suite import maintest, moulitest, libftest
9+
from PyChecker.testing_suite import libft_unit_test
910

1011
def check_required(project_path: str, required_functions):
1112
while True:
@@ -86,6 +87,8 @@ def check(root_path: str, args):
8687
libftest_results = libftest.run(args.path, root_path)
8788
if not args.no_maintest:
8889
maintest_ok, maintest_fail = maintest.run_libft(args.path, root_path)
90+
if not args.no_libft_unit_test:
91+
libft_unit_test.run(root_path, args)
8992
print("\n\n\nThe results are in:\n")
9093
if not args.no_author:
9194
print("Author File: \n" + author_results + '\n')
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com>
3+
See full notice in `LICENSE'
4+
"""
5+
6+
import platform
7+
import subprocess
8+
9+
from chardet.universaldetector import UniversalDetector
10+
11+
detector = UniversalDetector()
12+
13+
14+
def get_encoding_type(current_file):
15+
detector.reset()
16+
for line in open(current_file):
17+
detector.feed(line)
18+
if detector.done: break
19+
detector.close()
20+
return detector.result['encoding']
21+
22+
23+
def convert(file: str, target:str):
24+
import codecs
25+
BLOCKSIZE = 1048576 # or some other, desired size in bytes
26+
with codecs.open(file, "r", get_encoding_type(file)) as sourceFile:
27+
with codecs.open(target, "w+", "utf-8") as targetFile:
28+
while True:
29+
contents = sourceFile.read(BLOCKSIZE)
30+
if not contents:
31+
break
32+
targetFile.write(contents)
33+
34+
35+
def run(root_path: str, args):
36+
print("*---------------------------------------------------------------*")
37+
print("*------------------------libft-unit-test------------------------*")
38+
print("*---------------------------------------------------------------*")
39+
if platform.system() != 'Darwin':
40+
print("Sorry, this testing suite can only be ran on Darwin computers (MacOS)")
41+
with open(root_path + '/.mylibftunittest', 'w+') as file:
42+
file.write("Sorry, this testing suite can only be ran on Darwin computers (MacOS)\n")
43+
return "Sorry, this testing suite can only be ran on Darwin computers (MacOS)"
44+
with open(root_path + '/.mylibftunittest', 'w+') as file:
45+
result = subprocess.run(['make', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
46+
file.write(result)
47+
print(result)
48+
result = subprocess.run(['make', 'f', '-C', root_path + '/testing_suites/libft-unit-test', 'LIBFTDIR=' + args.path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
49+
print(result)
50+
convert(root_path + '/testing_suites/libft-unit-test/result.log', root_path + '/result.log')
51+
with open(root_path + '/result.log', 'r') as file2:
52+
data = file2.read()
53+
file.write(data)
54+
if args.do_benchmark:
55+
result = subprocess.run([root_path + '/testing_suite/libft-unit-test/run_test', '-b'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode('utf-8')
56+
print(result)
57+
file.write(result)
58+
# @todo: return results from benchmark and tests

testing_suites/libft-unit-test

Submodule libft-unit-test added at 8091042

0 commit comments

Comments
 (0)