Re: [PATCH] test-lib.sh: work around ksh's trap shortcomings
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Aug 19, 2008, 00:06 UTC
- Message-ID
- <ZqhiQsjr6llIQS0q8PP8utINgu-mnafhFeUc119IDyjsaBEePvtv9g@cipher.nrlssc.navy.mil>
- In-Reply-To
- <7vbpzplw9o.fsf@gitster.siamese.dyndns.org>
I will try your suggestions.
I also hope you noticed that these patches followed an FYI message and were not meant for direct inclusion. I hope you noticed that since I don't want you to waste your time. Maybe I should have put FYI in the [PATCH] string.
That being said, I (as always) appreciate the comments.
-brandon
Junio C Hamano wrote:
Show 43 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
>
>> In ksh, if trap is called within a function with 0 or EXIT as its signal,
>> then the trap will be executed at the time the function returns. This
>> causes a problem in the test functions since 'trap - exit' is called
>> within the test_done function
>
> 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...
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 11c0275..010bfda 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -156,10 +156,16 @@ test_count=0
> test_fixed=0
> test_broken=0
> test_success=0
> +test_exit_ok=0
>
> die () {
> - echo >&5 "FATAL: Unexpected exit with code $?"
> - exit 1
> + status=$?
> + if test 1 != $test_exit_ok
> + then
> + echo >&5 "FATAL: Unexpected exit with code $status"
> + exit 1
> + fi
> + exit $status
> }
>
> trap 'die' exit
> @@ -415,6 +421,7 @@ test_create_repo () {
> }
>
> test_done () {
> + test_exit_ok=1
> trap - exit
> test_results_dir="$TEST_DIRECTORY/test-results"
> mkdir -p "$test_results_dir"