-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutator.pl
73 lines (58 loc) · 1.05 KB
/
mutator.pl
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
# Usage: mutator.pl FILE
use File::Copy qw/mv cp/;
($f) = @ARGV;
%m = (
0 => 'OK',
256 => 'FAIL',
);
open(my $FH, $f) or die();
my @all;
# slurp
while(<$FH>)
{
push @all, $_;
}
close($FH);
$mutator = "==";
$replacement = "!=";
# first pass. Count the number of mutators.
foreach my $line (@all)
{
if ($line =~ m/$mutator/)
{
$count++;
}
}
print "You have $count occurences of $mutator\n";
# second pass. Create mutants.
foreach my $n (1 .. $count)
{
@copy = @all;
$i = 0;
open(my $OH, '>', $f . "." . $n) or next;
foreach my $line (@copy)
{
if ($line =~ m/$mutator/)
{
$i++;
if ($n eq $i)
{
$line =~ s/$mutator/$replacement/;
}
}
print $OH $line;
}
close($OH);
}
# store away original.
mv($f, $f . ".orig");
# move each mutant to original
foreach my $n (1 .. $count)
{
mv($f . "." . $n, $f) or die "$!";
$res = system("go test");
warn "Result for $n = $res";
mv($f, $f . ".$n." . $m{$res});
}
unlink($f);
cp($f . ".orig", $f);