1#!/usr/bin/perl -w
2use strict;
3require File::Temp;
4use File::Temp ();
5
6die "update_plist_test <test file> <plist file>\n" if ($#ARGV < 1);
7my $testFile = shift @ARGV;
8die "error: cannot read file $testFile\n" if (! -r $testFile);
9my $plistFile = shift @ARGV;
10die "error: cannot read file $plistFile\n" if (! -r $plistFile);
11
12# Create a temp file for the new test.
13my $fh = File::Temp->new();
14my $filename = $fh->filename;
15$fh->unlink_on_destroy(1);
16
17# Copy the existing temp file, skipping the FileCheck comments.
18open (IN, $testFile) or die "cannot open $testFile\n";
19while (<IN>) {
20  next if (/^\/\/ CHECK/);
21  print $fh $_;
22}
23close(IN);
24
25# Copy the plist data, and specially format it.
26open (IN, $plistFile) or die "cannot open $plistFile\n";
27my $firstArray = 1;
28my $first = 1;
29while (<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}
47close (IN);
48close ($fh);
49
50`cp $filename $testFile`;
51print "updated $testFile\n";
52