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