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

[PATCH 2/2] Better tests for error cases

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 11, 2014, 14:27 UTC
Message-ID
<1405088833-5817-2-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1405088833-5817-1-git-send-email-Matthieu.Moy@imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
Consider squashing this into PATCH 2/2
Probably not sufficient.
 t/t1308-config-set.sh | 22 ++++++++++++++++++++++
 test-config.c         |  8 ++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index 87a29f1..f1e9e76 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -167,4 +167,26 @@ test_expect_success 'find value_list for a key from a configset' '
 	test_cmp expect actual
 '
 
+test_expect_success 'proper error on non-existant files' '
+	echo "Error reading configuration file non-existant-file." >expect &&
+	test_must_fail test-config configset_get_value foo.bar non-existant-file 2>actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'proper error on error in default config files' '
+	cp .git/config .git/config.old &&
+	test_when_finished "mv .git/config.old .git/config" &&
+	echo "[" >> .git/config &&
+	echo "fatal: bad config file line 35 in .git/config" >expect &&
+	test_must_fail test-config get_value foo.bar 2>actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'proper error on error in custom config files' '
+	echo "[" >> syntax-error &&
+	echo "fatal: bad config file line 1 in syntax-error" >expect &&
+	test_must_fail test-config configset_get_value foo.bar syntax-error 2>actual &&
+	test_cmp expect actual
+'
+
 test_done
diff --git a/test-config.c b/test-config.c
index 07b61ef..49f8cd7 100644
--- a/test-config.c
+++ b/test-config.c
@@ -86,8 +86,10 @@ int main(int argc, char **argv)
 		}
 	} else if (!strcmp(argv[1], "configset_get_value")) {
 		for (i = 3; i < argc; i++) {
-			if (git_configset_add_file(&cs, argv[i]))
+			if (git_configset_add_file(&cs, argv[i])) {
+				fprintf(stderr, "Error reading configuration file %s.\n", argv[i]);
 				goto exit2;
+			}
 		}
 		if (!git_configset_get_value(&cs, argv[2], &v)) {
 			if (!v)
@@ -101,8 +103,10 @@ int main(int argc, char **argv)
 		}
 	} else if (!strcmp(argv[1], "configset_get_value_multi")) {
 		for (i = 3; i < argc; i++) {
-			if (git_configset_add_file(&cs, argv[i]))
+			if (git_configset_add_file(&cs, argv[i])) {
+				fprintf(stderr, "Error reading configuration file %s.\n", argv[i]);
 				goto exit2;
+			}
 		}
 		strptr = git_configset_get_value_multi(&cs, argv[2]);
 		if (strptr) {
-- 
2.0.0.262.gdafc651
Previous: Matthieu MoyNext: Junio C Hamano
Message 12 of 14 in “git config cache & special querying api utilizing the cache”
  1. 0/3 git config cache & special querying api utilizing the cacheTanay Abhra, Jul 11, 2014
  2. 1/2 add `config_set` API for caching config-like filesTanay Abhra, Jul 11, 2014
  3. Matthieu MoyJul 11, 2014
  4. Tanay AbhraJul 11, 2014
  5. Matthieu MoyJul 11, 2014
  6. Tanay AbhraJul 15, 2014
  7. Matthieu MoyJul 15, 2014
  8. Junio C HamanoJul 11, 2014
  9. 2/2 test-config: add tests for the config_set APITanay Abhra, Jul 11, 2014
  10. Matthieu MoyJul 11, 2014
  11. 1/2 Call configset_clearMatthieu Moy, Jul 11, 2014
  12. 2/2 Better tests for error casesMatthieu Moy, Jul 11, 2014
  13. Junio C HamanoJul 11, 2014
  14. Tanay AbhraJul 15, 2014

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.