mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-18 20:32:21 -05:00
Replace bare grep with test_grep in test assertions across the
suite, including sourced test helpers (lib-*.sh, *-tests.sh).
test_grep prints the contents of the file being searched on
failure, making debugging easier than a bare grep which fails
silently.
Only assertion-style greps are converted: grep used as a filter
in pipelines, command substitutions, conditionals, or with
redirected I/O is left as-is with a "# lint-ok" annotation.
Existing '! test_grep' calls are rewritten to 'test_grep !' so
that the diagnostic output is preserved on failure.
The conversion was generated using a grep-assertion linter
(greplint.pl, added in the following commit) to identify bare
grep calls at command position. To reproduce:
# Step 1: mark bare greps that should not be converted
sed -i '/! grep "$m" \.git\/packed-refs/s/$/ # lint-ok: file may not exist (reftable)/' \
t/t1400-update-ref.sh
sed -i '/! grep dirty file3 &&/{/lint-ok/!s/$/ # lint-ok: file may not exist after --quit/}' \
t/t3420-rebase-autostash.sh
sed -i '/grep -vf before commits\.raw/s/$/ # lint-ok: data filter/' \
t/t5326-multi-pack-bitmaps.sh
sed -i '/! grep $d shallow-client\/\.git\/shallow/s/$/ # lint-ok: file may not exist after repack/' \
t/t5537-fetch-shallow.sh
sed -i '/grep -E "^\[0-9a-f\].*|| :/s/$/ # lint-ok: data filter/' \
t/t5702-protocol-v2.sh
sed -i '/! grep gitdir squatting-clone/s/$/ # lint-ok: file may not exist after failed clone/' \
t/t7450-bad-git-dotfiles.sh
# Step 2: reorder pre-existing '! test_grep' to 'test_grep !'
# (must come before steps 3-4 so greplint does not see them)
sed -i 's/! test_grep/test_grep !/' t/t0031-lockfile-pid.sh
sed -i 's/! test_grep/test_grep !/' t/t5300-pack-object.sh
sed -i 's/! test_grep/test_grep !/' t/t5319-multi-pack-index.sh
# Step 3: convert '! grep' -> 'test_grep !'
perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 |
while IFS=: read f l; do
sed -i "${l}s/! *grep/test_grep !/" "$f"
done
# Step 4: convert remaining 'grep' -> 'test_grep'
perl t/greplint.pl t/*.sh 2>&1 | cut -d: -f1,2 |
while IFS=: read f l; do
sed -i "${l}s/grep/test_grep/" "$f"
done
To verify, run: make -C t test-greplint
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
217 lines
6.1 KiB
Bash
Executable File
217 lines
6.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='git p4 metadata encoding
|
|
|
|
This test checks that the import process handles inconsistent text
|
|
encoding in p4 metadata (author names, commit messages, etc) without
|
|
failing, and produces maximally sane output in git.'
|
|
|
|
. ./lib-git-p4.sh
|
|
|
|
###############################
|
|
## SECTION REPEATED IN t9835 ##
|
|
###############################
|
|
|
|
EXTRA_PATH="$(pwd)/temp_python"
|
|
mkdir "$EXTRA_PATH"
|
|
PATH="$EXTRA_PATH:$PATH"
|
|
export PATH
|
|
|
|
# These tests are specific to Python 3. Write a custom script that executes
|
|
# git-p4 directly with the Python 3 interpreter to ensure that we use that
|
|
# version even if Git was compiled with Python 2.
|
|
test_lazy_prereq P4_PYTHON3 '
|
|
python_target_binary=$(which python3) &&
|
|
test -n "$python_target_binary" &&
|
|
write_script "$EXTRA_PATH"/git-p4-python3 <<-EOF &&
|
|
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
|
|
EOF
|
|
( git p4-python3 || true ) >err &&
|
|
test_grep "valid commands" err
|
|
'
|
|
|
|
if ! test_have_prereq P4_PYTHON3
|
|
then
|
|
skip_all="skipping python3 git p4 tests; python3 not available"
|
|
test_done
|
|
fi
|
|
|
|
remove_user_cache () {
|
|
rm "$HOME/.gitp4-usercache.txt" || true
|
|
}
|
|
|
|
test_expect_success 'start p4d' '
|
|
start_p4d
|
|
'
|
|
|
|
test_expect_success 'init depot' '
|
|
(
|
|
cd "$cli" &&
|
|
|
|
p4_add_user "utf8_author" "ǣuthor" &&
|
|
P4USER=utf8_author &&
|
|
touch file1 &&
|
|
p4 add file1 &&
|
|
p4 submit -d "first CL has some utf-8 tǣxt" &&
|
|
|
|
p4_add_user "latin1_author" "$(echo æuthor |
|
|
iconv -f utf8 -t latin1)" &&
|
|
P4USER=latin1_author &&
|
|
touch file2 &&
|
|
p4 add file2 &&
|
|
p4 submit -d "$(echo second CL has some latin-1 tæxt |
|
|
iconv -f utf8 -t latin1)" &&
|
|
|
|
p4_add_user "cp1252_author" "$(echo æuthœr |
|
|
iconv -f utf8 -t cp1252)" &&
|
|
P4USER=cp1252_author &&
|
|
touch file3 &&
|
|
p4 add file3 &&
|
|
p4 submit -d "$(echo third CL has sœme cp-1252 tæxt |
|
|
iconv -f utf8 -t cp1252)" &&
|
|
|
|
p4_add_user "cp850_author" "$(echo Åuthor |
|
|
iconv -f utf8 -t cp850)" &&
|
|
P4USER=cp850_author &&
|
|
touch file4 &&
|
|
p4 add file4 &&
|
|
p4 submit -d "$(echo fourth CL hÅs some cp850 text |
|
|
iconv -f utf8 -t cp850)"
|
|
)
|
|
'
|
|
|
|
test_expect_success 'clone non-utf8 repo with strict encoding' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4-python3 clone --dest="$git" //depot@all 2>err &&
|
|
test_grep "Decoding perforce metadata failed!" err
|
|
'
|
|
|
|
test_expect_success 'check utf-8 contents with passthrough strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=passthrough p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "some utf-8 tǣxt" actual &&
|
|
test_grep "ǣuthor" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=passthrough p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) &&
|
|
test_grep "$badly_encoded_in_git" actual &&
|
|
bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" &&
|
|
test_grep "$bad_author_in_git" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check utf-8 contents with fallback strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "some utf-8 tǣxt" actual &&
|
|
test_grep "ǣuthor" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check latin-1 contents with fallback strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "some latin-1 tæxt" actual &&
|
|
test_grep "æuthor" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check cp-1252 contents with fallback strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "sœme cp-1252 tæxt" actual &&
|
|
test_grep "æuthœr" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check cp850 contents parsed with correct fallback' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "hÅs some cp850 text" actual &&
|
|
test_grep "Åuthor" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "h%8Fs some cp850 text" actual &&
|
|
test_grep "%8Futhor" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$cli" &&
|
|
P4USER=cp1252_author &&
|
|
touch file10 &&
|
|
p4 add file10 &&
|
|
p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt |
|
|
iconv -f utf8 -t cp1252)"
|
|
) &&
|
|
(
|
|
cd "$git" &&
|
|
|
|
git p4-python3 sync --branch=master &&
|
|
|
|
git log p4/master >actual &&
|
|
test_grep "sœme more cp-1252 tæxt" actual &&
|
|
test_grep "æuthœr" actual
|
|
)
|
|
'
|
|
|
|
############################
|
|
## / END REPEATED SECTION ##
|
|
############################
|
|
|
|
|
|
test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' '
|
|
test_when_finished cleanup_git &&
|
|
test_when_finished remove_user_cache &&
|
|
git p4-python3 clone --dest="$git" //depot@all &&
|
|
(
|
|
cd "$git" &&
|
|
git log >actual &&
|
|
test_grep "sœme cp-1252 tæxt" actual &&
|
|
test_grep "æuthœr" actual
|
|
)
|
|
'
|
|
|
|
test_done
|