update_plist_test.pl 1.2 KB

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