From 1c5e94f459a0b7c23ef7e855441a65afdc4effab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Sun, 19 Aug 2018 23:57:25 +0200 Subject: tests: use 'test_must_be_empty' instead of 'test_cmp ' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- t/t3004-ls-files-basic.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 't/t3004-ls-files-basic.sh') diff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh index 9c7adbdbe1..9fd5a1f188 100755 --- a/t/t3004-ls-files-basic.sh +++ b/t/t3004-ls-files-basic.sh @@ -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' ' -- cgit v1.2.3