t6019: modernize tests with helper
The tests in t6019 are repetitive, so create a helper that greatly simplifies the test script. In addition, update the common pattern that places 'git rev-list' on the left side of a pipe, which can hide some exit codes. Send the output to a 'raw' file that is then consumed by other tools so the Git exit code is verified as zero. And since we're using --format anyway, switch to `git log`, so that we get the desired format and can avoid using sed. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Elijah Newren <newren@gmail.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Aug 19, 2022 at 04:28 UTC
1838e21cff17f97900a4987b35ba70ca48bce4b7
1 file changed
+25
-62
t/t6019-rev-list-ancestry-path.sh
+25
-62
@@ -50,73 +50,36 @@ test_expect_success setup '
50
test_commit M
51
'
52
53
-test_expect_success 'rev-list D..M' '
54
- test_write_lines E F G H I J K L M >expect &&
55
- git rev-list --format=%s D..M |
56
- sed -e "/^commit /d" |
57
- sort >actual &&
58
- test_cmp expect actual
59
-'
60
-
61
-test_expect_success 'rev-list --ancestry-path D..M' '
62
- test_write_lines E F H I J L M >expect &&
63
- git rev-list --ancestry-path --format=%s D..M |
64
- sed -e "/^commit /d" |
65
- sort >actual &&
66
- test_cmp expect actual
67
-'
68
-
69
-test_expect_success 'rev-list D..M -- M.t' '
70
- echo M >expect &&
71
- git rev-list --format=%s D..M -- M.t |
72
- sed -e "/^commit /d" >actual &&
73
- test_cmp expect actual
74
-'
75
-
76
-test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
77
- echo M >expect &&
78
- git rev-list --ancestry-path --format=%s D..M -- M.t |
79
- sed -e "/^commit /d" >actual &&
80
- test_cmp expect actual
81
-'
53
+test_ancestry () {
54
+ args=$1
55
+ expected=$2
56
+ test_expect_success "log $args" "
57
+ test_write_lines $expected >expect &&
58
+ git log --format=%s $args >raw &&
59
+
60
+ if test -n \"$expected\"
61
+ then
62
+ sort raw >actual &&
63
+ test_cmp expect actual
64
+ else
65
+ test_must_be_empty raw
66
+ fi
67
+ "
68
+}
69
83
-test_expect_success 'rev-list F...I' '
84
- test_write_lines F G H I >expect &&
85
- git rev-list --format=%s F...I |
86
- sed -e "/^commit /d" |
87
- sort >actual &&
88
- test_cmp expect actual
89
-'
70
+test_ancestry "D..M" "E F G H I J K L M"
71
91
-test_expect_success 'rev-list --ancestry-path F...I' '
92
- test_write_lines F H I >expect &&
93
- git rev-list --ancestry-path --format=%s F...I |
94
- sed -e "/^commit /d" |
95
- sort >actual &&
96
- test_cmp expect actual
97
-'
72
+test_ancestry "--ancestry-path D..M" "E F H I J L M"
73
99
-# G.t is dropped in an "-s ours" merge
100
-test_expect_success 'rev-list G..M -- G.t' '
101
- git rev-list --format=%s G..M -- G.t |
102
- sed -e "/^commit /d" >actual &&
103
- test_must_be_empty actual
104
-'
74
+test_ancestry "D..M -- M.t" "M"
75
+test_ancestry "--ancestry-path D..M -- M.t" "M"
76
106
-test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
107
- echo L >expect &&
108
- git rev-list --ancestry-path --format=%s G..M -- G.t |
109
- sed -e "/^commit /d" >actual &&
110
- test_cmp expect actual
111
-'
77
+test_ancestry "F...I" "F G H I"
78
+test_ancestry "--ancestry-path F...I" "F H I"
79
113
-test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' '
114
- test_write_lines G L >expect &&
115
- git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t |
116
- sed -e "/^commit /d" |
117
- sort >actual &&
118
- test_cmp expect actual
119
-'
80
+test_ancestry "G..M -- G.t" ""
81
+test_ancestry "--ancestry-path G..M -- G.t" "L"
82
+test_ancestry "--ancestry-path --simplify-merges G^..M -- G.t" "G L"
83
84
# b---bc
85
# / \ /