Skip to content

Commit 879ed75

Browse files
peffgitster
authored andcommitted
t: add tests for "git var"
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6991ce commit 879ed75

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

t/t0007-git-var.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
test_description='basic sanity checks for git var'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'get GIT_AUTHOR_IDENT' '
7+
test_tick &&
8+
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
9+
git var GIT_AUTHOR_IDENT >actual &&
10+
test_cmp expect actual
11+
'
12+
13+
test_expect_success 'get GIT_COMMITTER_IDENT' '
14+
test_tick &&
15+
echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
16+
git var GIT_COMMITTER_IDENT >actual &&
17+
test_cmp expect actual
18+
'
19+
20+
test_expect_success !AUTOIDENT 'requested identites are strict' '
21+
(
22+
sane_unset GIT_COMMITTER_NAME &&
23+
sane_unset GIT_COMMITTER_EMAIL &&
24+
test_must_fail git var GIT_COMMITTER_IDENT
25+
)
26+
'
27+
28+
# For git var -l, we check only a representative variable;
29+
# testing the whole output would make our test too brittle with
30+
# respect to unrelated changes in the test suite's environment.
31+
test_expect_success 'git var -l lists variables' '
32+
git var -l >actual &&
33+
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
34+
sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
35+
test_cmp expect actual.author
36+
'
37+
38+
test_expect_success 'git var -l lists config' '
39+
git var -l >actual &&
40+
echo false >expect &&
41+
sed -n s/core\\.bare=//p <actual >actual.bare &&
42+
test_cmp expect actual.bare
43+
'
44+
45+
test_expect_success 'listing and asking for variables are exclusive' '
46+
test_must_fail git var -l GIT_COMMITTER_IDENT
47+
'
48+
49+
test_done

0 commit comments

Comments
 (0)