From 7e634eae6345ab38027f156202e298b591b68fb6 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Thu, 20 May 2021 00:15:25 -0500 Subject: Search for POSIX Awk in dejagnu auxiliary launcher --- ChangeLog | 7 +++++++ dejagnu | 29 +++++++++++++++++++++++++---- testsuite/launcher.all/command.exp | 13 +++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d57bea6..4e53a3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-05-20 Jacob Bachmeyer + + * 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 * dejagnu: Redirect input from /dev/null when testing if awk is diff --git a/dejagnu b/dejagnu index 8d3ba70..b3948a8 100755 --- a/dejagnu +++ b/dejagnu @@ -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 -- cgit v1.1