On 27/11/17 16:06, Bernhard Voelker wrote:
> On 11/27/2017 07:21 PM, Pádraig Brady wrote:
>> Blush. Please apply.
> 
> Thanks, pushed.
> 
>>> BTW: what do you think about a new syntax-check rule to verify that
>>> all options in usage are actually supported?
>>> Some of the option checks for some utilities might become complicated,
>>> but maybe still worth ...
>>
>> I've caught this particular issue myself in a couple of patches from others,
>> so I'll write a syntax check later today hopefully.
> 
> I've also played a bit ... and it turned out to become a regular
> test instead of a syntax-check rule.
> It's a draft, and I only tested here on openSUSE:Tumbleweed,
> but at least it seems to be a good start.  Maybe it should be
> marked as expensive.

Cool stuff. This correlates a lot of things.
It's not that expensive really.
Takes about 9s on my oldish laptop.

This would be the first real use of awk
(I notice one other test using gawk which I'll change to using something else).
Attached is a diff to change to using sed.
Also it simplifies the subsequent sed calls to avoid the separate cases.

thanks!
Pádraig
diff --git a/src/readlink.c b/src/readlink.c
index abbd352..6b41f79 100644
--- a/src/readlink.c
+++ b/src/readlink.c
@@ -78,7 +78,7 @@ usage (int status)
 \n\
                                 without requirements on components existence\n\
   -n, --no-newline              do not output the trailing delimiter\n\
-  -q, --quiet,\n\
+  -q, --quiet\n\
   -s, --silent                  suppress most error messages (on by default)\n\
   -v, --verbose                 report error messages\n\
   -z, --zero                    end each output line with NUL, not newline\n\
diff --git a/tests/misc/usage_vs_getopt.sh b/tests/misc/usage_vs_getopt.sh
index 923bb30..09b97d9 100755
--- a/tests/misc/usage_vs_getopt.sh
+++ b/tests/misc/usage_vs_getopt.sh
@@ -36,19 +36,9 @@ checkprg () {
   # Get output for --help.
   $prg --help > help || fail=1
 
-  # Get list of options of the utility, including --help but stopping
-  # at --version to avoid to get lines with explanations below the options
-  # list like e.g. in 'cut --help | grep -F -- "-M"'.
-  awk '/^[ ]*--version/ { exit; }
-       /^[ ]*-/ {
-         for(i=1;i<=NF;i++) {
-           if (substr($i,1,1)!="-")
-             break;
-           print gensub(/[[,=].*$/,"",1,$i)
-         }
-       }
-       ' help \
-    | grep . > opts || framework_failure_
+  sed -n -e '/--version/q' \
+    -e 's/^ \{2,6\}-/-/; s/  .*//; s/[=[].*//; s/, /\'$'\n''/g; s/^-/-/p' help \
+    > opts || framework_failure_
 
   # Test all options mentioned in usage (but --version).
   while read opt; do
@@ -72,16 +62,7 @@ checkprg () {
       # Replace $opt in stderr output by the neutral placeholder.
       # Differentiate between long vs. short option error messages.
       # Fail if the stderr output is identical to the above provoked error.
-      case "$opt" in
-        '--'*)
-          sed "s/$opt/OPT/" < err1 > err || framework_failure_
-          compare expl err && { fail=1; cat err1; }
-          ;;
-        *)
-          sed "s/'.'/'OPT'/" < err1 > err || framework_failure_
-          compare exps err && { fail=1; cat err1; }
-          ;;
-      esac
+      sed -e "s/$opt/OPT/" -e "s/'.'/'OPT'/" < err1 > err || framework_failure_
     fi
   done < opts
 }

Reply via email to