Skip to content
Snippets Groups Projects
Commit 1c5e94f4 authored by SZEDER Gábor's avatar SZEDER Gábor Committed by Junio C Hamano
Browse files

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: default avatarSZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent ec21ac8c
No related branches found
No related tags found
No related merge requests found
Showing
with 41 additions and 73 deletions
Loading
Loading
@@ -167,9 +167,8 @@ test_expect_success 'reinit' '
) &&
test_i18ngrep "Initialized empty" again/out1 &&
test_i18ngrep "Reinitialized existing" again/out2 &&
>again/empty &&
test_i18ncmp again/empty again/err1 &&
test_i18ncmp again/empty again/err2
test_must_be_empty again/err1 &&
test_must_be_empty again/err2
'
 
test_expect_success 'init with --template' '
Loading
Loading
Loading
Loading
@@ -208,9 +208,8 @@ test_expect_success 'attribute test: --all option' '
'
 
test_expect_success 'attribute test: --cached option' '
: >empty &&
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
test_cmp empty actual &&
test_must_be_empty actual &&
git add .gitattributes a/.gitattributes a/b/.gitattributes &&
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
test_cmp specified-all actual
Loading
Loading
Loading
Loading
@@ -320,22 +320,20 @@ test_expect_success \
 
test_expect_success \
'spaces with newline at end should be replaced with empty string' '
printf "" >expect &&
echo | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
echo "$sss" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
echo "$sss$sss" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
echo "$sss$sss$sss" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
echo "$sss$sss$sss$sss" | git stripspace >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_expect_success \
Loading
Loading
@@ -349,19 +347,17 @@ test_expect_success \
 
test_expect_success \
'spaces without newline at end should be replaced with empty string' '
printf "" >expect &&
printf "" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
printf "$sss$sss" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
printf "$sss$sss$sss" | git stripspace >actual &&
test_cmp expect actual &&
test_must_be_empty actual &&
 
printf "$sss$sss$sss$sss" | git stripspace >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_expect_success \
Loading
Loading
Loading
Loading
@@ -286,11 +286,9 @@ test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
test_cmp expect output
'
 
>expect
test_expect_success 'OPT_CALLBACK() and callback errors work' '
test_must_fail test-parse-options --no-length >output 2>output.err &&
test_i18ncmp expect output &&
test_must_be_empty output &&
test_must_be_empty output.err
'
 
Loading
Loading
Loading
Loading
@@ -11,7 +11,6 @@ cat >hello-script <<-EOF
#!$SHELL_PATH
cat hello-script
EOF
>empty
 
test_expect_success 'start_command reports ENOENT' '
test-tool run-command start-command-ENOENT ./does-not-exist
Loading
Loading
@@ -23,7 +22,7 @@ test_expect_success 'run_command can run a command' '
test-tool run-command run-command ./hello.sh >actual 2>err &&
 
test_cmp hello-script actual &&
test_cmp empty err
test_must_be_empty err
'
 
test_expect_success !MINGW 'run_command can run a script without a #! line' '
Loading
Loading
@@ -34,7 +33,7 @@ test_expect_success !MINGW 'run_command can run a script without a #! line' '
test-tool run-command run-command ./hello >actual 2>err &&
 
test_cmp hello-script actual &&
test_cmp empty err
test_must_be_empty err
'
 
test_expect_success 'run_command does not try to execute a directory' '
Loading
Loading
@@ -47,7 +46,7 @@ test_expect_success 'run_command does not try to execute a directory' '
PATH=$PWD/bin1:$PWD/bin2:$PATH \
test-tool run-command run-command greet >actual 2>err &&
test_cmp bin2/greet actual &&
test_cmp empty err
test_must_be_empty err
'
 
test_expect_success POSIXPERM 'run_command passes over non-executable file' '
Loading
Loading
@@ -64,7 +63,7 @@ test_expect_success POSIXPERM 'run_command passes over non-executable file' '
PATH=$PWD/bin1:$PWD/bin2:$PATH \
test-tool run-command run-command greet >actual 2>err &&
test_cmp bin2/greet actual &&
test_cmp empty err
test_must_be_empty err
'
 
test_expect_success POSIXPERM 'run_command reports EACCES' '
Loading
Loading
Loading
Loading
@@ -346,12 +346,9 @@ test_expect_success 'working --list' '
git config --list > output &&
test_cmp expect output
'
cat > expect << EOF
EOF
test_expect_success '--list without repo produces empty output' '
git --git-dir=nonexistent config --list >output &&
test_cmp expect output
test_must_be_empty output
'
 
cat > expect << EOF
Loading
Loading
Loading
Loading
@@ -290,9 +290,8 @@ test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
# same as before, but we only create a reflog for "one" if
# it already exists, which it does not
git -c core.logallrefupdates=false branch one master &&
: >expect &&
git log -g --format="%gd %gs" one >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
# Triggering the bug detected by this test requires a newline to fall
Loading
Loading
Loading
Loading
@@ -136,13 +136,12 @@ test_expect_success '--date magic does not override explicit @{0} syntax' '
test_cmp expect actual
'
 
: >expect
test_expect_success 'empty reflog file' '
git branch empty &&
git reflog expire --expire=all refs/heads/empty &&
 
git log -g empty >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
# This guards against the alternative of showing the diffs vs. the
Loading
Loading
Loading
Loading
@@ -16,8 +16,7 @@ test_expect_success setup '
git checkout HEAD^0 &&
test_commit B fileB two &&
git tag -d A B &&
git reflog expire --expire=now --all &&
>empty
git reflog expire --expire=now --all
'
 
test_expect_success 'loose objects borrowed from alternate are not missing' '
Loading
Loading
@@ -29,12 +28,12 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
test_commit C fileC one &&
git fsck --no-dangling >../actual 2>&1
) &&
test_cmp empty actual
test_must_be_empty actual
'
 
test_expect_success 'HEAD is part of refs, valid objects appear valid' '
git fsck >actual 2>&1 &&
test_cmp empty actual
test_must_be_empty actual
'
 
# Corruption tests follow. Make sure to remove all traces of the
Loading
Loading
@@ -346,12 +345,12 @@ test_expect_success 'tag with NUL in header' '
 
test_expect_success 'cleaned up' '
git fsck >actual 2>&1 &&
test_cmp empty actual
test_must_be_empty actual
'
 
test_expect_success 'rev-list --verify-objects' '
git rev-list --verify-objects --all >/dev/null 2>out &&
test_cmp empty out
test_must_be_empty out
'
 
test_expect_success 'rev-list --verify-objects with bad sha1' '
Loading
Loading
Loading
Loading
@@ -41,8 +41,7 @@ test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index'
GIT_INDEX_VERSION=1 &&
export GIT_INDEX_VERSION &&
git add a 2>actual.err &&
>expect.err &&
test_i18ncmp expect.err actual.err
test_must_be_empty actual.err
)
'
 
Loading
Loading
Loading
Loading
@@ -143,9 +143,7 @@ test_expect_success 'remove file not in base index' '
test_expect_success 'remove file in base index' '
git update-index --force-remove one &&
git ls-files --stage >ls-files.actual &&
cat >ls-files.expect <<-EOF &&
EOF
test_cmp ls-files.expect ls-files.actual &&
test_must_be_empty ls-files.actual &&
 
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
cat >expect <<-EOF &&
Loading
Loading
Loading
Loading
@@ -88,9 +88,8 @@ test_expect_success 'non-qualified update in subdir updates from the root' '
echo even more >>sub2 &&
git add -u
) &&
: >expect &&
git diff-files --name-only >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_expect_success 'replace a file with a symlink' '
Loading
Loading
Loading
Loading
@@ -195,8 +195,7 @@ test_expect_success 'rename detection finds the right names' '
test_cmp expected.4 actual.4 &&
 
git diff --cached --stat >actual.5 &&
: >expected.5 &&
test_cmp expected.5 actual.5
test_must_be_empty actual.5
 
)
'
Loading
Loading
@@ -241,8 +240,7 @@ test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '
echo " create mode 100644 new-ita" >expected &&
test_cmp expected actual &&
git diff --cached --summary >actual2 &&
: >expected2 &&
test_cmp expected2 actual2
test_must_be_empty actual2
'
 
 
Loading
Loading
Loading
Loading
@@ -277,9 +277,8 @@ test_expect_success 'hide empty ignored sub-directory with --no-empty-directory'
'
 
test_expect_success 'pattern matches prefix completely' '
: >expect &&
git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_expect_success 'ls-files with "**" patterns' '
Loading
Loading
@@ -295,9 +294,8 @@ EOF
 
 
test_expect_success 'ls-files with "**" patterns and no slashes' '
: >expect &&
git ls-files -o -i --exclude "one**a.1" >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_done
Loading
Loading
@@ -8,16 +8,14 @@ command-line arguments.
 
. ./test-lib.sh
 
>empty
test_expect_success 'ls-files in empty repository' '
git ls-files >actual &&
test_cmp empty actual
test_must_be_empty actual
'
 
test_expect_success 'ls-files with nonexistent path' '
git ls-files doesnotexist >actual &&
test_cmp empty actual
test_must_be_empty actual
'
 
test_expect_success 'ls-files with nonsense option' '
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@ test_commit_this () {
}
 
test_expect_success 'setup' '
: >empty &&
test_file checked-out init &&
test_file modify_delete modify_delete_init &&
test_commit_this init &&
Loading
Loading
@@ -38,7 +37,7 @@ test_expect_success 'reset --hard works after the conflict' '
 
test_expect_success 'is reset properly' '
git status --porcelain -- modify_delete >out &&
test_cmp empty out &&
test_must_be_empty out &&
test_path_is_missing modify_delete
'
 
Loading
Loading
@@ -52,7 +51,7 @@ test_expect_success 'Merge abort works after the conflict' '
 
test_expect_success 'is aborted properly' '
git status --porcelain -- modify_delete >out &&
test_cmp empty out &&
test_must_be_empty out &&
test_path_is_missing modify_delete
'
 
Loading
Loading
Loading
Loading
@@ -481,10 +481,8 @@ test_expect_success 'list specific note with "git notes list <object>"' '
'
 
test_expect_success 'listing non-existing notes fails' '
cat >expect <<-EOF &&
EOF
test_must_fail git notes list HEAD >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
test_expect_success 'append to existing note with "git notes append"' '
Loading
Loading
Loading
Loading
@@ -787,16 +787,15 @@ test_expect_success 'always cherry-pick with --no-ff' '
git tag original-no-ff-branch &&
set_fake_editor &&
git rebase -i --no-ff A &&
touch empty &&
for p in 0 1 2
do
test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
git diff HEAD~$p original-no-ff-branch~$p > out &&
test_cmp empty out
test_must_be_empty out
done &&
test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
git diff HEAD~3 original-no-ff-branch~3 > out &&
test_cmp empty out
test_must_be_empty out
'
 
test_expect_success 'set up commits with funny messages' '
Loading
Loading
Loading
Loading
@@ -776,8 +776,6 @@ test_expect_success 'checkdiff allows new blank lines' '
git diff --check
'
 
cat <<EOF >expect
EOF
test_expect_success 'whitespace-only changes not reported' '
git reset --hard &&
echo >x "hello world" &&
Loading
Loading
@@ -785,7 +783,7 @@ test_expect_success 'whitespace-only changes not reported' '
git commit -m "hello 1" &&
echo >x "hello world" &&
git diff -b >actual &&
test_cmp expect actual
test_must_be_empty actual
'
 
cat <<EOF >expect
Loading
Loading
Loading
Loading
@@ -239,10 +239,9 @@ test_expect_success 'git diff between submodule commits [.gitmodules]' '
'
 
test_expect_success 'git diff (empty submodule dir)' '
: >empty &&
rm -rf sub/* sub/.git &&
git diff > actual.empty &&
test_cmp empty actual.empty
test_must_be_empty actual.empty
'
 
test_expect_success 'conflicted submodule setup' '
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment