-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_prep_c_tests.py
36 lines (28 loc) · 1.06 KB
/
auto_prep_c_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from os import path, listdir, mkdir
import subprocess
import sys
import shutil
from os import unlink
"""
given a path to a directory of c files
and a dst path for the tests directory
compiles & runs each c file to get return code
and organizes tests inputs & targets in dst directory
"""
c_files_dir = sys.argv[1]
dst_tests_dir = sys.argv[2]
if not path.isdir(dst_tests_dir):
mkdir(dst_tests_dir)
if not path.isdir(path.join(dst_tests_dir, 'inputs')):
mkdir(path.join(dst_tests_dir, 'inputs'))
if not path.isdir(path.join(dst_tests_dir, 'targets')):
mkdir(path.join(dst_tests_dir, 'targets'))
for c_file in listdir(c_files_dir):
subprocess.run(f'gcc {path.join(c_files_dir, c_file)}', shell=True)
child = subprocess.Popen('./a.out', stdout=subprocess.PIPE, shell=True)
_ = child.communicate()[0]
retcode = child.returncode
with open(path.join(dst_tests_dir, 'targets', c_file.replace('.c', '.txt')), 'w') as f:
f.write(str(retcode))
shutil.copy(path.join(c_files_dir, c_file), path.join(dst_tests_dir, 'inputs', c_file))
unlink('a.out')