Re: [PATCH] test-lib.sh: work around ksh's trap shortcomings

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

 



Brandon Casey wrote:
> Junio C Hamano wrote:
>> Your alias test_done that calls function test_done look ugly and confusing
>> beyond words.  Perhaps test_done() can instead set a global variable and
>> die() can notice it instead, like this?  I haven't bothered to change the
>> other "trap - exit" but I think you got the idea...
> 
> Yes that works and is much clearer. Tested on solaris and irix.

I spoke too soon. Failing tests do not terminate the testing.

ksh does not place the exit status of the shell in $? or provide it as an argument
to the trap function. Possibly the status of the 'exit' command is provided instead?

$ cat test.sh
#!/bin/sh

die () {
    status=$?
    echo >&2 "die status: $status"
    exit $status
}

trap 'die' 0

echo "I am dying"
exit 1

###### END TEST SCRIPT ######

linux $ /bin/sh test.sh
I am dying
die status: 1
linux $ echo $?
1

linux $ /usr/bin/ksh test.sh
I am dying
die status: 1
linux $ echo $?
1

IRIX $ /bin/ksh test.sh
I am dying
die status: 0
IRIX $ echo $?
0

SunOS $ /usr/xpg4/bin/sh test.sh
I am dying
die status: 0
SunOS $ echo $?
0

Ah, no, it looks like the status of the command executed immediately before
exit is what the trap has access to in $?. Adding a call to false before exit
in the above script causes the korn scripts to exit with status 1 on IRIX and
SunOS.

#!/bin/sh

die () {
    status=$?
    echo >&2 "die status: $status"
    exit $status
}

trap 'die' 0

echo "I am dying"
false
exit 1

-brandon
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux