]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test-wrap-argv: add --check parameter
authorJán Tomko <jtomko@redhat.com>
Wed, 15 Jun 2016 12:18:17 +0000 (14:18 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 21 Jun 2016 16:13:07 +0000 (18:13 +0200)
This script can already operate on a list of files.
Add a --check parameter to check if multiple files are wrapped
correctly with a single invocation of the script.

cfg.mk
tests/test-wrap-argv.pl

diff --git a/cfg.mk b/cfg.mk
index d82070d770177b868cb01d9a143088036651ba42..31da9f95f09c572c428a0d23a2a0f3c28700a869 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1109,17 +1109,7 @@ spacing-check:
 
 test-wrap-argv:
        $(AM_V_GEN)files=`$(VC_LIST) | grep -E '\.(ldargs|args)'`; \
-       for file in $$files ; \
-       do \
-           $(PERL) $(top_srcdir)/tests/test-wrap-argv.pl $$file > $${file}-t ; \
-           diff $$file $${file}-t; \
-           res=$$? ; \
-           rm $${file}-t ; \
-           test $$res == 0 || { \
-             echo "$(ME): Incorrect line wrapping in $$file" 1>&2; \
-              echo "$(ME): Use test-wrap-argv.pl to wrap test data files" 1>&2; \
-             exit 1; } \
-       done
+       $(PERL) $(top_srcdir)/tests/test-wrap-argv.pl --check $$files
 
 # sc_po_check can fail if generated files are not built first
 sc_po_check: \
index 97f6903e85b0cd117069d7c6367303c7a3770c78..d66f5b41c1cef0b7adef2804f34a9e5e43de1b28 100755 (executable)
 #
 # If --in-place is supplied as the first parameter of this script,
 # the files will be changed in place.
+# If --check is the first parameter, the script will return
+# a non-zero value if a file is not wrapped correctly.
 # Otherwise the rewrapped files are printed to the standard output.
 
 $in_place = 0;
+$check = 0;
 
 if (@ARGV[0] eq "--in-place") {
     $in_place = 1;
     shift @ARGV;
+} elsif (@ARGV[0] eq "--check") {
+    $check = 1;
+    shift @ARGV;
 }
 
 foreach my $file (@ARGV) {
-    &rewrap($file);
+    $ret = 0;
+    if (&rewrap($file) < 0) {
+        $ret = 1;
+    }
 }
 
+exit $ret;
+
 sub rewrap {
     my $file = shift;
 
@@ -74,11 +85,21 @@ sub rewrap {
             print FILE $line;
         }
         close FILE;
+    } elsif ($check) {
+        my $nl = join('', @lines);
+        my $ol = join('', @orig_lines);
+        unless ($nl eq $ol) {
+            print STDERR $ol;
+            print STDERR "Incorrect line wrapping in $file\n";
+            print STDERR "Use test-wrap-argv.pl to wrap test data files\n";
+            return -1;
+        }
     } else {
         foreach my $line (@lines) {
             print $line;
         }
     }
+    return 0;
 }
 
 sub rewrap_line {