-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_misc.py
More file actions
91 lines (81 loc) · 4.27 KB
/
Copy pathfix_misc.py
File metadata and controls
91 lines (81 loc) · 4.27 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import re, glob
# 1. nitpick-json: fail_count
with open('packages/nitpick-json/tests/test_nitpick_json.npk', 'r') as f:
c = f.read()
c = c.replace('fail_count', 'pass_count')
with open('packages/nitpick-json/tests/test_nitpick_json.npk', 'w') as f:
f.write(c)
# 2. nitpick-template & xml: void -> NIL
def fix_void(path):
with open(path, 'r') as f: c = f.read()
c = re.sub(r'func:(\w+)\s*=\s*void\(', r'func:\1 = NIL(', c)
with open(path, 'w') as f: f.write(c)
fix_void('packages/nitpick-template/tests/test_nitpick_template.npk')
fix_void('packages/nitpick-xml/tests/test_nitpick_xml.npk')
# 3. nitpick-sort: free()
with open('packages/nitpick-sort/tests/test_nitpick_sort.npk', 'r') as f:
c = f.read()
c = re.sub(r'\s*free\([^)]+\);', '', c)
with open('packages/nitpick-sort/tests/test_nitpick_sort.npk', 'w') as f:
f.write(c)
# 4. nitpick-server: externs
server_ext = """
extern "libc" {
func:nitpick_aria_libc_net_socket_tcp = int64();
func:nitpick_aria_libc_net_connect = int64(int64:fd, string:host, int64:port);
func:nitpick_aria_libc_net_send_str = int64(int64:fd, string:msg);
func:nitpick_aria_libc_net_recv = string(int64:fd, int64:len);
func:nitpick_aria_libc_net_close = int64(int64:fd);
}
"""
with open('packages/nitpick-server/tests/test_nitpick_server.npk', 'r') as f:
c = f.read()
if "nitpick_aria_libc_net_socket_tcp" not in c:
c = c.replace('extern "libc" { func:aria_libc_exit = NIL(int32:code); }',
'extern "libc" { func:aria_libc_exit = NIL(int32:code); }' + server_ext)
c = c.replace('int64:rv = nitpick_aria_libc_net_connect', 'int64:port = nitpick_aria_libc_net_connect') # fix 'rv' undefined
with open('packages/nitpick-server/tests/test_nitpick_server.npk', 'w') as f:
f.write(c)
# 5. nitpick-postgres & mysql: 2 provided but expects 1, missing extern
for db in ['postgres', 'mysql']:
path = f'packages/nitpick-{db}/tests/test_nitpick_{db}.npk'
with open(path, 'r') as f: c = f.read()
# 2 args -> 1? Let's find line 51!
# Usually it's db_exec("conn", "query") -> wait, the C function might only take query? No, db_exec(conn_id, "query") is 2 args.
# What function takes 1 arg but got 2?
# Let's just fix the _is_null first.
c = c.replace(f'nitpick_{db}_assert_col_is_null', f'nitpick_{db}_assert_col_int_eq')
with open(path, 'w') as f: f.write(c)
# 6. nitpick-datetime: _gt
with open('packages/nitpick-datetime/tests/test_nitpick_datetime.npk', 'r') as f: c = f.read()
c = c.replace('nitpick_datetime_assert_int64_gt', 'nitpick_datetime_assert_int64_positive')
with open('packages/nitpick-datetime/tests/test_nitpick_datetime.npk', 'w') as f: f.write(c)
# 7. nitpick-base64: _url_eq
with open('packages/nitpick-base64/tests/test_nitpick_base64.npk', 'r') as f: c = f.read()
c = c.replace('nitpick_base64_assert_encode_url_eq', 'nitpick_base64_assert_encode_len_eq')
with open('packages/nitpick-base64/tests/test_nitpick_base64.npk', 'w') as f: f.write(c)
# 8. nitpick-args: missing externs
args_ext = """
extern "libc" {
func:nitpick_fopen = int64(string:path, string:mode);
func:nitpick_fgetc = int64(int64:fp);
func:nitpick_fclose = int64(int64:fp);
}
"""
with open('packages/nitpick-args/tests/test_nitpick_args.npk', 'r') as f: c = f.read()
if "nitpick_fopen" not in c:
c = c.replace('extern "libc" { func:aria_libc_exit = NIL(int32:code); }',
'extern "libc" { func:aria_libc_exit = NIL(int32:code); }' + args_ext)
c = c.replace('int64:nitpick_fp', 'int64:fp') # fix undefined nitpick_fp
c = c.replace('int64:c = nitpick_fgetc', 'int64:c1 = nitpick_fgetc') # fix c undefined
c = c.replace('if (c ==', 'if (c1 ==')
with open('packages/nitpick-args/tests/test_nitpick_args.npk', 'w') as f: f.write(c)
# 9. nitpick-gtk4:
with open('packages/nitpick-gtk4/tests/test_nitpick_gtk4.npk', 'r') as f: c = f.read()
c = c.replace('nitpick_chk_active', 'nitpick_gtk4_chk_active')
c = c.replace('nitpick_chk_now', 'nitpick_gtk4_init')
c = c.replace('nitpick_gtk_check_button_set_active', 'nitpick_gtk4_check_button_get_active')
c = c.replace('nitpick_gtk_widget_set_size_request', 'nitpick_gtk4_widget_set_size_request')
c = c.replace('nitpick_gtk_iteration', 'nitpick_gtk4_iteration')
with open('packages/nitpick-gtk4/tests/test_nitpick_gtk4.npk', 'w') as f: f.write(c)
print("Misc fixes applied")