Skip to content

Commit

Permalink
Search for POSIX Awk in dejagnu auxiliary launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Bachmeyer committed May 20, 2021
1 parent 9673505 commit 7e634ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2021-05-20 Jacob Bachmeyer <[email protected]>

* 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 <[email protected]>

* dejagnu: Redirect input from /dev/null when testing if awk is
Expand Down
29 changes: 25 additions & 4 deletions dejagnu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions testsuite/launcher.all/command.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e634ea

Please sign in to comment.