Skip to content

Commit 2c873f9

Browse files
committed
Merge branch 'ab/tests-various-fixup'
Various test updates. * ab/tests-various-fixup: rm tests: actually test for SIGPIPE in SIGPIPE test archive tests: use a cheaper "zipinfo -h" invocation to get header upload-pack tests: avoid a non-zero "grep" exit status git-svn tests: rewrite brittle tests to use "--[no-]merges". git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty git svn mergeinfo tests: modernize redirection & quoting style cache-tree tests: explicitly test HEAD and index differences cache-tree tests: use a sub-shell with less indirection cache-tree tests: remove unused $2 parameter cache-tree tests: refactor for modern test style
2 parents f011795 + db89a82 commit 2c873f9

File tree

5 files changed

+80
-67
lines changed

5 files changed

+80
-67
lines changed

t/t0090-cache-tree.sh

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,36 @@ cache-tree extension.
1010
cmp_cache_tree () {
1111
test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
1212
sed "s/$OID_REGEX/SHA/" <actual >filtered &&
13-
test_cmp "$1" filtered
13+
test_cmp "$1" filtered &&
14+
rm filtered
1415
}
1516

1617
# We don't bother with actually checking the SHA1:
1718
# test-tool dump-cache-tree already verifies that all existing data is
1819
# correct.
19-
generate_expected_cache_tree_rec () {
20-
dir="$1${1:+/}" &&
21-
parent="$2" &&
22-
# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
23-
# We want to count only foo because it's the only direct child
24-
git ls-files >files &&
25-
subtrees=$(grep / files|cut -d / -f 1|uniq) &&
26-
subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
27-
entries=$(wc -l <files) &&
28-
printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
29-
for subtree in $subtrees
30-
do
31-
cd "$subtree"
32-
generate_expected_cache_tree_rec "$dir$subtree" "$dir" || return 1
33-
cd ..
34-
done &&
35-
dir=$parent
36-
}
37-
3820
generate_expected_cache_tree () {
39-
(
40-
generate_expected_cache_tree_rec
41-
)
21+
pathspec="$1" &&
22+
dir="$2${2:+/}" &&
23+
git ls-tree --name-only HEAD -- "$pathspec" >files &&
24+
git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees &&
25+
printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) &&
26+
while read subtree
27+
do
28+
generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1
29+
done <subtrees
4230
}
4331

4432
test_cache_tree () {
45-
generate_expected_cache_tree >expect &&
46-
cmp_cache_tree expect
33+
generate_expected_cache_tree "." >expect &&
34+
cmp_cache_tree expect &&
35+
rm expect actual files subtrees &&
36+
git status --porcelain -- ':!status' ':!expected.status' >status &&
37+
if test -n "$1"
38+
then
39+
test_cmp "$1" status
40+
else
41+
test_must_be_empty status
42+
fi
4743
}
4844

4945
test_invalid_cache_tree () {
@@ -54,7 +50,7 @@ test_invalid_cache_tree () {
5450
}
5551

5652
test_no_cache_tree () {
57-
: >expect &&
53+
>expect &&
5854
cmp_cache_tree expect
5955
}
6056

@@ -83,28 +79,27 @@ test_expect_success 'git-add in subdir invalidates cache-tree' '
8379
test_invalid_cache_tree
8480
'
8581

86-
cat >before <<\EOF
87-
SHA (3 entries, 2 subtrees)
88-
SHA dir1/ (1 entries, 0 subtrees)
89-
SHA dir2/ (1 entries, 0 subtrees)
90-
EOF
91-
92-
cat >expect <<\EOF
93-
invalid (2 subtrees)
94-
invalid dir1/ (0 subtrees)
95-
SHA dir2/ (1 entries, 0 subtrees)
96-
EOF
97-
9882
test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' '
9983
git tag no-children &&
10084
test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
10185
mkdir dir1 dir2 &&
10286
test_commit dir1/a &&
10387
test_commit dir2/b &&
10488
echo "I changed this file" >dir1/a &&
89+
test_when_finished "rm before" &&
90+
cat >before <<-\EOF &&
91+
SHA (3 entries, 2 subtrees)
92+
SHA dir1/ (1 entries, 0 subtrees)
93+
SHA dir2/ (1 entries, 0 subtrees)
94+
EOF
10595
cmp_cache_tree before &&
10696
echo "I changed this file" >dir1/a &&
10797
git add dir1/a &&
98+
cat >expect <<-\EOF &&
99+
invalid (2 subtrees)
100+
invalid dir1/ (0 subtrees)
101+
SHA dir2/ (1 entries, 0 subtrees)
102+
EOF
108103
cmp_cache_tree expect
109104
'
110105

@@ -133,6 +128,7 @@ test_expect_success 'second commit has cache-tree' '
133128
'
134129

135130
test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' '
131+
test_when_finished "git reset --hard" &&
136132
cat <<-\EOT >foo.c &&
137133
int foo()
138134
{
@@ -159,7 +155,10 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
159155
EOT
160156
test_write_lines p 1 "" s n y q |
161157
git commit --interactive -m foo &&
162-
test_cache_tree
158+
cat <<-\EOF >expected.status &&
159+
M foo.c
160+
EOF
161+
test_cache_tree expected.status
163162
'
164163

165164
test_expect_success PERL 'commit -p with shrinking cache-tree' '
@@ -250,7 +249,10 @@ test_expect_success 'partial commit gives cache-tree' '
250249
git add one.t &&
251250
echo "some other change" >two.t &&
252251
git commit two.t -m partial &&
253-
test_cache_tree
252+
cat <<-\EOF >expected.status &&
253+
M one.t
254+
EOF
255+
test_cache_tree expected.status
254256
'
255257

256258
test_expect_success 'no phantom error when switching trees' '

t/t3600-rm.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
243243
test_path_is_missing frotz/nitfol
244244
'
245245

246-
test_expect_success 'choking "git rm" should not let it die with cruft' '
246+
choke_git_rm_setup() {
247247
git reset -q --hard &&
248248
test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
249249
i=0 &&
@@ -252,12 +252,24 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
252252
do
253253
echo "100644 $hash 0 some-file-$i"
254254
i=$(( $i + 1 ))
255-
done | git update-index --index-info &&
255+
done | git update-index --index-info
256+
}
257+
258+
test_expect_success 'choking "git rm" should not let it die with cruft (induce SIGPIPE)' '
259+
choke_git_rm_setup &&
256260
# git command is intentionally placed upstream of pipe to induce SIGPIPE
257261
git rm -n "some-file-*" | : &&
258262
test_path_is_missing .git/index.lock
259263
'
260264

265+
266+
test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
267+
choke_git_rm_setup &&
268+
OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
269+
test_match_signal 13 "$OUT" &&
270+
test_path_is_missing .git/index.lock
271+
'
272+
261273
test_expect_success 'Resolving by removal is not a warning-worthy event' '
262274
git reset -q --hard &&
263275
test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&

t/t5004-archive-corner-cases.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
153153
154154
# check the number of entries in the ZIP file directory
155155
expr 65536 + 256 >expect &&
156-
"$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual &&
156+
"$ZIPINFO" -h many.zip >zipinfo &&
157+
sed -n "2s/.* //p" <zipinfo >actual &&
157158
test_cmp expect actual
158159
'
159160

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ get_actual_commits () {
1919
test-tool pkt-line unpack-sideband <out >o.pack &&
2020
git index-pack o.pack &&
2121
git verify-pack -v o.idx >objs &&
22-
grep commit objs | cut -d" " -f1 | sort >actual_commits
22+
sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs >objs.sed &&
23+
sort >actual_commits <objs.sed
2324
}
2425

2526
check_output () {

t/t9151-svn-mergeinfo.sh

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,46 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1212

1313
test_expect_success 'load svn dump' "
1414
svnadmin load -q '$rawsvnrepo' \
15-
< '$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' &&
15+
<'$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' &&
1616
git svn init --minimize-url -R svnmerge \
1717
--rewrite-root=http://svn.example.org \
1818
-T trunk -b branches '$svnrepo' &&
1919
git svn fetch --all
20-
"
20+
"
2121

2222
test_expect_success 'all svn merges became git merge commits' '
23-
unmarked=$(git rev-list --parents --all --grep=Merge |
24-
grep -v " .* " | cut -f1 -d" ") &&
25-
[ -z "$unmarked" ]
26-
'
23+
git rev-list --all --no-merges --grep=Merge >unmarked &&
24+
test_must_be_empty unmarked
25+
'
2726

2827
test_expect_success 'cherry picks did not become git merge commits' '
29-
bad_cherries=$(git rev-list --parents --all --grep=Cherry |
30-
grep " .* " | cut -f1 -d" ") &&
31-
[ -z "$bad_cherries" ]
32-
'
28+
git rev-list --all --merges --grep=Cherry >bad-cherries &&
29+
test_must_be_empty bad-cherries
30+
'
3331

3432
test_expect_success 'svn non-merge merge commits did not become git merge commits' '
35-
bad_non_merges=$(git rev-list --parents --all --grep=non-merge |
36-
grep " .* " | cut -f1 -d" ") &&
37-
[ -z "$bad_non_merges" ]
38-
'
33+
git rev-list --all --merges --grep=non-merge >bad-non-merges &&
34+
test_must_be_empty bad-non-merges
35+
'
3936

4037
test_expect_success 'commit made to merged branch is reachable from the merge' '
4138
before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") &&
4239
merge_commit=$(git rev-list --all --grep="Merge trunk to b2") &&
43-
not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) &&
44-
[ -z "$not_reachable" ]
45-
'
40+
git rev-list -1 $before_commit --not $merge_commit >not-reachable &&
41+
test_must_be_empty not-reachable
42+
'
4643

4744
test_expect_success 'merging two branches in one commit is detected correctly' '
4845
f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") &&
4946
f2_commit=$(git rev-list --all --grep="make f2 branch from trunk") &&
5047
merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") &&
51-
not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) &&
52-
[ -z "$not_reachable" ]
53-
'
48+
git rev-list -1 $f1_commit $f2_commit --not $merge_commit >not-reachable &&
49+
test_must_be_empty not-reachable
50+
'
5451

5552
test_expect_failure 'everything got merged in the end' '
56-
unmerged=$(git rev-list --all --not main) &&
57-
[ -z "$unmerged" ]
58-
'
53+
git rev-list --all --not main >unmerged &&
54+
test_must_be_empty unmerged
55+
'
5956

6057
test_done

0 commit comments

Comments
 (0)