Added Test Mapping framework and running through a path.

This commit is contained in:
Sandeep Hegde 2017-10-24 22:16:48 -04:00
parent 0d2ad9a5be
commit ba2152900c
3 changed files with 48 additions and 10 deletions

View file

@ -0,0 +1,29 @@
from os import listdir
from os.path import isfile, isdir, join
import json
import sys
import test
def get_folders_list(path):
folder_list = []
for filename in listdir(path):
if (isdir(join(path, filename))):
folder_name = join(path,filename)
folder_list.append(folder_name)
return(folder_list)
def mutation_test_for(mutation_path):
test_mapping_file = join(mutation_path, 'Test_mapping.json')
if(isfile(test_mapping_file)):
json_data = open(test_mapping_file).read()
test_mapping = json.loads(json_data)
for src_file in test_mapping.keys():
test.mutation_test(join(mutation_path,src_file.encode('utf-8')), test_mapping[src_file])
for folder in get_folders_list(mutation_path):
mutation_test_for(folder)
else:
print ("This folder %s has no test mapping file." %(mutation_path))
mutation_test_for(sys.argv[1])

View file

@ -10,7 +10,7 @@ def mutate_line(file_name, line_number):
out.writelines(lines)
out.close()
def mutation_test(file_name):
def mutation_test(file_name, tests):
lineNumbers = []
for line in fileinput.input(file_name):
if re.search(r'\s&&\s', line):
@ -21,17 +21,16 @@ def mutation_test(file_name):
mutate_line(file_name, lineToMutate)
print "compling mutant {0}-{1}".format(file_name, lineToMutate)
sys.stdout.flush()
subprocess.call('python mach build --release', shell=True)
#subprocess.call('python mach build --release', shell=True)
print "running tests for mutant {0}-{1}".format(file_name, lineToMutate)
sys.stdout.flush()
testStatus = subprocess.call('python mach test-wpt XMLHttpRequest --release', shell=True)
if testStatus != 0:
print('Failed in while running `python mach test-wpt XMLHttpRequest --release`')
print "mutated file {0} diff".format(file_name)
sys.stdout.flush()
subprocess.call('git --no-pager diff {0}'.format(file_name), shell=True)
for test in tests:
testStatus = subprocess.call("python mach test-wpt {0} --release".format(test.encode('utf-8')), shell=True)
if testStatus != 0:
print('Failed in while running `python mach test-wpt {0} --release`'.format(test.encode('utf-8')))
print "mutated file {0} diff".format(file_name)
sys.stdout.flush()
subprocess.call('git --no-pager diff {0}'.format(file_name), shell=True)
print "reverting mutant {0}-{1}".format(file_name, lineToMutate)
sys.stdout.flush()
subprocess.call('git checkout {0}'.format(file_name), shell=True)
mutation_test('components/script/dom/xmlhttprequest.rs')