-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
42 lines (30 loc) · 1.11 KB
/
test.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
37
38
39
40
41
import os
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def check(input: str, expected: int):
os.system(f'./9cc "{input}" > tmp.s')
os.system("cc -o tmp tmp.s")
returned_value = (os.system("./tmp") >> 8) & 0xff
if expected == returned_value:
print(f"{bcolors.OKGREEN}passed:{input=} {expected=} {bcolors.ENDC}")
return True
print(f"{bcolors.FAIL}FAIL:check:{input=} {expected=} {returned_value=}{bcolors.ENDC}")
return False
def checkandlink(input: str, expected: int):
os.system(f'./9cc "{input}" > tmp.s')
os.system("gcc -S testfunc.c -o testfunc.s")
os.system("cc -o tmp tmp.s testfunc.s")
returned_value = (os.system("./tmp") >> 8) & 0xff
if expected == returned_value:
print(f"{bcolors.OKGREEN}passed:{input=} {expected=} {bcolors.ENDC}")
return True
print(f"{bcolors.FAIL}FAIL:check:{input=} {expected=} {returned_value=}{bcolors.ENDC}")
return False