t3415: increase granularity of test_auto_{fixup,squash}()
We are using `test_must_fail test_auto_{fixup,squash}` which would ensure that the function failed. However, this is a little ham-fisted as there is no way of ensuring that the expected part of the function actually fails. Increase the granularity by accepting an optional `!` first argument which will check that the rebase does not squash in any commits by ensuring that there are still 4 commits. If `!` is not provided, the old logic is run. This patch may be better reviewed with `--ignore-all-space`. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Jan 6, 2020 at 23:53 UTC
c232ffa83cb3b21e4e6671c50609bfaf5659e899
1 file changed
+44
-20
t/t3415-rebase-autosquash.sh
+44
-20
@@ -25,6 +25,13 @@ test_expect_success setup '
25
'
26
27
test_auto_fixup () {
28
+ no_squash= &&
29
+ if test "x$1" = 'x!'
30
+ then
31
+ no_squash=true
32
+ shift
33
+ fi &&
34
+
35
git reset --hard base &&
36
echo 1 >file1 &&
37
git add -u &&
@@ -35,14 +42,19 @@ test_auto_fixup () {
42
test_tick &&
43
git rebase $2 -i HEAD^^^ &&
44
git log --oneline >actual &&
38
- test_line_count = 3 actual &&
39
- git diff --exit-code $1 &&
40
- echo 1 >expect &&
41
- git cat-file blob HEAD^:file1 >actual &&
42
- test_cmp expect actual &&
43
- git cat-file commit HEAD^ >commit &&
44
- grep first commit >actual &&
45
- test_line_count = 1 actual
45
+ if test -n "$no_squash"
46
+ then
47
+ test_line_count = 4 actual
48
+ else
49
+ test_line_count = 3 actual &&
50
+ git diff --exit-code $1 &&
51
+ echo 1 >expect &&
52
+ git cat-file blob HEAD^:file1 >actual &&
53
+ test_cmp expect actual &&
54
+ git cat-file commit HEAD^ >commit &&
55
+ grep first commit >actual &&
56
+ test_line_count = 1 actual
57
+ fi
58
}
59
60
test_expect_success 'auto fixup (option)' '
@@ -52,12 +64,19 @@ test_expect_success 'auto fixup (option)' '
64
test_expect_success 'auto fixup (config)' '
65
git config rebase.autosquash true &&
66
test_auto_fixup final-fixup-config-true &&
55
- test_must_fail test_auto_fixup fixup-config-true-no --no-autosquash &&
67
+ test_auto_fixup ! fixup-config-true-no --no-autosquash &&
68
git config rebase.autosquash false &&
57
- test_must_fail test_auto_fixup final-fixup-config-false
69
+ test_auto_fixup ! final-fixup-config-false
70
'
71
72
test_auto_squash () {
73
+ no_squash= &&
74
+ if test "x$1" = 'x!'
75
+ then
76
+ no_squash=true
77
+ shift
78
+ fi &&
79
+
80
git reset --hard base &&
81
echo 1 >file1 &&
82
git add -u &&
@@ -68,14 +87,19 @@ test_auto_squash () {
87
test_tick &&
88
git rebase $2 -i HEAD^^^ &&
89
git log --oneline >actual &&
71
- test_line_count = 3 actual &&
72
- git diff --exit-code $1 &&
73
- echo 1 >expect &&
74
- git cat-file blob HEAD^:file1 >actual &&
75
- test_cmp expect actual &&
76
- git cat-file commit HEAD^ >commit &&
77
- grep first commit >actual &&
78
- test_line_count = 2 actual
90
+ if test -n "$no_squash"
91
+ then
92
+ test_line_count = 4 actual
93
+ else
94
+ test_line_count = 3 actual &&
95
+ git diff --exit-code $1 &&
96
+ echo 1 >expect &&
97
+ git cat-file blob HEAD^:file1 >actual &&
98
+ test_cmp expect actual &&
99
+ git cat-file commit HEAD^ >commit &&
100
+ grep first commit >actual &&
101
+ test_line_count = 2 actual
102
+ fi
103
}
104
105
test_expect_success 'auto squash (option)' '
@@ -85,9 +109,9 @@ test_expect_success 'auto squash (option)' '
109
test_expect_success 'auto squash (config)' '
110
git config rebase.autosquash true &&
111
test_auto_squash final-squash-config-true &&
88
- test_must_fail test_auto_squash squash-config-true-no --no-autosquash &&
112
+ test_auto_squash ! squash-config-true-no --no-autosquash &&
113
git config rebase.autosquash false &&
90
- test_must_fail test_auto_squash final-squash-config-false
114
+ test_auto_squash ! final-squash-config-false
115
'
116
117
test_expect_success 'misspelled auto squash' '