From f270220b11ad293ff6793211d1dda769b4a5062d Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 9 Apr 2019 10:57:59 -0400 Subject: [PATCH] build-aux/csvm2csv: Propagate csvm-expand exit status csvm2csv was not failing when csvm-expand exited with a non-zero status. Further, the tests were written incorrectly to account for this. * build-aux/csvm2csv: Set `pipefail' option. * build-aux/test/test-csvm2csv: Fix tests. --- build-aux/csvm2csv | 2 ++ build-aux/test/test-csvm2csv | 36 ++++++++++++------------------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/build-aux/csvm2csv b/build-aux/csvm2csv index 8a589136..c787fb23 100755 --- a/build-aux/csvm2csv +++ b/build-aux/csvm2csv @@ -22,6 +22,8 @@ # header line. ## +set -o pipefail + # account for symlinks, since historically this script lives in a different # directory and has been symlinked for compatibility declare -r mypath=$( dirname "$( readlink -f "$0" )" ) diff --git a/build-aux/test/test-csvm2csv b/build-aux/test/test-csvm2csv index 3e9bded6..3d44e88d 100755 --- a/build-aux/test/test-csvm2csv +++ b/build-aux/test/test-csvm2csv @@ -258,13 +258,10 @@ header, line' ((testsum++)) - local -r result=$( - ../csvm2csv 2>&1 <<< "$input" \ - && echo '(test failure: expected failure)' - ) + local result + ! result=$( ../csvm2csv 2>&1 <<< "$input" ) || return 1 - grep -q '!DIRECTIVE2' <<< "$result" \ - || return 1 + [[ "$result" =~ !DIRECTIVE2 ]] } @@ -272,13 +269,10 @@ test-fail-unknown-var-ref() { ((testsum++)) - local -r result=$( - ../csvm2csv 2>&1 <<< '$undefined' \ - && echo '(test failure: expected failure)' - ) + local result + ! result=$( ../csvm2csv 2>&1 <<< '$undefined' ) || return 1 - grep -q 'unknown.*\$undefined' <<< "$result" \ - || return 1 + [[ "$result" =~ unknown.*\$undefined ]] } @@ -286,13 +280,10 @@ test-fail-non-numeric-range() { ((testsum++)) - local -r result=$( - ../csvm2csv 2>&1 <<< 'A--Z' \ - && echo '(test failure: expected failure)' - ) + local result + ! result=$( ../csvm2csv 2>&1 <<< 'A--Z' ) || return 1 - grep -q 'invalid range.*A--Z' <<< "$result" \ - || return 1 + [[ "$result" =~ invalid\ range.*A--Z ]] } @@ -300,13 +291,10 @@ test-fail-invalid-var-dfn() { ((testsum++)) - local -r result=$( - ../csvm2csv 2>&1 <<< ':BAD@#=var' \ - && echo '(test failure: expected failure)' - ) + local result + ! result=$( ../csvm2csv 2>&1 <<< ':BAD@#=var' ) || return 1 - grep -q 'invalid variable definition.*:BAD@#=var' <<< "$result" \ - || return 1 + [[ "$result" =~ invalid\ variable\ definition.*:BAD@#=var ]] }