Browse Source

t3600: Use test prerequisite tags

There are two prerequisites:

- The filesystem supports names with tabs or new-lines.

- Files cannot be removed if their containing directory is read-only.

Previously, whether these preconditions are satisified was tested inside
test_expect_success. We move these tests outside because, strictly
speaking, they are not part of the tests.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
maint
Johannes Sixt 16 years ago
parent
commit
56e78bfb29
  1. 58
      t/t3600-rm.sh

58
t/t3600-rm.sh

@ -12,31 +12,37 @@ test_expect_success \
'Initialize test directory' \ 'Initialize test directory' \
"touch -- foo bar baz 'space embedded' -q && "touch -- foo bar baz 'space embedded' -q &&
git add -- foo bar baz 'space embedded' -q && git add -- foo bar baz 'space embedded' -q &&
git commit -m 'add normal files' && git commit -m 'add normal files'"
test_tabs=y &&
if touch -- 'tab embedded' 'newline if touch -- 'tab embedded' 'newline
embedded' embedded' 2>/dev/null
then then
test_set_prereq FUNNYNAMES
else
say 'Your filesystem does not allow tabs in filenames.'
fi

test_expect_success FUNNYNAMES 'add files with funny names' "
git add -- 'tab embedded' 'newline git add -- 'tab embedded' 'newline
embedded' && embedded' &&
git commit -m 'add files with tabs and newlines' git commit -m 'add files with tabs and newlines'
else "
test_tabs=n
fi"

test "$test_tabs" = n && say 'Your filesystem does not allow tabs in filenames.'


# Determine rm behavior
# Later we will try removing an unremovable path to make sure # Later we will try removing an unremovable path to make sure
# git rm barfs, but if the test is run as root that cannot be # git rm barfs, but if the test is run as root that cannot be
# arranged. # arranged.
test_expect_success \ : >test-file
'Determine rm behavior' \ chmod a-w .
': >test-file rm -f test-file 2>/dev/null
chmod a-w . if test -f test-file
rm -f test-file then
test -f test-file && test_failed_remove=y test_set_prereq RO_DIR
chmod 775 . else
rm -f test-file' say 'skipping removal failure test (perhaps running as root?)'
fi
chmod 775 .
rm -f test-file


test_expect_success \ test_expect_success \
'Pre-check that foo exists and is in index before git rm foo' \ 'Pre-check that foo exists and is in index before git rm foo' \
@ -101,20 +107,16 @@ test_expect_success \
'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' \ 'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' \
'git rm -- -q' 'git rm -- -q'


test "$test_tabs" = y && test_expect_success \ test_expect_success FUNNYNAMES \
"Test that \"git rm -f\" succeeds with embedded space, tab, or newline characters." \ "Test that \"git rm -f\" succeeds with embedded space, tab, or newline characters." \
"git rm -f 'space embedded' 'tab embedded' 'newline "git rm -f 'space embedded' 'tab embedded' 'newline
embedded'" embedded'"


if test "$test_failed_remove" = y; then test_expect_success RO_DIR 'Test that "git rm -f" fails if its rm fails' '
chmod a-w . chmod a-w . &&
test_expect_success \ test_must_fail git rm -f baz &&
'Test that "git rm -f" fails if its rm fails' \ chmod 775 .
'test_must_fail git rm -f baz' '
chmod 775 .
else
say 'skipping removal failure test (perhaps running as root?)'
fi


test_expect_success \ test_expect_success \
'When the rm in "git rm -f" fails, it should not remove the file from the index' \ 'When the rm in "git rm -f" fails, it should not remove the file from the index' \

Loading…
Cancel
Save