mirror of
https://github.com/git/git
synced 2024-08-25 10:45:59 +00:00
test-lib: user-friendly alternatives to test [-d|-f|-e]
The helper functions are implemented, documented, and used in a few places to validate them, but not everywhere to avoid useless code churn. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cd035b1cef
commit
2caf20c52b
7
t/README
7
t/README
|
@ -467,6 +467,13 @@ library for your script to use.
|
||||||
<expected> file. This behaves like "cmp" but produces more
|
<expected> file. This behaves like "cmp" but produces more
|
||||||
helpful output when the test is run with "-v" option.
|
helpful output when the test is run with "-v" option.
|
||||||
|
|
||||||
|
- test_path_is_file <file> [<diagnosis>]
|
||||||
|
test_path_is_dir <dir> [<diagnosis>]
|
||||||
|
test_path_is_missing <path> [<diagnosis>]
|
||||||
|
|
||||||
|
Check whether a file/directory exists or doesn't. <diagnosis> will
|
||||||
|
be displayed if the test fails.
|
||||||
|
|
||||||
- test_when_finished <script>
|
- test_when_finished <script>
|
||||||
|
|
||||||
Prepend <script> to a list of commands to run to clean up
|
Prepend <script> to a list of commands to run to clean up
|
||||||
|
|
|
@ -79,18 +79,18 @@ test_expect_success 'rebase -i with the exec command' '
|
||||||
export FAKE_LINES &&
|
export FAKE_LINES &&
|
||||||
test_must_fail git rebase -i A
|
test_must_fail git rebase -i A
|
||||||
) &&
|
) &&
|
||||||
test -f touch-one &&
|
test_path_is_file touch-one &&
|
||||||
test -f touch-two &&
|
test_path_is_file touch-two &&
|
||||||
! test -f touch-three &&
|
test_path_is_missing touch-three " (should have stopped before)" &&
|
||||||
test $(git rev-parse C) = $(git rev-parse HEAD) || {
|
test $(git rev-parse C) = $(git rev-parse HEAD) || {
|
||||||
echo "Stopped at wrong revision:"
|
echo "Stopped at wrong revision:"
|
||||||
echo "($(git describe --tags HEAD) instead of C)"
|
echo "($(git describe --tags HEAD) instead of C)"
|
||||||
false
|
false
|
||||||
} &&
|
} &&
|
||||||
git rebase --continue &&
|
git rebase --continue &&
|
||||||
test -f touch-three &&
|
test_path_is_file touch-three &&
|
||||||
test -f "touch-file name with spaces" &&
|
test_path_is_file "touch-file name with spaces" &&
|
||||||
test -f touch-after-semicolon &&
|
test_path_is_file touch-after-semicolon &&
|
||||||
test $(git rev-parse master) = $(git rev-parse HEAD) || {
|
test $(git rev-parse master) = $(git rev-parse HEAD) || {
|
||||||
echo "Stopped at wrong revision:"
|
echo "Stopped at wrong revision:"
|
||||||
echo "($(git describe --tags HEAD) instead of master)"
|
echo "($(git describe --tags HEAD) instead of master)"
|
||||||
|
@ -105,7 +105,7 @@ test_expect_success 'rebase -i with the exec command runs from tree root' '
|
||||||
FAKE_LINES="1 exec_>touch-subdir" \
|
FAKE_LINES="1 exec_>touch-subdir" \
|
||||||
git rebase -i HEAD^ &&
|
git rebase -i HEAD^ &&
|
||||||
cd .. &&
|
cd .. &&
|
||||||
test -f touch-subdir &&
|
test_path_is_file touch-subdir &&
|
||||||
rm -fr subdir
|
rm -fr subdir
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ test_expect_success 'abort' '
|
||||||
git rebase --abort &&
|
git rebase --abort &&
|
||||||
test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
|
test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
|
||||||
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
|
test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
|
||||||
! test -d .git/rebase-merge
|
test_path_is_missing .git/rebase-merge
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'abort with error when new base cannot be checked out' '
|
test_expect_success 'abort with error when new base cannot be checked out' '
|
||||||
|
@ -213,7 +213,7 @@ test_expect_success 'abort with error when new base cannot be checked out' '
|
||||||
test_must_fail git rebase -i master > output 2>&1 &&
|
test_must_fail git rebase -i master > output 2>&1 &&
|
||||||
grep "Untracked working tree file .file1. would be overwritten" \
|
grep "Untracked working tree file .file1. would be overwritten" \
|
||||||
output &&
|
output &&
|
||||||
! test -d .git/rebase-merge &&
|
test_path_is_missing .git/rebase-merge &&
|
||||||
git reset --hard HEAD^
|
git reset --hard HEAD^
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ testrebase() {
|
||||||
# Clean up the state from the previous one
|
# Clean up the state from the previous one
|
||||||
git reset --hard pre-rebase &&
|
git reset --hard pre-rebase &&
|
||||||
test_must_fail git rebase$type master &&
|
test_must_fail git rebase$type master &&
|
||||||
test -d "$dotest" &&
|
test_path_is_dir "$dotest" &&
|
||||||
git rebase --abort &&
|
git rebase --abort &&
|
||||||
test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
|
test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
|
||||||
test ! -d "$dotest"
|
test ! -d "$dotest"
|
||||||
|
@ -49,7 +49,7 @@ testrebase() {
|
||||||
# Clean up the state from the previous one
|
# Clean up the state from the previous one
|
||||||
git reset --hard pre-rebase &&
|
git reset --hard pre-rebase &&
|
||||||
test_must_fail git rebase$type master &&
|
test_must_fail git rebase$type master &&
|
||||||
test -d "$dotest" &&
|
test_path_is_dir "$dotest" &&
|
||||||
test_must_fail git rebase --skip &&
|
test_must_fail git rebase --skip &&
|
||||||
test $(git rev-parse HEAD) = $(git rev-parse master) &&
|
test $(git rev-parse HEAD) = $(git rev-parse master) &&
|
||||||
git rebase --abort &&
|
git rebase --abort &&
|
||||||
|
@ -62,7 +62,7 @@ testrebase() {
|
||||||
# Clean up the state from the previous one
|
# Clean up the state from the previous one
|
||||||
git reset --hard pre-rebase &&
|
git reset --hard pre-rebase &&
|
||||||
test_must_fail git rebase$type master &&
|
test_must_fail git rebase$type master &&
|
||||||
test -d "$dotest" &&
|
test_path_is_dir "$dotest" &&
|
||||||
echo c > a &&
|
echo c > a &&
|
||||||
echo d >> a &&
|
echo d >> a &&
|
||||||
git add a &&
|
git add a &&
|
||||||
|
|
|
@ -542,6 +542,38 @@ test_external_without_stderr () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# debugging-friendly alternatives to "test [-f|-d|-e]"
|
||||||
|
# The commands test the existence or non-existence of $1. $2 can be
|
||||||
|
# given to provide a more precise diagnosis.
|
||||||
|
test_path_is_file () {
|
||||||
|
if ! [ -f "$1" ]
|
||||||
|
then
|
||||||
|
echo "File $1 doesn't exist. $*"
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_path_is_dir () {
|
||||||
|
if ! [ -d "$1" ]
|
||||||
|
then
|
||||||
|
echo "Directory $1 doesn't exist. $*"
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_path_is_missing () {
|
||||||
|
if [ -e "$1" ]
|
||||||
|
then
|
||||||
|
echo "Path exists:"
|
||||||
|
ls -ld "$1"
|
||||||
|
if [ $# -ge 1 ]; then
|
||||||
|
echo "$*"
|
||||||
|
fi
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# This is not among top-level (test_expect_success | test_expect_failure)
|
# This is not among top-level (test_expect_success | test_expect_failure)
|
||||||
# but is a prefix that can be used in the test script, like:
|
# but is a prefix that can be used in the test script, like:
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue