New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial steps of Mutation testing #18984
Changes from 1 commit
abbdcf0
0d2ad9a
ba21529
af605a6
445ab9a
58ab11c
c2d46c3
6688b8a
2b8b98d
5366264
5cc498d
ffbabf4
d24d6ac
84f694d
f6f4545
6e66c0d
b8199e1
cc6c2ee
ed47f89
2f900a0
61794f8
f817a9c
a9493d0
b8c6d14
File filter...
Jump to…
XMLHTTPRequest Mutator - Initial step Mutation testing
- Loading branch information
| @@ -0,0 +1,35 @@ | ||
| import fileinput | ||
| import re | ||
| import subprocess | ||
| import sys | ||
|
|
||
| def mutate_line(file_name, line_number): | ||
| lines = open(file_name, 'r').readlines() | ||
| lines[line_number - 1] = re.sub(r'\s&&\s', ' || ', lines[line_number - 1]) | ||
| out = open(file_name, 'w') | ||
|
||
| out.writelines(lines) | ||
| out.close() | ||
|
|
||
| def mutation_test(file_name): | ||
| lineNumbers = [] | ||
| for line in fileinput.input(file_name): | ||
| if re.search(r'\s&&\s', line): | ||
asajeffrey
Member
|
||
| lineNumbers.append(fileinput.lineno()) | ||
|
|
||
| for lineToMutate in lineNumbers: | ||
| print "Mutating {0} at line {1}".format(file_name, lineToMutate) | ||
asajeffrey
Member
|
||
| 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) | ||
| print "running tests for mutant {0}-{1}".format(file_name, lineToMutate) | ||
| sys.stdout.flush() | ||
| subprocess.call('python mach test-wpt XMLHttpRequest --release', shell=True) | ||
| 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') | ||
dsandeephegde
Contributor
|
||
This is opening the file twice for each mutation, which is fine for this small test, but might be problematic when you come to scale it up.