forked from EmInReLab/bugsPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myTest.py
145 lines (118 loc) · 6.58 KB
/
myTest.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import myProject
import os
import subprocess as sp
import sys
import pydash as _
def install(param_dict):
print('Installing packages ...')
SCRIPTDIR = os.path.abspath(os.path.dirname(sys.argv[0]))
bug_info = myProject.get_bug_info(param_dict)
if not os.path.isdir(param_dict['output']):
print("can't find the project folder")
exit()
proj_path = param_dict['output']
print(proj_path)
sp.call(['php', '-r', 'copy("https://getcomposer.org/installer", "composer-setup.php");'], shell=False, cwd=proj_path)
sp.call(['php', '-r', "if (hash_file('sha384', 'composer-setup.php') === file_get_contents('https://composer.github.io/installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"], shell=False, cwd=proj_path)
sp.call(["php", "composer-setup.php"], shell=False, cwd=proj_path)
sp.call(['php', '-r', 'unlink("composer-setup.php");'], shell=False, cwd=proj_path)
sp.call(['php', "composer.phar", 'config', '--no-plugins', 'allow-plugins', 'true'], shell=False, cwd=proj_path)
sp.call(["php", "composer.phar", "self-update", "2.5.1"], shell=False, cwd=proj_path)
sp.call(["php", "composer.phar", "install", "--no-interaction", "--no-progress", "--quiet", "--ignore-platform-reqs"], shell=False, cwd=proj_path)
def formatted_test_case_ref(test_case):
ref = test_case['@className'] + '::' + test_case['@methodName']
ref = ref.split('\\')[-1]
if('with data set' in ref):
splitted = ref.split('with data set')
if('#' in splitted[1]):
ref = splitted[0].strip() + '.*'+splitted[1].strip()+'$'
else:
ref = splitted[0].strip() + '.*' + splitted[1].strip()
return ref
def get_chunked_test_cases_cmd_list(test_cases):
max_cmd_string_length = 30000
concatenated_test_cases_list = []
temp = []
for test_case in test_cases:
if(len(_.join(temp + [formatted_test_case_ref(test_case)], '\|')) > max_cmd_string_length):
concatenated_test_cases_list.append(_.join(temp, '\|'))
temp = []
else:
temp.append(formatted_test_case_ref(test_case))
concatenated_test_cases_list.append(_.join(temp, '\|'))
return concatenated_test_cases_list
def run_all_test(param_dict):
SCRIPTDIR = os.path.abspath(os.path.dirname(sys.argv[0]))
bug_info = myProject.get_bug_info(param_dict)
if(not os.path.isdir(param_dict['output'])):
print("can't find the project folder")
exit()
for test_case_chunck in get_chunked_test_cases_cmd_list(bug_info['test_results']['fixed']):
test_script_cmd = ''
if(bug_info['repo_full_name'] == 'magento/magento2' or
bug_info['repo_full_name'] == 'kanboard/kanboard'):
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' ' + bug_info['test_folder'] + ' --filter ' + test_case_chunck
else:
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' --filter ' + test_case_chunck
try:
# print(test_script_cmd)
# sp.call(test_script_cmd, shell=True, cwd=os.path.join(param_dict['output'], bug_info['repo_name']))
outs, errs = sp.Popen(test_script_cmd, shell=True, cwd=param_dict['output'],
universal_newlines=True, stdout=sp.PIPE, stderr=sp.PIPE).communicate()
index = _.find_last_index(outs.split('\n'), lambda x: ('FAILURES!' in x) or ('ERRORS!' in x) or ('OK' in x))
print(outs.split('\n')[index])
print(outs.split('\n')[index+1])
print('')
except Exception as e:
print(e)
def run_single_test_case(param_dict):
SCRIPTDIR = os.path.abspath(os.path.dirname(sys.argv[0]))
bug_info = myProject.get_bug_info(param_dict)
if(not os.path.isdir(param_dict['output'])):
print("can't find the project folder")
exit()
test_case_no = param_dict['test-case']
if(test_case_no <= 0 or test_case_no > len(bug_info['test_results']['fixed'])):
print("can't find the test case")
exit()
test_script_cmd = ''
if(bug_info['repo_full_name'] == 'magento/magento2' or
bug_info['repo_full_name'] == 'kanboard/kanboard'):
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' ' + bug_info['test_folder'] + ' --filter ' + formatted_test_case_ref(bug_info['test_results']['fixed'][test_case_no-1])
else:
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' --filter ' + formatted_test_case_ref(bug_info['test_results']['fixed'][test_case_no-1])
try:
# print(test_script_cmd)
sp.call(test_script_cmd, shell=True, cwd=param_dict['output'])
except Exception as e:
print(e)
def get_failing_test_cases(test_results):
failing_test_cases = []
for test_case in test_results['fixed']:
f = _.find(test_results['buggy'], lambda x:x['@className']==test_case['@className'] and x['@methodName']==test_case['@methodName'])
if(f['@status'] == '3' or f['@status'] == '4'):
failing_test_cases.append(test_case)
return failing_test_cases
def run_all_failing_test(param_dict):
SCRIPTDIR = os.path.abspath(os.path.dirname(sys.argv[0]))
bug_info = myProject.get_bug_info(param_dict)
if(not os.path.isdir(param_dict['output'])):
print("can't find the project folder")
exit()
for test_case_chunck in get_chunked_test_cases_cmd_list(get_failing_test_cases(bug_info['test_results'])):
test_script_cmd = ''
if(bug_info['repo_full_name'] == 'magento/magento2' or
bug_info['repo_full_name'] == 'kanboard/kanboard'):
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' ' + bug_info['test_folder'] + ' --filter ' + test_case_chunck
else:
test_script_cmd = 'vendor/bin/' + bug_info['test_framework'] + ' --filter ' + test_case_chunck
try:
outs, errs = sp.Popen(test_script_cmd, shell=True, cwd=param_dict['output'],
universal_newlines=True, stdout=sp.PIPE, stderr=sp.PIPE).communicate()
index = _.find_last_index(outs.split('\n'), lambda x: ('FAILURES!' in x) or ('ERRORS!' in x) or ('OK' in x))
print(outs.split('\n')[index])
print(outs.split('\n')[index+1])
print("out:\n", outs)
print("err:\n", errs)
except Exception as e:
print(e)