test-suite: Log everything to a file in non-verbose mode

Using 'return' from a test snippet is now a no-go because it would skip the
assignment of the resulting exit code and it would also skip set +x.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
This commit is contained in:
Johannes Sixt
2009-03-31 15:09:06 +02:00
parent 50f37d18b6
commit abd1fa1a1b
9 changed files with 68 additions and 213 deletions

1
t/.gitignore vendored
View File

@@ -1,2 +1,3 @@
/trash directory* /trash directory*
/test-results /test-results
/test-log

View File

@@ -21,7 +21,7 @@ $(T):
@echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
pre-clean: pre-clean:
$(RM) -r test-results $(RM) -r test-results test-log
clean: clean:
$(RM) -r 'trash directory'.* test-results $(RM) -r 'trash directory'.* test-results

View File

@@ -39,6 +39,7 @@ Standard options
EOF EOF
test_expect_success 'test help' ' test_expect_success 'test help' '
set +x &&
test_must_fail test-parse-options -h > output 2> output.err && test_must_fail test-parse-options -h > output 2> output.err &&
test ! -s output && test ! -s output &&
test_cmp expect.err output.err test_cmp expect.err output.err
@@ -158,6 +159,7 @@ error: did you mean \`--boolean\` (with two dashes ?)
EOF EOF
test_expect_success 'detect possible typos' ' test_expect_success 'detect possible typos' '
set +x &&
test_must_fail test-parse-options -boolean > output 2> output.err && test_must_fail test-parse-options -boolean > output 2> output.err &&
test ! -s output && test ! -s output &&
test_cmp typo.err output.err test_cmp typo.err output.err
@@ -223,6 +225,7 @@ Callback: "not set", 1
EOF EOF
test_expect_success 'OPT_CALLBACK() and callback errors work' ' test_expect_success 'OPT_CALLBACK() and callback errors work' '
set +x &&
test_must_fail test-parse-options --no-length > output 2> output.err && test_must_fail test-parse-options --no-length > output 2> output.err &&
test_cmp expect output && test_cmp expect output &&
test_cmp expect.err output.err test_cmp expect.err output.err

View File

@@ -71,6 +71,7 @@ test_expect_success 'fails with any bad rev or many good revs' '
' '
test_expect_success 'fails silently when using -q' ' test_expect_success 'fails silently when using -q' '
set +x &&
test_must_fail git rev-parse --verify --quiet 2>error && test_must_fail git rev-parse --verify --quiet 2>error &&
test -z "$(cat error)" && test -z "$(cat error)" &&
test_must_fail git rev-parse -q --verify foo 2>error && test_must_fail git rev-parse -q --verify foo 2>error &&

View File

@@ -247,6 +247,7 @@ EOF
test_expect_success 'set-head --auto fails w/multiple HEADs' ' test_expect_success 'set-head --auto fails w/multiple HEADs' '
(cd test && (cd test &&
set +x &&
test_must_fail git remote set-head --auto two >output 2>&1 && test_must_fail git remote set-head --auto two >output 2>&1 &&
test_cmp expect output) test_cmp expect output)
' '

View File

@@ -95,30 +95,15 @@ git checkout master'
test_expect_success 'pull renaming branch into unrenaming one' \ test_expect_success 'pull renaming branch into unrenaming one' \
' '
git show-branch git show-branch
git pull . white && { test_must_fail git pull . white &&
echo "BAD: should have conflicted" git ls-files -s &&
return 1 test "$(git ls-files -u B | wc -l)" -eq 3 &&
} test "$(git ls-files -s N | wc -l)" -eq 1 &&
git ls-files -s
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages for B"
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
return 1
}
sed -ne "/^g/{ sed -ne "/^g/{
p p
q q
}" B | grep master || { }" B | grep master &&
echo "BAD: should have listed our change first" test "$(git diff white N | wc -l)" -eq 0
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
return 1
}
' '
test_expect_success 'pull renaming branch into another renaming one' \ test_expect_success 'pull renaming branch into another renaming one' \
@@ -126,95 +111,44 @@ test_expect_success 'pull renaming branch into another renaming one' \
rm -f B rm -f B
git reset --hard git reset --hard
git checkout red git checkout red
git pull . white && { test_must_fail git pull . white &&
echo "BAD: should have conflicted" test "$(git ls-files -u B | wc -l)" -eq 3 &&
return 1 test "$(git ls-files -s N | wc -l)" -eq 1 &&
}
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages"
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
return 1
}
sed -ne "/^g/{ sed -ne "/^g/{
p p
q q
}" B | grep red || { }" B | grep red &&
echo "BAD: should have listed our change first" test "$(git diff white N | wc -l)" -eq 0
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
return 1
}
' '
test_expect_success 'pull unrenaming branch into renaming one' \ test_expect_success 'pull unrenaming branch into renaming one' \
' '
git reset --hard git reset --hard
git show-branch git show-branch
git pull . master && { test_must_fail git pull . master &&
echo "BAD: should have conflicted" test "$(git ls-files -u B | wc -l)" -eq 3 &&
return 1 test "$(git ls-files -s N | wc -l)" -eq 1 &&
}
test "$(git ls-files -u B | wc -l)" -eq 3 || {
echo "BAD: should have left stages"
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
return 1
}
sed -ne "/^g/{ sed -ne "/^g/{
p p
q q
}" B | grep red || { }" B | grep red &&
echo "BAD: should have listed our change first" test "$(git diff white N | wc -l)" -eq 0
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
return 1
}
' '
test_expect_success 'pull conflicting renames' \ test_expect_success 'pull conflicting renames' \
' '
git reset --hard git reset --hard
git show-branch git show-branch
git pull . blue && { test_must_fail git pull . blue &&
echo "BAD: should have conflicted" test "$(git ls-files -u A | wc -l)" -eq 1 &&
return 1 test "$(git ls-files -u B | wc -l)" -eq 1 &&
} test "$(git ls-files -u C | wc -l)" -eq 1 &&
test "$(git ls-files -u A | wc -l)" -eq 1 || { test "$(git ls-files -s N | wc -l)" -eq 1 &&
echo "BAD: should have left a stage"
return 1
}
test "$(git ls-files -u B | wc -l)" -eq 1 || {
echo "BAD: should have left a stage"
return 1
}
test "$(git ls-files -u C | wc -l)" -eq 1 || {
echo "BAD: should have left a stage"
return 1
}
test "$(git ls-files -s N | wc -l)" -eq 1 || {
echo "BAD: should have merged N"
return 1
}
sed -ne "/^g/{ sed -ne "/^g/{
p p
q q
}" B | grep red || { }" B | grep red &&
echo "BAD: should have listed our change first" test "$(git diff white N | wc -l)" -eq 0
return 1
}
test "$(git diff white N | wc -l)" -eq 0 || {
echo "BAD: should have taken colored branch"
return 1
}
' '
test_expect_success 'interference with untracked working tree file' ' test_expect_success 'interference with untracked working tree file' '
@@ -222,14 +156,8 @@ test_expect_success 'interference with untracked working tree file' '
git reset --hard git reset --hard
git show-branch git show-branch
echo >A this file should not matter echo >A this file should not matter
git pull . white && { test_must_fail git pull . white &&
echo "BAD: should have conflicted" test -f A
return 1
}
test -f A || {
echo "BAD: should have left A intact"
return 1
}
' '
test_expect_success 'interference with untracked working tree file' ' test_expect_success 'interference with untracked working tree file' '
@@ -239,14 +167,8 @@ test_expect_success 'interference with untracked working tree file' '
git show-branch git show-branch
rm -f A rm -f A
echo >A this file should not matter echo >A this file should not matter
git pull . red && { test_must_fail git pull . red &&
echo "BAD: should have conflicted" test -f A
return 1
}
test -f A || {
echo "BAD: should have left A intact"
return 1
}
' '
test_expect_success 'interference with untracked working tree file' ' test_expect_success 'interference with untracked working tree file' '
@@ -256,14 +178,8 @@ test_expect_success 'interference with untracked working tree file' '
git checkout -f master git checkout -f master
git tag -f anchor git tag -f anchor
git show-branch git show-branch
git pull . yellow || { git pull . yellow
echo "BAD: should have cleanly merged" test ! -f M &&
return 1
}
test -f M && {
echo "BAD: should have removed M"
return 1
}
git reset --hard anchor git reset --hard anchor
' '
@@ -276,14 +192,8 @@ test_expect_success 'updated working tree file should prevent the merge' '
git show-branch git show-branch
echo >>M one line addition echo >>M one line addition
cat M >M.saved cat M >M.saved
git pull . yellow && { test_must_fail git pull . yellow &&
echo "BAD: should have complained" diff M M.saved &&
return 1
}
diff M M.saved || {
echo "BAD: should have left M intact"
return 1
}
rm -f M.saved rm -f M.saved
' '
@@ -297,14 +207,8 @@ test_expect_success 'updated working tree file should prevent the merge' '
echo >>M one line addition echo >>M one line addition
cat M >M.saved cat M >M.saved
git update-index M git update-index M
git pull . yellow && { test_must_fail git pull . yellow &&
echo "BAD: should have complained" diff M M.saved &&
return 1
}
diff M M.saved || {
echo "BAD: should have left M intact"
return 1
}
rm -f M.saved rm -f M.saved
' '
@@ -316,18 +220,9 @@ test_expect_success 'interference with untracked working tree file' '
git tag -f anchor git tag -f anchor
git show-branch git show-branch
echo >M this file should not matter echo >M this file should not matter
git pull . master || { git pull . master &&
echo "BAD: should have cleanly merged" test -f M &&
return 1 ! (git ls-files -s | grep M) &&
}
test -f M || {
echo "BAD: should have left M intact"
return 1
}
git ls-files -s | grep M && {
echo "BAD: M must be untracked in the result"
return 1
}
git reset --hard anchor git reset --hard anchor
' '

View File

@@ -73,33 +73,12 @@ test_expect_success 'merge white into red (A->B,M->N)' \
' '
git checkout -b red-white red && git checkout -b red-white red &&
git merge white && git merge white &&
git write-tree >/dev/null || { git write-tree >/dev/null &&
echo "BAD: merge did not complete" test -f B &&
return 1 test -f N &&
} test -f R &&
! test -f A &&
test -f B || { ! test -f M
echo "BAD: B does not exist in working directory"
return 1
}
test -f N || {
echo "BAD: N does not exist in working directory"
return 1
}
test -f R || {
echo "BAD: R does not exist in working directory"
return 1
}
test -f A && {
echo "BAD: A still exists in working directory"
return 1
}
test -f M && {
echo "BAD: M still exists in working directory"
return 1
}
return 0
' '
# This test broke in 8371234ecaaf6e14fe3f2082a855eff1bbd79ae9 # This test broke in 8371234ecaaf6e14fe3f2082a855eff1bbd79ae9
@@ -108,32 +87,12 @@ test_expect_success 'merge blue into white (A->B, mod A, A untracked)' \
git checkout -b white-blue white && git checkout -b white-blue white &&
echo dirty >A && echo dirty >A &&
git merge blue && git merge blue &&
git write-tree >/dev/null || { git write-tree >/dev/null &&
echo "BAD: merge did not complete" test -f A &&
return 1 test `cat A` = dirty &&
} test -f B &&
test -f N &&
test -f A || { ! test -f M
echo "BAD: A does not exist in working directory"
return 1
}
test `cat A` = dirty || {
echo "BAD: A content is wrong"
return 1
}
test -f B || {
echo "BAD: B does not exist in working directory"
return 1
}
test -f N || {
echo "BAD: N does not exist in working directory"
return 1
}
test -f M && {
echo "BAD: M still exists in working directory"
return 1
}
return 0
' '
test_done test_done

View File

@@ -399,20 +399,8 @@ from refs/heads/branch
INPUT_END INPUT_END
test_expect_success \ test_expect_success \
'F: non-fast-forward update skips' \ 'F: non-fast-forward update skips' \
'if git fast-import <input 'test_must_fail git fast-import <input &&
then test $old_branch = `git rev-parse --verify branch^0`
echo BAD gfi did not fail
return 1
else
if test $old_branch = `git rev-parse --verify branch^0`
then
: branch unaffected and failure returned
return 0
else
echo BAD gfi changed branch $old_branch
return 1
fi
fi
' '
test_expect_success \ test_expect_success \
'F: verify pack' \ 'F: verify pack' \

View File

@@ -60,6 +60,7 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
export EDITOR VISUAL export EDITOR VISUAL
GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
TEST_DIRECTORY=$(pwd)
# Protect ourselves from common misconfiguration to export # Protect ourselves from common misconfiguration to export
# CDPATH into the environment # CDPATH into the environment
@@ -167,9 +168,15 @@ fi
exec 5>&1 exec 5>&1
if test "$verbose" = "t" if test "$verbose" = "t"
then then
set_x= set_nox=
exec 4>&2 3>&1 exec 4>&2 3>&1
else else
exec 4>/dev/null 3>/dev/null test_log_dir="$TEST_DIRECTORY/test-log"
mkdir -p "$test_log_dir"
test_log_path="$test_log_dir/${0%.sh}-$$"
set_x='set -x;'
set_nox='set +x'
exec 3>"$test_log_path" 4>&3
fi fi
test_failure=0 test_failure=0
@@ -303,8 +310,9 @@ test_debug () {
} }
test_run_ () { test_run_ () {
eval >&3 2>&4 "$1" eval >&3 2>&4 $set_x "$1" '
eval_ret="$?" eval_ret=$?
$set_nox'
return 0 return 0
} }
@@ -540,7 +548,6 @@ test_done () {
# Test the binaries we have just built. The tests are kept in # Test the binaries we have just built. The tests are kept in
# t/ subdirectory and are run in 'trash directory' subdirectory. # t/ subdirectory and are run in 'trash directory' subdirectory.
TEST_DIRECTORY=$(pwd)
if test -z "$valgrind" if test -z "$valgrind"
then then
if test -z "$GIT_TEST_INSTALLED" if test -z "$GIT_TEST_INSTALLED"