pretty: update tests to use `test_config`
These tests use raw `git config` calls, which is an older style that can cause config to bleed between tests if not manually unset. `test_config` ensures that config is unset at the end of each test automatically. `test_config` is chosen over `git -c` since `test_config` still ends up calling `git config` which seems slightly more realistic to how pretty formats would be defined normally. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Brian Lyles <brianmlyles@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brian Lyles committed
Mar 25, 2024 at 02:25 UTC
2cd134f2c538a9cb7b0946ace6004489eba9535f
1 file changed
+14
-16
t/t4205-log-pretty-formats.sh
+14
-16
@@ -30,40 +30,38 @@ test_expect_success 'set up basic repos' '
30
>bar &&
31
git add foo &&
32
test_tick &&
33
- git config i18n.commitEncoding $test_encoding &&
33
+ test_config i18n.commitEncoding $test_encoding &&
34
commit_msg $test_encoding | git commit -F - &&
35
git add bar &&
36
test_tick &&
37
- git commit -m "add bar" &&
38
- git config --unset i18n.commitEncoding
37
+ git commit -m "add bar"
38
'
39
40
test_expect_success 'alias builtin format' '
41
git log --pretty=oneline >expected &&
43
- git config pretty.test-alias oneline &&
42
+ test_config pretty.test-alias oneline &&
43
git log --pretty=test-alias >actual &&
44
test_cmp expected actual
45
'
46
47
test_expect_success 'alias masking builtin format' '
48
git log --pretty=oneline >expected &&
50
- git config pretty.oneline "%H" &&
49
+ test_config pretty.oneline "%H" &&
50
git log --pretty=oneline >actual &&
51
test_cmp expected actual
52
'
53
54
test_expect_success 'alias user-defined format' '
55
git log --pretty="format:%h" >expected &&
57
- git config pretty.test-alias "format:%h" &&
56
+ test_config pretty.test-alias "format:%h" &&
57
git log --pretty=test-alias >actual &&
58
test_cmp expected actual
59
'
60
61
test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63
- git config i18n.logOutputEncoding $test_encoding &&
62
+ test_config i18n.logOutputEncoding $test_encoding &&
63
git log --oneline >expected-s &&
64
git log --pretty="tformat:%h %s" >actual-s &&
66
- git config --unset i18n.logOutputEncoding &&
65
test_cmp expected-s actual-s
66
'
67
@@ -75,34 +73,34 @@ test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
73
74
test_expect_success 'alias user-defined tformat' '
75
git log --pretty="tformat:%h" >expected &&
78
- git config pretty.test-alias "tformat:%h" &&
76
+ test_config pretty.test-alias "tformat:%h" &&
77
git log --pretty=test-alias >actual &&
78
test_cmp expected actual
79
'
80
81
test_expect_success 'alias non-existent format' '
84
- git config pretty.test-alias format-that-will-never-exist &&
82
+ test_config pretty.test-alias format-that-will-never-exist &&
83
test_must_fail git log --pretty=test-alias
84
'
85
86
test_expect_success 'alias of an alias' '
87
git log --pretty="tformat:%h" >expected &&
90
- git config pretty.test-foo "tformat:%h" &&
91
- git config pretty.test-bar test-foo &&
88
+ test_config pretty.test-foo "tformat:%h" &&
89
+ test_config pretty.test-bar test-foo &&
90
git log --pretty=test-bar >actual && test_cmp expected actual
91
'
92
93
test_expect_success 'alias masking an alias' '
94
git log --pretty=format:"Two %H" >expected &&
97
- git config pretty.duplicate "format:One %H" &&
98
- git config --add pretty.duplicate "format:Two %H" &&
95
+ test_config pretty.duplicate "format:One %H" &&
96
+ test_config pretty.duplicate "format:Two %H" --add &&
97
git log --pretty=duplicate >actual &&
98
test_cmp expected actual
99
'
100
101
test_expect_success 'alias loop' '
104
- git config pretty.test-foo test-bar &&
105
- git config pretty.test-bar test-foo &&
102
+ test_config pretty.test-foo test-bar &&
103
+ test_config pretty.test-bar test-foo &&
104
test_must_fail git log --pretty=test-foo
105
'
106