Skip to content

Commit db7b9e3

Browse files
committed
t4008: modernise style
Update this ancient test script to a more modern style in which the expected result is prepared inside the body of the test that uses it. Also, instead of using $tree, a shell variable, throughout the test script, create a tag that points at it, to make it easier to manually debug the test script in its trash directory. Signed-off-by: Junio C Hamano <[email protected]>
1 parent bd9150b commit db7b9e3

File tree

1 file changed

+126
-160
lines changed

1 file changed

+126
-160
lines changed

t/t4008-diff-break-rewrite.sh

Lines changed: 126 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -24,165 +24,131 @@ Further, with -B and -M together, these should turn into two renames.
2424
. ./test-lib.sh
2525
. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
2626

27-
test_expect_success \
28-
setup \
29-
'cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
30-
cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
31-
git update-index --add file0 file1 &&
32-
tree=$(git write-tree) &&
33-
echo "$tree"'
34-
35-
test_expect_success \
36-
'change file1 with copy-edit of file0 and remove file0' \
37-
'sed -e "s/git/GIT/" file0 >file1 &&
38-
rm -f file0 &&
39-
git update-index --remove file0 file1'
40-
41-
test_expect_success \
42-
'run diff with -B' \
43-
'git diff-index -B --cached "$tree" >current'
44-
45-
cat >expected <<\EOF
46-
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
47-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
48-
EOF
49-
50-
test_expect_success \
51-
'validate result of -B (#1)' \
52-
'compare_diff_raw expected current'
53-
54-
test_expect_success \
55-
'run diff with -B and -M' \
56-
'git diff-index -B -M "$tree" >current'
57-
58-
cat >expected <<\EOF
59-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
60-
EOF
61-
62-
test_expect_success \
63-
'validate result of -B -M (#2)' \
64-
'compare_diff_raw expected current'
65-
66-
test_expect_success \
67-
'swap file0 and file1' \
68-
'rm -f file0 file1 &&
69-
git read-tree -m $tree &&
70-
git checkout-index -f -u -a &&
71-
mv file0 tmp &&
72-
mv file1 file0 &&
73-
mv tmp file1 &&
74-
git update-index file0 file1'
75-
76-
test_expect_success \
77-
'run diff with -B' \
78-
'git diff-index -B "$tree" >current'
79-
80-
cat >expected <<\EOF
81-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
82-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
83-
EOF
84-
85-
test_expect_success \
86-
'validate result of -B (#3)' \
87-
'compare_diff_raw expected current'
88-
89-
test_expect_success \
90-
'run diff with -B and -M' \
91-
'git diff-index -B -M "$tree" >current'
92-
93-
cat >expected <<\EOF
94-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
95-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
96-
EOF
97-
98-
test_expect_success \
99-
'validate result of -B -M (#4)' \
100-
'compare_diff_raw expected current'
101-
102-
test_expect_success \
103-
'make file0 into something completely different' \
104-
'rm -f file0 &&
105-
test_ln_s_add frotz file0 &&
106-
git update-index file1'
107-
108-
test_expect_success \
109-
'run diff with -B' \
110-
'git diff-index -B "$tree" >current'
111-
112-
cat >expected <<\EOF
113-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
114-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
115-
EOF
116-
117-
test_expect_success \
118-
'validate result of -B (#5)' \
119-
'compare_diff_raw expected current'
120-
121-
test_expect_success \
122-
'run diff with -B -M' \
123-
'git diff-index -B -M "$tree" >current'
124-
125-
# file0 changed from regular to symlink. file1 is very close to the preimage of file0.
126-
# the change does not make file0 disappear, so file1 is denoted as a copy of file0
127-
cat >expected <<\EOF
128-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
129-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
130-
EOF
131-
132-
test_expect_success \
133-
'validate result of -B -M (#6)' \
134-
'compare_diff_raw expected current'
135-
136-
test_expect_success \
137-
'run diff with -M' \
138-
'git diff-index -M "$tree" >current'
139-
140-
# This should not mistake file0 as the copy source of new file1
141-
# due to type differences.
142-
cat >expected <<\EOF
143-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
144-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
145-
EOF
146-
147-
test_expect_success \
148-
'validate result of -M (#7)' \
149-
'compare_diff_raw expected current'
150-
151-
test_expect_success \
152-
'file1 edited to look like file0 and file0 rename-edited to file2' \
153-
'rm -f file0 file1 &&
154-
git read-tree -m $tree &&
155-
git checkout-index -f -u -a &&
156-
sed -e "s/git/GIT/" file0 >file1 &&
157-
sed -e "s/git/GET/" file0 >file2 &&
158-
rm -f file0 &&
159-
git update-index --add --remove file0 file1 file2'
160-
161-
test_expect_success \
162-
'run diff with -B' \
163-
'git diff-index -B "$tree" >current'
164-
165-
cat >expected <<\EOF
166-
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
167-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
168-
:000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
169-
EOF
170-
171-
test_expect_success \
172-
'validate result of -B (#8)' \
173-
'compare_diff_raw expected current'
174-
175-
test_expect_success \
176-
'run diff with -B -C' \
177-
'git diff-index -B -C "$tree" >current'
178-
179-
cat >expected <<\EOF
180-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
181-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
182-
EOF
183-
184-
test_expect_success \
185-
'validate result of -B -M (#9)' \
186-
'compare_diff_raw expected current'
27+
test_expect_success setup '
28+
cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
29+
cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
30+
git update-index --add file0 file1 &&
31+
git tag reference $(git write-tree)
32+
'
33+
34+
test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
35+
sed -e "s/git/GIT/" file0 >file1 &&
36+
rm -f file0 &&
37+
git update-index --remove file0 file1
38+
'
39+
40+
test_expect_success 'run diff with -B (#1)' '
41+
git diff-index -B --cached reference >current &&
42+
cat >expect <<-\EOF &&
43+
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
44+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
45+
EOF
46+
compare_diff_raw expect current
47+
'
48+
49+
test_expect_success 'run diff with -B and -M (#2)' '
50+
git diff-index -B -M reference >current &&
51+
cat >expect <<-\EOF &&
52+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
53+
EOF
54+
compare_diff_raw expect current
55+
'
56+
57+
test_expect_success 'swap file0 and file1' '
58+
rm -f file0 file1 &&
59+
git read-tree -m reference &&
60+
git checkout-index -f -u -a &&
61+
mv file0 tmp &&
62+
mv file1 file0 &&
63+
mv tmp file1 &&
64+
git update-index file0 file1
65+
'
66+
67+
test_expect_success 'run diff with -B (#3)' '
68+
git diff-index -B reference >current &&
69+
cat >expect <<-\EOF &&
70+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
71+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
72+
EOF
73+
compare_diff_raw expect current
74+
'
75+
76+
test_expect_success 'run diff with -B and -M (#4)' '
77+
git diff-index -B -M reference >current &&
78+
cat >expect <<-\EOF &&
79+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
80+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
81+
EOF
82+
compare_diff_raw expect current
83+
'
84+
85+
test_expect_success 'make file0 into something completely different' '
86+
rm -f file0 &&
87+
test_ln_s_add frotz file0 &&
88+
git update-index file1
89+
'
90+
91+
test_expect_success 'run diff with -B (#5)' '
92+
git diff-index -B reference >current &&
93+
cat >expect <<-\EOF &&
94+
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
95+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
96+
EOF
97+
compare_diff_raw expect current
98+
'
99+
100+
test_expect_success 'run diff with -B -M (#6)' '
101+
git diff-index -B -M reference >current &&
102+
103+
# file0 changed from regular to symlink. file1 is the same as the preimage
104+
# of file0. Because the change does not make file0 disappear, file1 is
105+
# denoted as a copy of file0
106+
cat >expect <<-\EOF &&
107+
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
108+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
109+
EOF
110+
compare_diff_raw expect current
111+
'
112+
113+
test_expect_success 'run diff with -M (#7)' '
114+
git diff-index -M reference >current &&
115+
116+
# This should not mistake file0 as the copy source of new file1
117+
# due to type differences.
118+
cat >expect <<-\EOF &&
119+
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
120+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
121+
EOF
122+
compare_diff_raw expect current
123+
'
124+
125+
test_expect_success 'file1 edited to look like file0 and file0 rename-edited to file2' '
126+
rm -f file0 file1 &&
127+
git read-tree -m reference &&
128+
git checkout-index -f -u -a &&
129+
sed -e "s/git/GIT/" file0 >file1 &&
130+
sed -e "s/git/GET/" file0 >file2 &&
131+
rm -f file0 &&
132+
git update-index --add --remove file0 file1 file2
133+
'
134+
135+
test_expect_success 'run diff with -B (#8)' '
136+
git diff-index -B reference >current &&
137+
cat >expect <<-\EOF &&
138+
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
139+
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
140+
:000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
141+
EOF
142+
compare_diff_raw expect current
143+
'
144+
145+
test_expect_success 'run diff with -B -C (#9)' '
146+
git diff-index -B -C reference >current &&
147+
cat >expect <<-\EOF &&
148+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
149+
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
150+
EOF
151+
compare_diff_raw expect current
152+
'
187153

188154
test_done

0 commit comments

Comments
 (0)