Re: [GUILT v3 09/31] Test suite: properly check the exit status of commands.
On Fri, May 16, 2014 at 04:45:56PM +0200, Per Cederqvist wrote:
Show 28 quoted lines
> The "cmd" and "shouldfail" functions checked the exit status of the
> replace_path function instead of the actual command that was running.
> (The $? construct checks the exit status of the last command in a
> pipeline, not the first command.)
>
> Updated t-032.sh, which used "shouldfail" instead of "cmd" in one
> place. (The comment in the script makes it clear that the command is
> expected to succeed.)
>
> Signed-off-by: Per Cederqvist <cederp@opera.com>
> ---
> regression/scaffold | 17 +++++++++++------
> regression/t-032.sh | 2 +-
> 2 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/regression/scaffold b/regression/scaffold
> index 5c8b73e..e4d7487 100644
> --- a/regression/scaffold
> +++ b/regression/scaffold
> @@ -51,18 +51,23 @@ function filter_dd
> function cmd
> {
> echo "% $@"
> - "$@" 2>&1 | replace_path && return 0
> - return 1
> + (
> + exec 3>&1
> + rv=`(("$@" 2>&1; echo $? >&4) | replace_path >&3 ) 4>&1`Wow. This took a while to decipher :)
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Show 37 quoted lines
> + exit $rv
> + )
> + return $?
> }
>
> # usage: shouldfail <cmd>..
> function shouldfail
> {
> echo "% $@"
> - (
> - "$@" 2>&1 || return 0
> - return 1
> - ) | replace_path
> + ! (
> + exec 3>&1
> + rv=`(("$@" 2>&1; echo $? >&4) | replace_path >&3 ) 4>&1`
> + exit $rv
> + )
> return $?
> }
>
> diff --git a/regression/t-032.sh b/regression/t-032.sh
> index b1d5f19..bba401e 100755
> --- a/regression/t-032.sh
> +++ b/regression/t-032.sh
> @@ -28,7 +28,7 @@ shouldfail guilt import -P foo3 foo
> cmd guilt import -P foo2 foo
>
> # ok
> -shouldfail guilt import foo
> +cmd guilt import foo
>
> # duplicate patch name (implicit)
> shouldfail guilt import foo
> --
> 1.8.3.1
> --
Fact: 28.1% of all statistics are generated randomly.