summaryrefslogtreecommitdiff
path: root/test/e2e/remove-betrue
blob: dd56ca818fe36be112861748688f4cb07fce7c1b (plain)
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
#!/usr/bin/perl
#
# one-shot script for #12387
#
use warnings;
use strict;
use File::Basename      qw(dirname);

chdir(dirname($0));

for my $f (glob('*_test.go')) {
    my ($indent, $okvar, $sessionvar, $s);
    my $prev = '';

    open my $fh_in, '<', $f or die;
    open my $fh_out, '>', "$f.tmp.$$" or die;
    while (<$fh_in>) {
        if (/^(\s+)(\S+),\s+_\s+:?=\s+(\S+)\.GrepString\((.*)\)/) {
            print { $fh_out } $prev;
            $prev = $_;
            ($indent, $okvar, $sessionvar, $s) = ($1, $2, $3, $4);
            next;
        }
        elsif ($okvar && /^\s+Expect\($okvar\)\.(Should|To)\(BeTrue\(\)\)\s*$/) {
            print { $fh_out} $indent, "Expect($sessionvar.OutputToString()).To(ContainSubstring($s))\n";
            $okvar = $sessionvar = $s = $prev = '';
            next;
        }
        else {
            print { $fh_out } $prev;
            $prev = $_;
            $okvar = $sessionvar = $s = '';

            # Handle other common cases
            $prev =~ s{
^ (\s+)          Expect\((\S+)\.LineInOutputContains\((.*?)\)\)\.To\(BeTrue\(\)\)
                  }{${1}Expect($2.OutputToString()).To(ContainSubstring($3))}xx;

            $prev =~ s{
^ (\s+)          Expect\((\S+)\.LineInOutputStartsWith\((.*)\)\)\.To\(BeTrue\(\)\)
                  }{${1}Expect($2.OutputToStringArray()).To(ContainElement(HavePrefix($3)))}xx;

        }
    }
    print { $fh_out } $prev;
    close $fh_out or die;
    rename "$f.tmp.$$" => "$f" or die;
}