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

[PATCH 5/5] t: add tests for "git var"

From
Jeff King <peff@peff.net>
Date
Nov 28, 2012, 18:26 UTC
Message-ID
<20121128182643.GE17122@sigill.intra.peff.net>
In-Reply-To
<20121128182534.GA21020@sigill.intra.peff.net>

We do not currently have any explicit tests for "git var" at all (though we do exercise it to some degree as a part of other tests). Let's add a few basic sanity checks.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t0007-git-var.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100755 t/t0007-git-var.sh
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
new file mode 100755
index 0000000..5868a87
--- /dev/null
+++ b/t/t0007-git-var.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+test_description='basic sanity checks for git var'
+. ./test-lib.sh
+
+test_expect_success 'get GIT_AUTHOR_IDENT' '
+	test_tick &&
+	echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
+	git var GIT_AUTHOR_IDENT >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'get GIT_COMMITTER_IDENT' '
+	test_tick &&
+	echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
+	git var GIT_COMMITTER_IDENT >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success !AUTOIDENT 'requested identites are strict' '
+	(
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		test_must_fail git var GIT_COMMITTER_IDENT
+	)
+'
+
+# For git var -l, we check only a representative variable;
+# testing the whole output would make our test too brittle with
+# respect to unrelated changes in the test suite's environment.
+test_expect_success 'git var -l lists variables' '
+	git var -l >actual &&
+	echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
+	sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
+	test_cmp expect actual.author
+'
+
+test_expect_success 'git var -l lists config' '
+	git var -l >actual &&
+	echo false >expect &&
+	sed -n s/core\\.bare=//p <actual >actual.bare &&
+	test_cmp expect actual.bare
+'
+
+test_expect_success 'listing and asking for variables are exclusive' '
+	test_must_fail git var -l GIT_COMMITTER_IDENT
+'
+
+test_done
-- 
1.8.0.207.gdf2154c
Previous: Jeff KingNext: Jeff King
Message 6 of 12 in “jk/send-email-sender-prompt loose ends”
  1. 0/5 jk/send-email-sender-prompt loose endsJeff King, Nov 28, 2012
  2. 1/5 test-lib: allow negation of prerequisitesJeff King, Nov 28, 2012
  3. 2/5 t7502: factor out autoident prerequisiteJeff King, Nov 28, 2012
  4. 3/5 ident: make user_ident_explicitly_given staticJeff King, Nov 28, 2012
  5. 4/5 ident: keep separate "explicit" flags for author and committerJeff King, Nov 28, 2012
  6. 5/5 t: add tests for "git var"Jeff King, Nov 28, 2012
  7. 6/5 t9001: check send-email behavior with implicit senderJeff King, Nov 28, 2012
  8. Junio C HamanoNov 28, 2012
  9. Jeff KingNov 28, 2012
  10. Jeff KingNov 28, 2012
  11. Junio C HamanoNov 28, 2012
  12. Felipe ContrerasNov 28, 2012

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.