groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 23/28: [mom]: Tweak shell style in test script.


From: G. Branden Robinson
Subject: [groff] 23/28: [mom]: Tweak shell style in test script.
Date: Sat, 7 Sep 2024 21:36:49 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 1354485bc37d66dcc3a3825c91899b3cb392e849
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Sep 7 02:32:10 2024 -0500

    [mom]: Tweak shell style in test script.
    
    * contrib/mom/examples/test-mom.sh.in: Tweak shell style.  Favor `[`
      command over `test` in conditional commands.  Stop quoting string
      literals that are pure alphanumeric character sequences.  Favor `$()`
      command substitution syntax over "backticks"; the groff 1.23.0
      release, with 100+ test scripts using the former syntax, established
      that every platform of interest to us supports it.  Exit with status
      1, not 255, on test failure.  The latter is not good practice per
      POSIX[1]--shells use the eighth bit of the exit status to indicate
      that a signal was received.  Rename variables for clarity.  Use AWK
      more idiomatically and frugally of the process table; it's perfectly
      capable of "grep"ping.  Use Bourne style for control structures, not
      pseudo-C.  More carefully quote variables with contents not under our
      control.  Report number of images found, instead of misreporting any
      value less than two as zero ("no images").  Exit with status 2 on
      failure to locate input files.  Quote file name in diagnostic message
      to make an empty value obvious.  Make failure output messages more
      closely resemble others in groff.
    
      (check_has_images): Prepare for patch by Sven Schober.  Poppler's
      pdfimages program writes out a header.  Strip that header from its
      output before counting lines.  Consequently make test of line count
      more precise.
    
    [1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/\
    V3_chap02.html#tag_19_08_02
---
 contrib/mom/ChangeLog               | 28 ++++++++++++++++++++++
 contrib/mom/examples/test-mom.sh.in | 46 ++++++++++++++++++++++---------------
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/contrib/mom/ChangeLog b/contrib/mom/ChangeLog
index 1ac14c90f..1ae753248 100644
--- a/contrib/mom/ChangeLog
+++ b/contrib/mom/ChangeLog
@@ -1,3 +1,31 @@
+2024-09-07  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * examples/test-mom.sh.in: Tweak shell style.  Favor `[` command
+       over `test` in conditional commands.  Stop quoting string
+       literals that are pure alphanumeric character sequences.  Favor
+       `$()` command substitution syntax over "backticks"; the groff
+       1.23.0 release, with 100+ test scripts using the former syntax,
+       established that every platform of interest to us supports it.
+       Exit with status 1, not 255, on test failure.  The latter is not
+       good practice per POSIX[1]--shells use the eighth bit of the
+       exit status to indicate that a signal was received.  Rename
+       variables for clarity.  Use AWK more idiomatically and frugally
+       of the process table; it's perfectly capable of "grep"ping.  Use
+       Bourne style for control structures, not pseudo-C.  More
+       carefully quote variables with contents not under our control.
+       Report number of images found, instead of misreporting any value
+       less than two as zero ("no images").  Exit with status 2 on
+       failure to locate input files.  Quote file name in diagnostic
+       message to make an empty value obvious.  Make failure output
+       messages more closely resemble others in groff.
+       (check_has_images): Prepare for patch by Sven Schober.
+       Poppler's pdfimages program writes out a header.  Strip that
+       header from its output before counting lines.  Consequently make
+       test of line count more precise.
+
+       [1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/\
+       V3_chap02.html#tag_19_08_02
+
 2024-09-07  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * mom.am: Rename generated test file.  It's pretty confusing to
diff --git a/contrib/mom/examples/test-mom.sh.in 
b/contrib/mom/examples/test-mom.sh.in
index 21c8835b8..3fa9be3c6 100644
--- a/contrib/mom/examples/test-mom.sh.in
+++ b/contrib/mom/examples/test-mom.sh.in
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2018-2020 Free Software Foundation, Inc.
+# Copyright (C) 2018-2024 Free Software Foundation, Inc.
 #
 # This file is part of groff.
 #
@@ -22,7 +22,7 @@ builddir="@abs_top_builddir@"
 have_urw_fonts="@groff_have_urw_fonts@"
 examplesdir="$builddir/contrib/mom/examples"
 ret=0
-list="
+examples="
   letter.pdf
   mom-pdf.pdf
   mon_premier_doc.pdf
@@ -33,7 +33,8 @@ list="
   copyright-default.pdf
   "
 
-if test "$have_urw_fonts" != "yes"; then
+if [ "$have_urw_fonts" != yes ]
+then
     echo "URW fonts needed to generate mom examples; skipping test" >&2
     exit 77 # skip
 fi
@@ -47,33 +48,40 @@ do
     fi
 done
 
-# $1: pdf file
+# $1: PDF file
 # $2: expected number of pages
 check_number_pages()
 {
-    echo "Checking number of pages of $1"
-    n_pages=`pdfinfo $1  | grep Pages | awk '{ print $2}'`
-    if test "$n_pages" != "$2"; then
-       echo "  Error: expected $2 pages, found $n_pages pages"
-       ret=255
+    echo "Checking number of pages in $1"
+    page_count=$(pdfinfo "$1" | awk '/Pages/ { print $2}')
+    if [ "$page_count" != "$2" ]
+    then
+       echo "...FAILED: expected $2 pages, found $page_count"
+       ret=1
     fi
 }
 
-# $1 pdf file
+# $1: PDF file
 check_has_images()
 {
-    echo "Checking if $1 has images"
-    n_lines=`pdfimages -list $1 | wc -l `
-    if test $n_lines -le 2; then
-        echo " no images found"
-        ret=255
+    echo "Checking whether $1 has images"
+    image_list=$(pdfimages -list "$1")
+    echo "$image_list"
+    # Strip header out of poppler pdfimages output.
+    image_count=$(echo "$image_list" | sed -n '1,/^---/d;p' | wc -l)
+    if [ "$image_count" -ne 2 ]
+    then
+        echo "...FAILED: expected 2 images, found $image_count"
+        ret=1
     fi
 }
 
-for k in $list; do
-    if ! test -f $examplesdir/$k; then
-        echo "File $k not found"
-        exit 255
+for k in $examples
+do
+    if ! [ -f "$examplesdir"/$k ]
+    then
+        echo "File '$k' not found"
+        exit 2
     fi
 done
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]