github.com/containers/podman/v4@v4.9.4/contrib/cirrus/pr-removes-fixed-skips.t (about)

     1  #!/usr/bin/perl -w
     2  
     3  # Don't care if these modules don't exist in CI; only Ed runs this test
     4  use v5.14;
     5  use Test::More;
     6  use Test::Differences;
     7  use File::Basename;
     8  use File::Path          qw(make_path remove_tree);
     9  use File::Temp          qw(tempdir);
    10  use FindBin;
    11  
    12  # Simpleminded parser tests. LHS gets glommed together into one long
    13  # github message; RHS (when present) is the expected subset of issue IDs
    14  # that will be parsed from it.
    15  #
    16  # Again, we glom the LHS into one long multiline string. There doesn't
    17  # seem to be much point to testing line-by-line.
    18  my $parser_tests = <<'END_PARSER_TESTS';
    19  Fixes 100
    20  Fixes: 101
    21  Closes 102
    22  
    23  Fixes: #103                           | 103
    24  Fix: #104, #105                       | 104
    25  Resolves: #106 closes #107            | 106 107
    26  
    27  fix: #108, FIXES: #109, FiXeD: #110   | 108 109 110
    28  Close:   #111 resolved: #112          | 111 112
    29  END_PARSER_TESTS
    30  
    31  
    32  # Read tests from __END__ section of this script
    33  my @full_tests;
    34  while (my $line = <DATA>) {
    35      chomp $line;
    36  
    37      if ($line =~ /^==\s+(.*)/) {
    38          push @full_tests,
    39              { name => $1, issues => [], files => {}, expect => [] };
    40      }
    41      elsif ($line =~ /^\[([\d\s,]+)\]$/) {
    42          $full_tests[-1]{issues} = [ split /,\s+/, $1 ];
    43      }
    44  
    45      #                  1     1   23   3 4   4 5  52
    46      elsif ($line =~ m!^(\!|\+)\s+((\S+):(\d+):(.*))$!) {
    47          push @{$full_tests[-1]{expect}}, $2 if $1 eq '+';
    48  
    49          $full_tests[-1]{files}{$3}[$4] = $5;
    50      }
    51  }
    52  
    53  plan tests => 1 + 1 + @full_tests;
    54  
    55  require_ok "$FindBin::Bin/pr-removes-fixed-skips";
    56  
    57  #
    58  # Parser tests. Just run as one test.
    59  #
    60  my $msg = '';
    61  my @parser_expect;
    62  for my $line (split "\n", $parser_tests) {
    63      if ($line =~ s/\s+\|\s+([\d\s]+)$//) {
    64          push @parser_expect, split ' ', $1;
    65      }
    66      $msg .= $line . "\n";
    67  }
    68  
    69  my @parsed = Podman::CI::PrRemovesFixedSkips::fixed_issues($msg);
    70  eq_or_diff \@parsed, \@parser_expect, "parser parses issue IDs";
    71  
    72  ###############################################################################
    73  
    74  #
    75  # Full tests. Create dummy source-code trees and verify that our check runs.
    76  #
    77  my $tmpdir = tempdir(basename($0) . ".XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
    78  chdir $tmpdir
    79      or die "Cannot cd $tmpdir: $!";
    80  mkdir $_        for qw(cmd libpod pkg test);
    81  for my $t (@full_tests) {
    82      for my $f (sort keys %{$t->{files}}) {
    83          my $lineno = 0;
    84          make_path(dirname($f));
    85          open my $fh, '>', $f or die;
    86  
    87          my @lines = @{$t->{files}{$f}};
    88          for my $i (1 .. @lines + 10) {
    89              my $line = $lines[$i] || "[line $i intentionally left blank]";
    90              print { $fh } $line, "\n";
    91          }
    92          close $fh
    93              or die;
    94      }
    95  
    96      # FIXME: run test
    97      my @actual = Podman::CI::PrRemovesFixedSkips::unremoved_skips(@{$t->{issues}});
    98      eq_or_diff \@actual, $t->{expect}, $t->{name};
    99  
   100      # clean up
   101      unlink $_   for sort keys %{$t->{files}};
   102  }
   103  
   104  chdir '/';
   105  
   106  __END__
   107  
   108  == basic test
   109  [12345]
   110  ! test/foo/bar/foo.bar:10:   skip "#12345: not a .go file"
   111  + test/foo/bar/foo.go:17:    skip "#12345: this one should be found"
   112  + test/zzz/foo.bats:10:   # FIXME: #12345: we detect FIXMEs also
   113  
   114  == no substring matches
   115  [123]
   116  ! test/system/123-foo.bats:12:    skip "#1234: should not match 123"
   117  ! test/system/123-foo.bats:13:    skip "#0123: should not match 123"
   118  
   119  == multiple matches
   120  [456, 789]
   121  + cmd/podman/foo_test.go:10:    Skip("#456 - blah blah")
   122  ! cmd/podman/foo_test.go:15:    Skip("#567 - not a match")
   123  + cmd/podman/foo_test.go:19:    Skip("#789 - match 2nd issue")
   124  + cmd/podman/zzz_test.go:12:    Skip("#789 - in another file")
   125  
   126  == no match on bkp files
   127  [10101]
   128  ! pkg/podman/foo_test.go~:10:    Skip("#10101: no match in ~ file")
   129  ! pkg/podman/foo_test.go.bkp:10:    Skip("#10101: no match in .bkp file")
   130  
   131  == no match if Skip is commented out
   132  [123]
   133  ! test/e2e/foo_test.go:10:   // Skip("#123: commented out")
   134  ! test/system/012-foo.bats:20:      # skip "#123: commented out"