t/test-lib.sh: minor readability improvements
PATCH 1/1 t/test-lib.sh: minor readability improvements
Tweak/apply parameter expansion. Also use here document to save test results instead of appending each line with ">>".
--- t/test-lib.sh | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
t/test-lib.sh +10 -8
@@ -24,7 +24,7 @@ done,*) *' --tee '*|*' --va'*) mkdir -p test-results BASE=test-results/$(basename "$0" .sh) - (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1; + (GIT_TEST_TEE_STARTED=done ${SHELL-"sh"} "$0" "$@" 2>&1; echo $? > $BASE.exit) | tee $BASE.out test "$(cat $BASE.exit)" = 0 exit
@@ -575,7 +575,7 @@ test_external () { test_external_without_stderr () { # The temporary file has no (and must have no) security # implications. - tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + tmp=${TMPDIR:-"/tmp"} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
@@ -801,12 +801,14 @@ test_done () { mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$.counts" - echo "total $test_count" >> $test_results_path - echo "success $test_success" >> $test_results_path - echo "fixed $test_fixed" >> $test_results_path - echo "broken $test_broken" >> $test_results_path - echo "failed $test_failure" >> $test_results_path - echo "" >> $test_results_path + cat >> "$test_results_path" <<EOF +total $test_count +success $test_success +fixed $test_fixed +broken $test_broken +failed $test_failure + +EOF fi if test "$test_fixed" != 0
Signature · 1 line
1.7.5
Quoted 2 lines · Mathias Lafeldt
Tweak/apply parameter expansion. Also use here document to save test results instead of appending each line with ">>".
Thanks. A few minor nits.
Quoted 10 lines
Signed-off-by Mathias Lafeldt <[email protected]>--- t/test-lib.sh | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)t/test-lib.sh +0
-0
t/test-lib.sh done,*) · line 27
Quoted 5 lines
t/test-lib.sh +1
-1@@ -24,7 +24,7 @@ done,*) *' --tee '*|*' --va'*) mkdir -p test-results BASE=test-results/$(basename "$0" .sh) - (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1; + (GIT_TEST_TEE_STARTED=done ${SHELL-"sh"} "$0" "$@" 2>&1;
Looks unnecessary. Superstition?
Quoted 20 lines
t/test-lib.sh +1
-5echo $? > $BASE.exit) | tee $BASE.out test "$(cat $BASE.exit)" = 0 exit@@ -575,7 +575,7 @@ test_external () { test_external_without_stderr () { # The temporary file has no (and must have no) security # implications. - tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + tmp=${TMPDIR:-"/tmp"} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" [ -f "$stderr" ] || error "Internal error: $stderr disappeared."@@ -801,12 +801,14 @@ test_done () { mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$.counts" - echo "total $test_count" >> $test_results_path - echo "success $test_success" >> $test_results_path - echo "fixed $test_fixed" >> $test_results_path - echo "broken $test_broken" >> $test_results_path
t/test-lib.sh test_done () { · line 811
Quoted 10 lines
t/test-lib.sh +8
-2- echo "failed $test_failure" >> $test_results_path - echo "" >> $test_results_path + cat >> "$test_results_path" <<EOF +total $test_count +success $test_success +fixed $test_fixed +broken $test_broken +failed $test_failure + +EOF
It may probably be even easier to read if you indented the whole thing, using the dash before the here-doc marker, like so:
cat >>"$test_results_path" <<-EOF
total $test_count
success $test_success
...
EOFQuoted 12 lines · Junio C Hamano
Quoted 2 lines · Mathias Lafeldt
Tweak/apply parameter expansion. Also use here document to save test results instead of appending each line with ">>".
Thanks. A few minor nits.
Quoted 5 lines
Signed-off-by Mathias Lafeldt <[email protected]>--- t/test-lib.sh | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
Quoted 12 lines
t/test-lib.sh done,*) · line 27
Quoted 10 lines
t/test-lib.sh +1
-1@@ -24,7 +24,7 @@ done,*) *' --tee '*|*' --va'*) mkdir -p test-results BASE=test-results/$(basename "$0" .sh) - (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1; + (GIT_TEST_TEE_STARTED=done ${SHELL-"sh"} "$0" "$@" 2>&1;Looks unnecessary. Superstition?
IMHO, ${SHELL-sh} is kind of hard to read, especially when you don't know about the ${parameter-word} format. In hindsight, I understand that the change isn't really necessary.
Quoted 9 lines
t/test-lib.sh test_external () { · line 578
Quoted 9 lines
t/test-lib.sh +1
-1echo $? > $BASE.exit) | tee $BASE.out test "$(cat $BASE.exit)" = 0 exit@@ -575,7 +575,7 @@ test_external () { test_external_without_stderr () { # The temporary file has no (and must have no) security # implications. - tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + tmp=${TMPDIR:-"/tmp"}
I guess, you'd prefer ${TMPDIR:-/tmp} here too.
Quoted 25 lines
Quoted 11 lines
t/test-lib.sh +0
-4stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" [ -f "$stderr" ] || error "Internal error: $stderr disappeared."@@ -801,12 +801,14 @@ test_done () { mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$.counts" - echo "total $test_count" >> $test_results_path - echo "success $test_success" >> $test_results_path - echo "fixed $test_fixed" >> $test_results_path - echo "broken $test_broken" >> $test_results_patht/test-lib.sh test_done () { · line 811
Quoted 10 lines
t/test-lib.sh +8
-2- echo "failed $test_failure" >> $test_results_path - echo "" >> $test_results_path + cat >> "$test_results_path" <<EOF +total $test_count +success $test_success +fixed $test_fixed +broken $test_broken +failed $test_failure + +EOFIt may probably be even easier to read if you indented the whole thing, using the dash before the here-doc marker, like so:
Quoted 5 lines
cat >>"$test_results_path" <<-EOF
total $test_count
success $test_success
...
EOFOK, I'll be re-rolling the patch using "<<-EOF".
-Mathias
PATCH v2 1/1 t/test-lib.sh: minor readability improvements
Apply parameter expansion. Also use here document to save test results instead of appending each line with ">>".
--- t/test-lib.sh | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
t/test-lib.sh +9 -7
@@ -575,7 +575,7 @@ test_external () { test_external_without_stderr () { # The temporary file has no (and must have no) security # implications. - tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + tmp=${TMPDIR:-/tmp} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
@@ -801,12 +801,14 @@ test_done () { mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$.counts" - echo "total $test_count" >> $test_results_path - echo "success $test_success" >> $test_results_path - echo "fixed $test_fixed" >> $test_results_path - echo "broken $test_broken" >> $test_results_path - echo "failed $test_failure" >> $test_results_path - echo "" >> $test_results_path + cat >>"$test_results_path" <<-EOF + total $test_count + success $test_success + fixed $test_fixed + broken $test_broken + failed $test_failure + + EOF fi if test "$test_fixed" != 0
Signature · 1 line
1.7.5
Thanks.