diff options
author | Jacob Bachmeyer <jcb@gnu.org> | 2021-05-20 00:15:25 -0500 |
---|---|---|
committer | Jacob Bachmeyer <jcb@gnu.org> | 2021-05-20 00:15:25 -0500 |
commit | 7e634eae6345ab38027f156202e298b591b68fb6 (patch) | |
tree | ea4d803631ae8c3a763cbdcb6d970c3862c9a8a5 | |
parent | 9673505b54f1f2017f4dae7a2b972503e687f04c (diff) | |
download | dejagnu-7e634eae6345ab38027f156202e298b591b68fb6.zip dejagnu-7e634eae6345ab38027f156202e298b591b68fb6.tar.gz dejagnu-7e634eae6345ab38027f156202e298b591b68fb6.tar.bz2 |
Search for POSIX Awk in dejagnu auxiliary launcher
-rw-r--r-- | ChangeLog | 7 | ||||
-rwxr-xr-x | dejagnu | 29 | ||||
-rw-r--r-- | testsuite/launcher.all/command.exp | 13 |
3 files changed, 45 insertions, 4 deletions
@@ -1,3 +1,10 @@ +2021-05-20 Jacob Bachmeyer <jcb@gnu.org> + + * dejagnu: Search for a POSIX Awk and validate that at least a + simple Awk program actually works. + * testsuite/launcher.all/command.exp: Add tests for error produced + when no Awk is found and a help message is requested. + 2021-05-18 Jacob Bachmeyer <jcb@gnu.org> * dejagnu: Redirect input from /dev/null when testing if awk is @@ -222,7 +222,14 @@ if test -n "$AWK" ; then elif test -x "${bindir}/awk" ; then awkbin="${bindir}/awk" else - awkbin=awk + # find what might be a usable awk + # on Solaris 10, POSIX awk is in /usr/xpg4/bin + for awktest in mawk /usr/xpg4/bin/awk nawk awk ; do + if command -v "$awktest" > /dev/null 2>&1 ; then + awkbin=$awktest + break; + fi + done fi if test -n "$GAWK" ; then gawkbin="$GAWK" @@ -231,7 +238,8 @@ elif test -x "${bindir}/gawk" ; then else gawkbin=gawk fi -if command -v "$awkbin" > /dev/null 2>&1 ; then +# The non-POSIX awk in /usr/bin on Solaris 10 fails this test +if echo | "$awkbin" '1 && 1 {exit 0}' > /dev/null 2>&1 ; then have_awk=true else have_awk=false @@ -267,6 +275,15 @@ if expr "$verbose" \> 2 > /dev/null ; then echo GNU Awk interpreter was not found fi fi +# export chosen Awk and GNU Awk +if $have_awk ; then + AWK=$awkbin + export AWK +fi +if $have_gawk ; then + GAWK=$gawkbin + export GAWK +fi # Bash @@ -410,6 +427,10 @@ fi # Are we just looking for a usage message? if $want_help ; then + if $have_awk; then : ; else + echo ERROR: extracting help message requires POSIX Awk; not found + exit 2 + fi if test -z "$command" ; then # want help on the launcher itself help_file=$0 @@ -420,13 +441,13 @@ if $want_help ; then echo ERROR: file "'$help_file'" is not readable exit 2 fi - if awk '/#help$/ { pfxlen = length($0) - 4 } + if "$AWK" '/#help$/ { pfxlen = length($0) - 4 } pfxlen && substr($0, pfxlen) == "#end" { exit 1 } ' "$help_file" ; then echo ERROR: file "'$help_file'" does not contain a help message exit 2 fi - exec awk '/#help$/ { pfxlen = length($0) - 4 } + exec "$AWK" '/#help$/ { pfxlen = length($0) - 4 } pfxlen && substr($0, pfxlen) == "#end" { exit 0 } pfxlen { print substr($0, pfxlen) }' "$help_file" fi diff --git a/testsuite/launcher.all/command.exp b/testsuite/launcher.all/command.exp index 6c400f0..c461b6a 100644 --- a/testsuite/launcher.all/command.exp +++ b/testsuite/launcher.all/command.exp @@ -103,6 +103,19 @@ set tests { { "dejagnu foo --help fails if Tcl variant selected" {foo --help} {EXPECT=true TCLSH=true } 2 "does not contain a help message" } + + { "dejagnu foo --help fails if no POSIX Awk available" + {foo --help} {EXPECT=bogus TCLSH=bogus AWK=bogus GAWK=bogus} 2 + "requires POSIX Awk" } + { "dejagnu foo --help recognizes dummy GNU Awk as Awk" + {foo --help} {EXPECT=bogus TCLSH=bogus AWK=bogus GAWK=true } 2 + "does not contain a help message" } + { + # The above still fails, because true(1) does not actually + # evaluate Awk programs and the Awk program that tests if a help + # message is present returns true if the launcher should abort. + } + } { dejagnu-foo |