From a5db0b77b916014e732155d116575bdffbcbe79b Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sun, 21 Oct 2018 16:02:27 +0200 Subject: t1300: extract and use test_cmp_config() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In many config-related tests it's common to check if a config variable has expected value and we want to print the differences when the test fails. Doing it the normal way is three lines of shell code. Let's add a function do to all this (and a little more). This function has uses outside t1300 as well but I'm not going to convert them all. And it will be used in the next commit where per-worktree config feature is introduced. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't/test-lib-functions.sh') diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 78d8c3783b..d158c8d0bf 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -747,6 +747,29 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# Check that the given config key has the expected value. +# +# test_cmp_config [-C ] +# [...] +# +# for example to check that the value of core.bar is foo +# +# test_cmp_config foo core.bar +# +test_cmp_config() { + local GD && + if test "$1" = "-C" + then + shift && + GD="-C $1" && + shift + fi && + printf "%s\n" "$1" >expect.config && + shift && + git $GD config "$@" >actual.config && + test_cmp expect.config actual.config +} + # test_cmp_bin - helper to compare binary files test_cmp_bin() { -- cgit v1.3-5-g9baa