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
0 commit comments