[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / utils / analyzer / update_plist_test.pl
blobe142c477d57ae8e80cd45c33d3f8877f6ea67f2d
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 require File::Temp;
5 use File::Temp ();
7 die "update_plist_test <test file> <plist file>\n" if ($#ARGV < 1);
8 my $testFile = shift @ARGV;
9 die "error: cannot read file $testFile\n" if (! -r $testFile);
10 my $plistFile = shift @ARGV;
11 die "error: cannot read file $plistFile\n" if (! -r $plistFile);
13 # Create a temp file for the new test.
14 my $fh = File::Temp->new();
15 my $filename = $fh->filename;
16 $fh->unlink_on_destroy(1);
18 # Copy the existing temp file, skipping the FileCheck comments.
19 open (IN, $testFile) or die "cannot open $testFile\n";
20 while (<IN>) {
21 next if (/^\/\/ CHECK/);
22 print $fh $_;
24 close(IN);
26 # Copy the plist data, and specially format it.
27 open (IN, $plistFile) or die "cannot open $plistFile\n";
28 my $firstArray = 1;
29 my $first = 1;
30 while (<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;
38 # Format the CHECK lines.
39 if ($first) {
40 print $fh "// CHECK: ";
41 $first = 0;
43 else {
44 print $fh "// CHECK-NEXT: ";
46 print $fh $_;
48 close (IN);
49 close ($fh);
51 `cp $filename $testFile`;
52 print "updated $testFile\n";