Skip to content

Commit 57b6dc7

Browse files
rscharfegitster
authored andcommitted
t4209: factor out helper function test_log()
Twelve tests in t4209 follow the same simple pattern for description, git log call and checking. Extract that shared logic into a helper function named test_log. Test specifications become a lot more compact, new tests can be added more easily. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0f7c7c commit 57b6dc7

File tree

1 file changed

+42
-58
lines changed

1 file changed

+42
-58
lines changed

t/t4209-log-pickaxe.sh

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@
33
test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
44
. ./test-lib.sh
55

6+
test_log () {
7+
expect=$1
8+
kind=$2
9+
needle=$3
10+
shift 3
11+
rest=$@
12+
13+
case $kind in
14+
--*)
15+
opt=$kind=$needle
16+
;;
17+
*)
18+
opt=$kind$needle
19+
;;
20+
esac
21+
case $expect in
22+
expect_nomatch)
23+
match=nomatch
24+
;;
25+
*)
26+
match=match
27+
;;
28+
esac
29+
30+
test_expect_success "log $kind${rest:+ $rest} ($match)" "
31+
git log $rest $opt --format=%H >actual &&
32+
test_cmp $expect actual
33+
"
34+
}
35+
636
test_expect_success setup '
737
>expect_nomatch &&
838
@@ -44,35 +74,12 @@ test_expect_success 'log --author -i' '
4474
test_cmp expect_second actual
4575
'
4676

47-
test_expect_success 'log -G (nomatch)' '
48-
git log -Gpicked --format=%H >actual &&
49-
test_cmp expect_nomatch actual
50-
'
51-
52-
test_expect_success 'log -G (match)' '
53-
git log -GPicked --format=%H >actual &&
54-
test_cmp expect_second actual
55-
'
56-
57-
test_expect_success 'log -G --regexp-ignore-case (nomatch)' '
58-
git log --regexp-ignore-case -Gpickle --format=%H >actual &&
59-
test_cmp expect_nomatch actual
60-
'
61-
62-
test_expect_success 'log -G -i (nomatch)' '
63-
git log -i -Gpickle --format=%H >actual &&
64-
test_cmp expect_nomatch actual
65-
'
66-
67-
test_expect_success 'log -G --regexp-ignore-case (match)' '
68-
git log --regexp-ignore-case -Gpicked --format=%H >actual &&
69-
test_cmp expect_second actual
70-
'
71-
72-
test_expect_success 'log -G -i (match)' '
73-
git log -i -Gpicked --format=%H >actual &&
74-
test_cmp expect_second actual
75-
'
77+
test_log expect_nomatch -G picked
78+
test_log expect_second -G Picked
79+
test_log expect_nomatch -G pickle --regexp-ignore-case
80+
test_log expect_nomatch -G pickle -i
81+
test_log expect_second -G picked --regexp-ignore-case
82+
test_log expect_second -G picked -i
7683

7784
test_expect_success 'log -G --textconv (missing textconv tool)' '
7885
echo "* diff=test" >.gitattributes &&
@@ -87,35 +94,12 @@ test_expect_success 'log -G --no-textconv (missing textconv tool)' '
8794
rm .gitattributes
8895
'
8996

90-
test_expect_success 'log -S (nomatch)' '
91-
git log -Spicked --format=%H >actual &&
92-
test_cmp expect_nomatch actual
93-
'
94-
95-
test_expect_success 'log -S (match)' '
96-
git log -SPicked --format=%H >actual &&
97-
test_cmp expect_second actual
98-
'
99-
100-
test_expect_success 'log -S --regexp-ignore-case (match)' '
101-
git log --regexp-ignore-case -Spicked --format=%H >actual &&
102-
test_cmp expect_second actual
103-
'
104-
105-
test_expect_success 'log -S -i (match)' '
106-
git log -i -Spicked --format=%H >actual &&
107-
test_cmp expect_second actual
108-
'
109-
110-
test_expect_success 'log -S --regexp-ignore-case (nomatch)' '
111-
git log --regexp-ignore-case -Spickle --format=%H >actual &&
112-
test_cmp expect_nomatch actual
113-
'
114-
115-
test_expect_success 'log -S -i (nomatch)' '
116-
git log -i -Spickle --format=%H >actual &&
117-
test_cmp expect_nomatch actual
118-
'
97+
test_log expect_nomatch -S picked
98+
test_log expect_second -S Picked
99+
test_log expect_second -S picked --regexp-ignore-case
100+
test_log expect_second -S picked -i
101+
test_log expect_nomatch -S pickle --regexp-ignore-case
102+
test_log expect_nomatch -S pickle -i
119103

120104
test_expect_success 'log -S --textconv (missing textconv tool)' '
121105
echo "* diff=test" >.gitattributes &&

0 commit comments

Comments
 (0)