t1002: stop using sum(1)

sum(1) is a command for calculating checksums of the contents of files. It was part of early editions of Unix ("Research Unix", 1972/1973, [1]). cksum(1) appeared in 4.4BSD (1993) as a replacement [2], and became part of POSIX.1-2008 [3]. OpenBSD 5.6 (2014) removed sum(1). We only use sum(1) in t1002 to check for changes in three files. On MinGW we use md5sum(1) instead. We could switch to the standard command cksum(1) for all platforms; MinGW comes with GNU coreutils now, which provides sum(1), cksum(1) and md5sum(1). Use our standard method for checking for file changes instead: test_cmp. It's more convenient because it shows differences nicely, it's faster on MinGW because we have a special implementation there based only on shell-internal commands, it's simpler as it allows us to avoid stripping out unnecessary entries from the checksum file using grep(1), and it's more consistent with the rest of the test suite. We already compare changed files with their expected new contents using diff(1), so we don't need to check with "test_must_fail test_cmp" if they differ from their original state. A later patch could convert the direct diff(1) calls to test_cmp as well. With all sum(1) calls gone, remove the MinGW-specific implementation from test-lib.sh as well. [1] http://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man1/sum.1 [2] http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/share/man/cat1/cksum.0 [3] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cksum.html Signed-off-by: René Scharfe <l.s.r@web.de> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 14, 2017 at 22:16 UTC 70ec6bd63bdfe5f08481e88d423592b55ccfbf65
2 files changed +35 -35
t/t1002-read-tree-m-u-2way.sh
+35 -32
@@ -51,7 +51,9 @@ test_expect_success \
51 treeM=$(git write-tree) &&
52 echo treeM $treeM &&
53 git ls-tree $treeM &&
54 - sum bozbar frotz nitfol >M.sum &&
54 + cp bozbar bozbar.M &&
55 + cp frotz frotz.M &&
56 + cp nitfol nitfol.M &&
57 git diff-tree $treeH $treeM'
58
59 test_expect_success \
@@ -61,8 +63,9 @@ test_expect_success \
63 read_tree_u_must_succeed -m -u $treeH $treeM &&
64 git ls-files --stage >1-3.out &&
65 cmp M.out 1-3.out &&
64 - sum bozbar frotz nitfol >actual3.sum &&
65 - cmp M.sum actual3.sum &&
66 + test_cmp bozbar.M bozbar &&
67 + test_cmp frotz.M frotz &&
68 + test_cmp nitfol.M nitfol &&
69 check_cache_at bozbar clean &&
70 check_cache_at frotz clean &&
71 check_cache_at nitfol clean'
@@ -79,8 +82,9 @@ test_expect_success \
82 test_might_fail git diff -U0 --no-index M.out 4.out >4diff.out &&
83 compare_change 4diff.out expected &&
84 check_cache_at yomin clean &&
82 - sum bozbar frotz nitfol >actual4.sum &&
83 - cmp M.sum actual4.sum &&
85 + test_cmp bozbar.M bozbar &&
86 + test_cmp frotz.M frotz &&
87 + test_cmp nitfol.M nitfol &&
88 echo yomin >yomin1 &&
89 diff yomin yomin1 &&
90 rm -f yomin1'
@@ -98,8 +102,9 @@ test_expect_success \
102 test_might_fail git diff -U0 --no-index M.out 5.out >5diff.out &&
103 compare_change 5diff.out expected &&
104 check_cache_at yomin dirty &&
101 - sum bozbar frotz nitfol >actual5.sum &&
102 - cmp M.sum actual5.sum &&
105 + test_cmp bozbar.M bozbar &&
106 + test_cmp frotz.M frotz &&
107 + test_cmp nitfol.M nitfol &&
108 : dirty index should have prevented -u from checking it out. &&
109 echo yomin yomin >yomin1 &&
110 diff yomin yomin1 &&
@@ -115,8 +120,9 @@ test_expect_success \
120 git ls-files --stage >6.out &&
121 test_cmp M.out 6.out &&
122 check_cache_at frotz clean &&
118 - sum bozbar frotz nitfol >actual3.sum &&
119 - cmp M.sum actual3.sum &&
123 + test_cmp bozbar.M bozbar &&
124 + test_cmp frotz.M frotz &&
125 + test_cmp nitfol.M nitfol &&
126 echo frotz >frotz1 &&
127 diff frotz frotz1 &&
128 rm -f frotz1'
@@ -132,8 +138,8 @@ test_expect_success \
138 git ls-files --stage >7.out &&
139 test_cmp M.out 7.out &&
140 check_cache_at frotz dirty &&
135 - sum bozbar frotz nitfol >actual7.sum &&
136 - if cmp M.sum actual7.sum; then false; else :; fi &&
141 + test_cmp bozbar.M bozbar &&
142 + test_cmp nitfol.M nitfol &&
143 : dirty index should have prevented -u from checking it out. &&
144 echo frotz frotz >frotz1 &&
145 diff frotz frotz1 &&
@@ -165,8 +171,10 @@ test_expect_success \
171 read_tree_u_must_succeed -m -u $treeH $treeM &&
172 git ls-files --stage >10.out &&
173 cmp M.out 10.out &&
168 - sum bozbar frotz nitfol >actual10.sum &&
169 - cmp M.sum actual10.sum'
174 + test_cmp bozbar.M bozbar &&
175 + test_cmp frotz.M frotz &&
176 + test_cmp nitfol.M nitfol
177 +'
178
179 test_expect_success \
180 '11 - dirty path removed.' \
@@ -209,11 +217,8 @@ test_expect_success \
217 git ls-files --stage >14.out &&
218 test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
219 compare_change 14diff.out expected &&
212 - sum bozbar frotz >actual14.sum &&
213 - grep -v nitfol M.sum > expected14.sum &&
214 - cmp expected14.sum actual14.sum &&
215 - sum bozbar frotz nitfol >actual14a.sum &&
216 - if cmp M.sum actual14a.sum; then false; else :; fi &&
220 + test_cmp bozbar.M bozbar &&
221 + test_cmp frotz.M frotz &&
222 check_cache_at nitfol clean &&
223 echo nitfol nitfol >nitfol1 &&
224 diff nitfol nitfol1 &&
@@ -231,11 +236,8 @@ test_expect_success \
236 test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
237 compare_change 15diff.out expected &&
238 check_cache_at nitfol dirty &&
234 - sum bozbar frotz >actual15.sum &&
235 - grep -v nitfol M.sum > expected15.sum &&
236 - cmp expected15.sum actual15.sum &&
237 - sum bozbar frotz nitfol >actual15a.sum &&
238 - if cmp M.sum actual15a.sum; then false; else :; fi &&
239 + test_cmp bozbar.M bozbar &&
240 + test_cmp frotz.M frotz &&
241 echo nitfol nitfol nitfol >nitfol1 &&
242 diff nitfol nitfol1 &&
243 rm -f nitfol1'
@@ -267,8 +269,10 @@ test_expect_success \
269 git ls-files --stage >18.out &&
270 test_cmp M.out 18.out &&
271 check_cache_at bozbar clean &&
270 - sum bozbar frotz nitfol >actual18.sum &&
271 - cmp M.sum actual18.sum'
272 + test_cmp bozbar.M bozbar &&
273 + test_cmp frotz.M frotz &&
274 + test_cmp nitfol.M nitfol
275 +'
276
277 test_expect_success \
278 '19 - local change already having a good result, further modified.' \
@@ -281,11 +285,8 @@ test_expect_success \
285 git ls-files --stage >19.out &&
286 test_cmp M.out 19.out &&
287 check_cache_at bozbar dirty &&
284 - sum frotz nitfol >actual19.sum &&
285 - grep -v bozbar M.sum > expected19.sum &&
286 - cmp expected19.sum actual19.sum &&
287 - sum bozbar frotz nitfol >actual19a.sum &&
288 - if cmp M.sum actual19a.sum; then false; else :; fi &&
288 + test_cmp frotz.M frotz &&
289 + test_cmp nitfol.M nitfol &&
290 echo gnusto gnusto >bozbar1 &&
291 diff bozbar bozbar1 &&
292 rm -f bozbar1'
@@ -300,8 +301,10 @@ test_expect_success \
301 git ls-files --stage >20.out &&
302 test_cmp M.out 20.out &&
303 check_cache_at bozbar clean &&
303 - sum bozbar frotz nitfol >actual20.sum &&
304 - cmp M.sum actual20.sum'
304 + test_cmp bozbar.M bozbar &&
305 + test_cmp frotz.M frotz &&
306 + test_cmp nitfol.M nitfol
307 +'
308
309 test_expect_success \
310 '21 - no local change, dirty cache.' \
t/test-lib.sh
-3
@@ -975,9 +975,6 @@ case $(uname -s) in
975 find () {
976 /usr/bin/find "$@"
977 }
978 - sum () {
979 - md5sum "$@"
980 - }
978 # git sees Windows-style pwd
979 pwd () {
980 builtin pwd -W