[Top][All Lists]

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

Re: unable to escape ! in autotest stdout comparison text

From: Eric Blake
Subject: Re: unable to escape ! in autotest stdout comparison text
Date: Tue, 29 May 2018 21:10:49 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 05/29/2018 08:25 PM, John Calcote wrote:
I'm trying to create a test using autotest that compares the stdout of my
program with a string. Unfortunately, the output of the program contains
the path of the program. As part of its output, it writes its own program
name (from argv[0]) to stdout, so I have to use ${abs_top_builddir} as part
of the comparison text - which means I need to use AT_CHECK_UNQUOTED.

Another wrench in the works is that it then also adds an exclamation mark
(!) to the end of the line, so the stdout text I'm trying to compare with
ends with ! - when I run the test, the unquoting code appears to evaluate
the ! and remove the line (bash history feature, I think - there's nothing
in the history starting with my string, so it replaces the entire string
with nothing).

Yeah, bash's handling of ! can be quite a misfeature when you don't want it to happen during scripting. But I thought it was disabled by default in POSIX mode, which is what autotest scripts should be selecting, so are you sure that history expansion is happening?

I've tried escaping with backslash, I've tried quoting with single quotes,
I've tried escaping within double quotes. Nothing works. It seems the
unquoting functionality will not be tricked into allowing a special
character to be escaped.

Any ideas?

Here's my

         [Hello from ${abs_top_builddir}/src/prog!])

First, are you sure you don't want a trailing newline? That is, did src/prog output "!" as it's last character, or "\n" after the "!"? (The placement of the ] in AT_CHECK[_UNQUOTED] matters).

I couldn't quickly reproduce the mangling of ! even though bash is my shell and my /bin/sh, but I did reproduce failure using that as you gave plus a minimal src/prog,, and for compiling and running the testsuite, due to the difference in newlines. Once I fixed that, the test ran successfully. To double-check, look at the generated testsuite, and show the code that it is creating just before AT_STOP_1 (here's what I see with autoconf 2.69):

$as_echo "$at_srcdir/ \"\${abs_top_builddir}/src/prog\""
at_fn_check_prepare_notrace 'a ${...} parameter expansion' ""
( $at_check_trace; "${abs_top_builddir}/src/prog"
) >>"$at_stdout" 2>>"$at_stderr" 5>&-
at_status=$? at_failed=false
at_fn_diff_devnull "$at_stderr" || at_failed=:
echo >>"$at_stdout"; $as_echo "Hello from ${abs_top_builddir}/src/prog!
" | \
  $at_diff - "$at_stdout" || at_failed=:

And $as_echo doesn't appear to be mangling ! for me, as long as I have the right trailing newline.

But since the output is variable, perhaps the easiest thing is to post-process the output prior to comparing it to fixed text, as in:

AT_CHECK_UNQUOTED(["${abs_top_builddir}/src/prog" |
  sed "s|${abs_top_builddir}|DIR|"],,
[Hello from DIR/src/prog!

I'm open to using AT_CHECK also - but I haven't figured out a good way to
access my program without using the shell variables defined in atconfig.

My approach works with both AT_CHECK and AT_CHECK_UNQUOTED, as there is no longer anything variable in the expected output. In fact, since bash changes argv[0] into the absolute path when a PATH lookup was performed, this also works:

AT_CHECK([PATH=$abs_top_builddir/src:$PATH; prog | sed ...] ...

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization: |

reply via email to

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