From 5116cc978798cedd7a522d3fdd3140efde9933b3 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 22 Aug 2011 12:14:32 +0200 Subject: [PATCH] tap/awk: prepare to fetch the exit status of the test command * lib/tap-driver.sh: Rewrite some logic in the main parsing loop, to make it possible to read the exit status of the test command from the last line of the input stream. --- ChangeLog | 7 +++++++ lib/tap-driver.sh | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e536ff6dd..5f17e99a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-08-22 Stefano Lattarini + + tap/awk: prepare to fetch the exit status of the test command + * lib/tap-driver.sh: Rewrite some logic in the main parsing loop, + to make it possible to read the exit status of the test command + from the last line of the input stream. + 2011-08-22 Stefano Lattarini tap/awk: refactor for future changes diff --git a/lib/tap-driver.sh b/lib/tap-driver.sh index 34da1813f..09fcaee0f 100755 --- a/lib/tap-driver.sh +++ b/lib/tap-driver.sh @@ -121,7 +121,7 @@ fi # expression | getline [var] # idiom, which should allow us to obtain the final exit status from # when closing it. - { test $merge -eq 0 || exec 2>&1; "$@"; } \ + { test $merge -eq 0 || exec 2>&1; "$@"; echo $?; } \ | LC_ALL=C ${AM_TAP_AWK-awk} \ -v me="$me" \ -v test_script_name="$test_name" \ @@ -458,13 +458,33 @@ plan_seen = NO_PLAN ## PARSING ## ## --------- ## +is_first_read = 1 + while (1) { + # Involutions required so that we are able to read the exit status + # from the last input line. st = getline - if (st == 0) # End-of-input - break - else if (st < 0) # I/O error. + if (st < 0) # I/O error. fatal("I/O error while reading from input stream") + else if (st == 0) # End-of-input + { + if (is_first_read) + abort("in input loop: only one input line") + break + } + if (is_first_read) + { + is_first_read = 0 + nextline = $0 + continue + } + else + { + curline = nextline + nextline = $0 + $0 = curline + } # Copy any input line verbatim into the log file. print # Parsing of TAP input should stop after a "Bail out!" directive. -- 2.47.2