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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Mar 22, 2014 at 18:15 UTC 57b6dc76f28544737b5aa6bddafa2ee5f42047d1
1 file changed +42 -58
t/t4209-log-pickaxe.sh
+42 -58
@@ -3,6 +3,36 @@
3 test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
4 . ./test-lib.sh
5
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 +
36 test_expect_success setup '
37 >expect_nomatch &&
38
@@ -44,35 +74,12 @@ test_expect_success 'log --author -i' '
74 test_cmp expect_second actual
75 '
76
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
83
84 test_expect_success 'log -G --textconv (missing textconv tool)' '
85 echo "* diff=test" >.gitattributes &&
@@ -87,35 +94,12 @@ test_expect_success 'log -G --no-textconv (missing textconv tool)' '
94 rm .gitattributes
95 '
96
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
103
104 test_expect_success 'log -S --textconv (missing textconv tool)' '
105 echo "* diff=test" >.gitattributes &&