2010-10-22 10:48:14 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='basic ls-files tests
|
|
|
|
|
|
|
|
This test runs git ls-files with various unusual or malformed
|
|
|
|
command-line arguments.
|
|
|
|
'
|
|
|
|
|
2021-10-12 16:56:42 +03:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2010-10-22 10:48:14 +04:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'ls-files in empty repository' '
|
|
|
|
git ls-files >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-20 00:57:25 +03:00
|
|
|
test_must_be_empty actual
|
2010-10-22 10:48:14 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ls-files with nonexistent path' '
|
|
|
|
git ls-files doesnotexist >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-20 00:57:25 +03:00
|
|
|
test_must_be_empty actual
|
2010-10-22 10:48:14 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ls-files with nonsense option' '
|
|
|
|
test_expect_code 129 git ls-files --nonsense 2>actual &&
|
2012-08-27 09:36:55 +04:00
|
|
|
test_i18ngrep "[Uu]sage: git ls-files" actual
|
2010-10-22 10:48:14 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'ls-files -h in corrupt repository' '
|
|
|
|
mkdir broken &&
|
|
|
|
(
|
|
|
|
cd broken &&
|
|
|
|
git init &&
|
|
|
|
>.git/index &&
|
|
|
|
test_expect_code 129 git ls-files -h >usage 2>&1
|
|
|
|
) &&
|
2012-08-27 09:36:55 +04:00
|
|
|
test_i18ngrep "[Uu]sage: git ls-files " broken/usage
|
2010-10-22 10:48:14 +04:00
|
|
|
'
|
|
|
|
|
2014-02-04 18:25:20 +04:00
|
|
|
test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' '
|
2014-02-04 18:25:15 +04:00
|
|
|
mkdir subs &&
|
|
|
|
ln -s nosuch link &&
|
|
|
|
ln -s ../nosuch subs/link &&
|
|
|
|
git add link subs/link &&
|
|
|
|
git ls-files -s link subs/link >expect &&
|
|
|
|
git ls-files -s "$(pwd)/link" "$(pwd)/subs/link" >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
(
|
|
|
|
cd subs &&
|
|
|
|
git ls-files -s link >../expect &&
|
|
|
|
git ls-files -s "$(pwd)/link" >../actual
|
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-10-22 10:48:14 +04:00
|
|
|
test_done
|