Skip to content

Commit

Permalink
Test suite: properly check the exit status of commands.
Browse files Browse the repository at this point in the history
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.)

Print an explicit error message if a command that should fail actually
succeeds.

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 <[email protected]>
Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
  • Loading branch information
Per Cederqvist committed Jan 22, 2015
1 parent d9e0216 commit 0281cba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions regression/scaffold
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,28 @@ function filter_dd
function cmd
{
echo "% $@"
"$@" 2>&1 | replace_path && return 0
return 1
if ! (
exec 3>&1
rv=`(("$@" 2>&1; echo $? >&4) | replace_path >&3 ) 4>&1`
exit $rv
) ; then
echo "% FAIL: The above command should succeed but failed."
exit 1
fi
}

# usage: shouldfail <cmd>..
function shouldfail
{
echo "% $@"
(
"$@" 2>&1 || return 0
return 1
) | replace_path
return $?
if (
exec 3>&1
rv=`(("$@" 2>&1; echo $? >&4) | replace_path >&3 ) 4>&1`
exit $rv
) ; then
echo "% FAIL: The above command should fail but succeeded."
exit 1
fi
}

# usage: list_files
Expand Down
2 changes: 1 addition & 1 deletion regression/t-032.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0281cba

Please sign in to comment.