git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] tests: use 'test_must_be_empty' instead of 'test ! -s'

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Aug 19, 2018, 21:57 UTC
Message-ID
<20180819215725.29001-3-szeder.dev@gmail.com>
In-Reply-To
<20180819215725.29001-1-szeder.dev@gmail.com>

Using 'test_must_be_empty' is preferable to 'test ! -s', because it gives a helpful error message if the given file is unexpectedly no empty, while the latter remains completely silent. Furthermore, it also catches cases when the given file unexpectedly does not exist at all.

This patch was created by:
  sed -i -e 's/test ! -s/test_must_be_empty/' t[0-9]*.sh
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 t/t4201-shortlog.sh         | 2 +-
 t/t4211-line-log.sh         | 2 +-
 t/t8010-cat-file-filters.sh | 2 +-
 t/t9802-git-p4-filetype.sh  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index 58c2773676..d3a7ce6bbb 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -192,7 +192,7 @@ test_expect_success 'shortlog with revision pseudo options' '
 
 test_expect_success 'shortlog with --output=<file>' '
 	git shortlog --output=shortlog -1 master >output &&
-	test ! -s output &&
+	test_must_be_empty output &&
 	test_line_count = 3 shortlog
 '
 
diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh
index d0377fae5c..6e378b23c7 100755
--- a/t/t4211-line-log.sh
+++ b/t/t4211-line-log.sh
@@ -102,7 +102,7 @@ test_expect_success '-L with --first-parent and a merge' '
 test_expect_success '-L with --output' '
 	git checkout parallel-change &&
 	git log --output=log -L :main:b.c >output &&
-	test ! -s output &&
+	test_must_be_empty output &&
 	test_line_count = 70 log
 '
 
diff --git a/t/t8010-cat-file-filters.sh b/t/t8010-cat-file-filters.sh
index 0f86c19174..31de4b64dc 100755
--- a/t/t8010-cat-file-filters.sh
+++ b/t/t8010-cat-file-filters.sh
@@ -47,7 +47,7 @@ test_expect_success 'cat-file --textconv --path=<path> works' '
 test_expect_success '--path=<path> complains without --textconv/--filters' '
 	sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
 	test_must_fail git cat-file --path=hello.txt blob $sha1 >actual 2>err &&
-	test ! -s actual &&
+	test_must_be_empty actual &&
 	grep "path.*needs.*filters" err
 '
 
diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh
index 1fc9b33aeb..9978352d78 100755
--- a/t/t9802-git-p4-filetype.sh
+++ b/t/t9802-git-p4-filetype.sh
@@ -310,7 +310,7 @@ test_expect_success SYMLINKS 'empty symlink target' '
 		# p4 to sync here will make it generate errors.
 		cd "$cli" &&
 		p4 print -q //depot/empty-symlink#2 >out &&
-		test ! -s out
+		test_must_be_empty out
 	) &&
 	test_when_finished cleanup_git &&
 
-- 
2.18.0.903.gab616d7dc6
Previous: SZEDER GáborNext: SZEDER Gábor
Message 2 of 6 in “tests: make more use of 'test_must_be_empty'”
  1. 0/4 tests: make more use of 'test_must_be_empty'SZEDER Gábor, Aug 19, 2018
  2. 2/4 tests: use 'test_must_be_empty' instead of 'test ! -s'SZEDER Gábor, Aug 19, 2018
  3. 1/4 tests: use 'test_must_be_empty' instead of '! test -s'SZEDER Gábor, Aug 19, 2018
  4. 3/4 tests: use 'test_must_be_empty' instead of 'test_cmp /dev/null <out>'SZEDER Gábor, Aug 19, 2018
  5. 4/4 tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'SZEDER Gábor, Aug 19, 2018
  6. Matthew DeVoreAug 22, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.