Home | History | Annotate | Download | only in analyzer
      1 #!/usr/bin/perl -w
      2 use strict;
      3 require File::Temp;
      4 use File::Temp ();
      5 
      6 die "update_plist_test <test file> <plist file>\n" if ($#ARGV < 1);
      7 my $testFile = shift @ARGV;
      8 die "error: cannot read file $testFile\n" if (! -r $testFile);
      9 my $plistFile = shift @ARGV;
     10 die "error: cannot read file $plistFile\n" if (! -r $plistFile);
     11 
     12 # Create a temp file for the new test.
     13 my $fh = File::Temp->new();
     14 my $filename = $fh->filename;
     15 $fh->unlink_on_destroy(1);
     16 
     17 # Copy the existing temp file, skipping the FileCheck comments.
     18 open (IN, $testFile) or die "cannot open $testFile\n";
     19 while (<IN>) {
     20   next if (/^\/\/ CHECK/);
     21   print $fh $_;
     22 }
     23 close(IN);
     24 
     25 # Copy the plist data, and specially format it.
     26 open (IN, $plistFile) or die "cannot open $plistFile\n";
     27 my $firstArray = 1;
     28 my $first = 1;
     29 while (<IN>) {
     30   # Skip everything not indented.
     31   next if (/^[^\s]/);
     32   # Skip the first array entry, which is for files.
     33   if ($firstArray) {
     34     if (/<\/array>/) { $firstArray = 0; }
     35 	next;
     36   }
     37   # Format the CHECK lines.
     38   if ($first) {
     39   	print $fh "// CHECK: ";
     40 	$first = 0;
     41   }
     42   else {
     43   	print $fh "// CHECK-NEXT: ";
     44   }
     45   print $fh $_;
     46 }
     47 close (IN);
     48 close ($fh);
     49 
     50 `cp $filename $testFile`;
     51 print "updated $testFile\n";
     52