[libvirt] [PATCH 8/8] test-wrap-argv: add --check parameter

Ján Tomko jtomko at redhat.com
Wed Jun 15 16:39:35 UTC 2016


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                  | 12 +-----------
 tests/test-wrap-argv.pl | 23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 297ca3a..f48c035 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1108,17 +1108,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: \
diff --git a/tests/test-wrap-argv.pl b/tests/test-wrap-argv.pl
index 97f6903..d66f5b4 100755
--- a/tests/test-wrap-argv.pl
+++ b/tests/test-wrap-argv.pl
@@ -24,19 +24,30 @@
 #
 # 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 {
-- 
2.7.3




More information about the libvir-list mailing list