tests: don't lose "git" exit codes in "! ( git ... | grep )"

Change tests that would lose the "git" exit code via a negation
pattern to:

- In the case of "t0055-beyond-symlinks.sh" compare against the
  expected output instead.

  We could use the same pattern as in the "t3700-add.sh" below, doing
  so would have the advantage that if we added an earlier test we
  wouldn't need to adjust the "expect" output.

  But as "t0055-beyond-symlinks.sh" is a small and focused test (less
  than 40 lines in total) let's use "test_cmp" instead.

- For "t3700-add.sh" use "sed -n" to print the expected "bad" part,
  and use "test_must_be_empty" to assert that it's not there. If we used
  "grep" we'd get a non-zero exit code.

  We could use "test_expect_code 1 grep", but this is more consistent
  with existing patterns in the test suite.

  We can also remove a repeated invocation of "git ls-files" for the
  last test that's being modified in that file, and search the
  existing "files" output instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2023-02-06 23:44:32 +01:00 коммит произвёл Junio C Hamano
Родитель 0cd1a8818d
Коммит c7e03b4e39
2 изменённых файлов: 25 добавлений и 7 удалений

Просмотреть файл

@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
test_must_fail git update-index --add c/d &&
! ( git ls-files | grep c/d )
cat >expect <<-\EOF &&
a
b/d
EOF
git ls-files >actual &&
test_cmp expect actual
'
test_expect_success SYMLINKS 'add beyond symlinks' '
test_must_fail git add c/d &&
! ( git ls-files | grep c/d )
cat >expect <<-\EOF &&
a
b/d
EOF
git ls-files >actual &&
test_cmp expect actual
'
test_done

Просмотреть файл

@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' '
test_expect_success '.gitignore is honored' '
git add . &&
! (git ls-files | grep "\\.ig")
git ls-files >files &&
sed -n "/\\.ig/p" <files >actual &&
test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones without -f' '
test_must_fail git add a.?? &&
! (git ls-files | grep "\\.ig")
git ls-files >files &&
sed -n "/\\.ig/p" <files >actual &&
test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones without -f' '
test_must_fail git add d.?? &&
! (git ls-files | grep "\\.ig")
git ls-files >files &&
sed -n "/\\.ig/p" <files >actual &&
test_must_be_empty actual
'
test_expect_success 'error out when attempting to add ignored ones but add others' '
touch a.if &&
test_must_fail git add a.?? &&
! (git ls-files | grep "\\.ig") &&
(git ls-files | grep a.if)
git ls-files >files &&
sed -n "/\\.ig/p" <files >actual &&
test_must_be_empty actual &&
grep a.if files
'
test_expect_success 'add ignored ones with -f' '