t5520: replace $(cat ...) comparison with test_cmp

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Denton Liu
2019-11-12 15:08:12 -08:00
committed by Junio C Hamano
parent e959a18ee7
commit a1a64fdd0a

View File

@ -15,8 +15,10 @@ test_pull_autostash () {
git add new_file && git add new_file &&
git pull "$@" . copy && git pull "$@" . copy &&
test_cmp_rev HEAD^ copy && test_cmp_rev HEAD^ copy &&
test "$(cat new_file)" = dirty && echo dirty >expect &&
test "$(cat file)" = "modified again" test_cmp expect new_file &&
echo "modified again" >expect &&
test_cmp expect file
} }
test_pull_autostash_fail () { test_pull_autostash_fail () {
@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
echo updated >file && echo updated >file &&
git commit -a -m updated && git commit -a -m updated &&
git checkout copy && git checkout copy &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull && git pull &&
test "$(cat file)" = updated && echo updated >expect &&
test_cmp expect file &&
git reflog -1 >reflog.actual && git reflog -1 >reflog.actual &&
sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected && echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
git commit -a -m modified && git commit -a -m modified &&
git checkout copy && git checkout copy &&
git reset --hard HEAD^ && git reset --hard HEAD^ &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull . second && git pull . second &&
test "$(cat file)" = modified && echo modified >expect &&
test_cmp expect file &&
git reflog -1 >reflog.actual && git reflog -1 >reflog.actual &&
sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected && echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
test_expect_success 'fail if wildcard spec does not match any refs' ' test_expect_success 'fail if wildcard spec does not match any refs' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err && test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
test_i18ngrep "no candidates for merging" err && test_i18ngrep "no candidates for merging" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'fail if no branches specified with non-default remote' ' test_expect_success 'fail if no branches specified with non-default remote' '
@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
test_when_finished "git remote remove test_remote" && test_when_finished "git remote remove test_remote" &&
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_config branch.test.remote origin && test_config branch.test.remote origin &&
test_must_fail git pull test_remote 2>err && test_must_fail git pull test_remote 2>err &&
test_i18ngrep "specify a branch on the command line" err && test_i18ngrep "specify a branch on the command line" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'fail if not on a branch' ' test_expect_success 'fail if not on a branch' '
@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
test_when_finished "git remote remove origin" && test_when_finished "git remote remove origin" &&
git checkout HEAD^ && git checkout HEAD^ &&
test_when_finished "git checkout -f copy" && test_when_finished "git checkout -f copy" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "not currently on a branch" err && test_i18ngrep "not currently on a branch" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'fail if no configuration for current branch' ' test_expect_success 'fail if no configuration for current branch' '
@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote test_remote && test_config branch.test.remote test_remote &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "no tracking information" err && test_i18ngrep "no tracking information" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'pull --all: fail if no configuration for current branch' ' test_expect_success 'pull --all: fail if no configuration for current branch' '
@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote test_remote && test_config branch.test.remote test_remote &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull --all 2>err && test_must_fail git pull --all 2>err &&
test_i18ngrep "There is no tracking information" err && test_i18ngrep "There is no tracking information" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'fail if upstream branch does not exist' ' test_expect_success 'fail if upstream branch does not exist' '
@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote . && test_config branch.test.remote . &&
test_config branch.test.merge refs/heads/nonexisting && test_config branch.test.merge refs/heads/nonexisting &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "no such ref was fetched" err && test_i18ngrep "no such ref was fetched" err &&
test "$(cat file)" = file echo file >expect &&
test_cmp expect file
' '
test_expect_success 'fail if the index has unresolved entries' ' test_expect_success 'fail if the index has unresolved entries' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_commit modified2 file && test_commit modified2 file &&
git ls-files -u >unmerged && git ls-files -u >unmerged &&
test_must_be_empty unmerged && test_must_be_empty unmerged &&
@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
test_expect_success 'fast-forwards working tree if branch head is updated' ' test_expect_success 'fast-forwards working tree if branch head is updated' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull . second:third 2>err && git pull . second:third 2>err &&
test_i18ngrep "fetch updated the current branch head" err && test_i18ngrep "fetch updated the current branch head" err &&
test "$(cat file)" = modified && echo modified >expect &&
test_cmp expect file &&
test_cmp_rev third second test_cmp_rev third second
' '
test_expect_success 'fast-forward fails with conflicting work tree' ' test_expect_success 'fast-forward fails with conflicting work tree' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
echo conflict >file && echo conflict >file &&
test_must_fail git pull . second:third 2>err && test_must_fail git pull . second:third 2>err &&
test_i18ngrep "Cannot fast-forward your working tree" err && test_i18ngrep "Cannot fast-forward your working tree" err &&
test "$(cat file)" = conflict && echo conflict >expect &&
test_cmp expect file &&
test_cmp_rev third second test_cmp_rev third second
' '
@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
test_set_editor "$TRASH_DIRECTORY/fake-editor" && test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
test_must_fail git pull --rebase=interactive . copy && test_must_fail git pull --rebase=interactive . copy &&
test "I was here" = "$(cat fake.out)" echo "I was here" >expect &&
test_cmp expect fake.out
' '
test_expect_success 'pull --rebase=i' ' test_expect_success 'pull --rebase=i' '
@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
test_set_editor "$TRASH_DIRECTORY/fake-editor" && test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
test_must_fail git pull --rebase=i . copy && test_must_fail git pull --rebase=i . copy &&
test "I was here, too" = "$(cat fake.out)" echo "I was here, too" >expect &&
test_cmp expect fake.out
' '
test_expect_success 'pull.rebase=invalid fails' ' test_expect_success 'pull.rebase=invalid fails' '
@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
git commit -m to-rebase file2 && git commit -m to-rebase file2 &&
git tag to-rebase-orig && git tag to-rebase-orig &&
git pull --rebase me copy && git pull --rebase me copy &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success '--rebase -f with rebased upstream' ' test_expect_success '--rebase -f with rebased upstream' '
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git pull --rebase -f me copy && git pull --rebase -f me copy &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success '--rebase with rebased default upstream' ' test_expect_success '--rebase with rebased default upstream' '
@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
git checkout --track -b to-rebase2 me/copy && git checkout --track -b to-rebase2 me/copy &&
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git pull --rebase && git pull --rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success 'rebased upstream + fetch + pull --rebase' ' test_expect_success 'rebased upstream + fetch + pull --rebase' '
@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git fetch && git fetch &&
git pull --rebase && git pull --rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
test_expect_success 'git pull --rebase against local branch' ' test_expect_success 'git pull --rebase against local branch' '
git checkout -b copy2 to-rebase-orig && git checkout -b copy2 to-rebase-orig &&
git pull --rebase . to-rebase && git pull --rebase . to-rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_done test_done