tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
commit1c5e94f459a0b7c23ef7e855441a65afdc4effab
authorSZEDER Gábor <szeder.dev@gmail.com>
Sun, 19 Aug 2018 21:57:25 +0000 (19 23:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Aug 2018 18:48:36 +0000 (21 11:48 -0700)
treeaa11042b35029df758f45585b0d7aeb84efdd731
parentec21ac8c189537df815e49bdf8f08da927665cf2
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>
46 files changed:
t/t0001-init.sh
t/t0003-attributes.sh
t/t0030-stripspace.sh
t/t0040-parse-options.sh
t/t0061-run-command.sh
t/t1300-config.sh
t/t1410-reflog.sh
t/t1411-reflog-show.sh
t/t1450-fsck.sh
t/t1600-index.sh
t/t1700-split-index.sh
t/t2200-add-update.sh
t/t2203-add-intent.sh
t/t3001-ls-files-others-exclude.sh
t/t3004-ls-files-basic.sh
t/t3035-merge-sparse.sh
t/t3301-notes.sh
t/t3404-rebase-interactive.sh
t/t4015-diff-whitespace.sh
t/t4027-diff-submodule.sh
t/t4041-diff-submodule-option.sh
t/t4060-diff-submodule-option-diff-format.sh
t/t4132-apply-removal.sh
t/t4203-mailmap.sh
t/t4212-log-corrupt.sh
t/t4300-merge-tree.sh
t/t5304-prune.sh
t/t5314-pack-cycle-detection.sh
t/t5526-fetch-submodules.sh
t/t6112-rev-list-filters-objects.sh
t/t6120-describe.sh
t/t6130-pathspec-noglob.sh
t/t6200-fmt-merge-msg.sh
t/t7004-tag.sh
t/t7008-grep-binary.sh
t/t7064-wtstatus-pv2.sh
t/t7201-co.sh
t/t7400-submodule-basic.sh
t/t7501-commit.sh
t/t7600-merge.sh
t/t7610-mergetool.sh
t/t7810-grep.sh
t/t7811-grep-open.sh
t/t9011-svn-da.sh
t/t9200-git-cvsexportcommit.sh
t/t9903-bash-prompt.sh