Skip to content

Commit

Permalink
Refactored mutate random line method
Browse files Browse the repository at this point in the history
  • Loading branch information
dsandeephegde committed Nov 14, 2017
1 parent 61794f8 commit f817a9c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/servo/mutation/test.py
Expand Up @@ -24,18 +24,18 @@ class Status(Enum):
UNEXPECTED = 3


def mutate_random_line(file_name):
def mutate_random_line(file_name, strategy):
line_numbers = []
for line in fileinput.input(file_name):
if re.search(r'\s&&\s', line):
if re.search(strategy['regex'], line):
line_numbers.append(fileinput.lineno())
if len(line_numbers) == 0:
return -1
else:
mutation_line_number = line_numbers[random.randint(0, len(line_numbers) - 1)]
for line in fileinput.input(file_name, inplace=True):
if fileinput.lineno() == mutation_line_number:
line = re.sub(r'\s&&\s', ' || ', line)
line = re.sub(strategy['regex'], strategy['replaceString'], line)
print line.rstrip()
return mutation_line_number

Expand All @@ -47,7 +47,8 @@ def mutation_test(file_name, tests):
status = Status.SKIPPED
print "{0} has local changes, please commit/remove changes before running the test".format(file_name)
else:
mutated_line = mutate_random_line(file_name)
strategy = {'regex': r'\s&&\s', 'replaceString': ' || '}
mutated_line = mutate_random_line(file_name, strategy)
if mutated_line != -1:
print "Mutating {0} at line {1}".format(file_name, mutated_line)
print "compling mutant {0}:{1}".format(file_name, mutated_line)
Expand Down

0 comments on commit f817a9c

Please sign in to comment.