diff mbox series

[1/2] unwritable tests: assert exact error output

Message ID patch-1.2-a5ef8ea47f4-20211009T133354Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/2] unwritable tests: assert exact error output | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 9, 2021, 1:34 p.m. UTC
In preparation for fixing a regression where we started emitting some
of these error messages twice, let's assert what the output from "git
commit" and friends is now in the case of permission errors.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0004-unwritable.sh | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

Comments

Junio C Hamano Oct. 11, 2021, 8:50 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> In preparation for fixing a regression where we started emitting some
> of these error messages twice, let's assert what the output from "git
> commit" and friends is now in the case of permission errors.

Usually we frown upon expecting an exact error message, but I guess
that the nature of the bug this series tries to address justifies
it.

> -	test_must_fail git write-tree
> +
> +	cat >expect <<-\EOF &&
> +	error: insufficient permission for adding an object to repository database .git/objects
> +	fatal: git-write-tree: error building trees
> +	EOF
> +	test_must_fail git write-tree 2>actual &&
> +	test_cmp expect actual
>  '

OK.

>  test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
>  	test_when_finished "chmod 775 .git/objects .git/objects/??" &&
>  	chmod a-w .git/objects .git/objects/?? &&
> -	test_must_fail git commit -m second
> +
> +	cat >expect <<-\EOF &&
> +	error: insufficient permission for adding an object to repository database .git/objects
> +	error: insufficient permission for adding an object to repository database .git/objects
> +	error: Error building trees
> +	EOF

This is odd.  Shouldn't the test expect one message from write-tree
and be marked as expecting a failure until the bug gets fixed?

> +	test_must_fail git commit -m second 2>actual &&
> +	test_cmp expect actual
>  '
diff mbox series

Patch

diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh
index e3137d638ee..998c9d1be69 100755
--- a/t/t0004-unwritable.sh
+++ b/t/t0004-unwritable.sh
@@ -18,27 +18,55 @@  test_expect_success setup '
 test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
 	test_when_finished "chmod 775 .git/objects .git/objects/??" &&
 	chmod a-w .git/objects .git/objects/?? &&
-	test_must_fail git write-tree
+
+	cat >expect <<-\EOF &&
+	error: insufficient permission for adding an object to repository database .git/objects
+	fatal: git-write-tree: error building trees
+	EOF
+	test_must_fail git write-tree 2>actual &&
+	test_cmp expect actual
 '
 
 test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
 	test_when_finished "chmod 775 .git/objects .git/objects/??" &&
 	chmod a-w .git/objects .git/objects/?? &&
-	test_must_fail git commit -m second
+
+	cat >expect <<-\EOF &&
+	error: insufficient permission for adding an object to repository database .git/objects
+	error: insufficient permission for adding an object to repository database .git/objects
+	error: Error building trees
+	EOF
+	test_must_fail git commit -m second 2>actual &&
+	test_cmp expect actual
 '
 
 test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
 	test_when_finished "chmod 775 .git/objects .git/objects/??" &&
 	echo 6O >file &&
 	chmod a-w .git/objects .git/objects/?? &&
-	test_must_fail git update-index file
+
+	cat >expect <<-\EOF &&
+	error: insufficient permission for adding an object to repository database .git/objects
+	error: file: failed to insert into database
+	fatal: Unable to process path file
+	EOF
+	test_must_fail git update-index file 2>actual &&
+	test_cmp expect actual
 '
 
 test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
 	test_when_finished "chmod 775 .git/objects .git/objects/??" &&
 	echo b >file &&
 	chmod a-w .git/objects .git/objects/?? &&
-	test_must_fail git add file
+
+	cat >expect <<-\EOF &&
+	error: insufficient permission for adding an object to repository database .git/objects
+	error: file: failed to insert into database
+	error: unable to index file '\''file'\''
+	fatal: updating files failed
+	EOF
+	test_must_fail git add file 2>actual &&
+	test_cmp expect actual
 '
 
 test_done