commit-graph tests: split up corrupt_graph_and_verify()

Split up the corrupt_graph_and_verify() function added in d9b9f8a6fd ("commit-graph: verify catches corrupt signature", 2018-06-27) into its logical components of setting up the test itself, doing the corruption in a particular way with "dd", and then finally testing that stderr is what we expect. This allows for re-using everything except the now slimmer corrupt_graph_and_verify() to corrupt the graph in a way that doesn't involve inserting a given byte sequence at a given position, e.g. truncating it entirely to a custom value. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 21, 2019 at 23:37 UTC f6761faaa17a98c025b34fffeeec71f0ec223b2d
1 file changed +16 -6
t/t5318-commit-graph.sh
+16 -6
@@ -366,6 +366,19 @@ GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
366 GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
367 GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
368
369 +corrupt_graph_setup() {
370 + cd "$TRASH_DIRECTORY/full" &&
371 + test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
372 + cp $objdir/info/commit-graph commit-graph-backup
373 +}
374 +
375 +corrupt_graph_verify() {
376 + grepstr=$1
377 + test_must_fail git commit-graph verify 2>test_err &&
378 + grep -v "^+" test_err >err &&
379 + test_i18ngrep "$grepstr" err
380 +}
381 +
382 # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
383 # Manipulates the commit-graph file at the position
384 # by inserting the data, optionally zeroing the file
@@ -376,17 +389,14 @@ corrupt_graph_and_verify() {
389 pos=$1
390 data="${2:-\0}"
391 grepstr=$3
379 - cd "$TRASH_DIRECTORY/full" &&
392 + corrupt_graph_setup &&
393 orig_size=$(wc -c < $objdir/info/commit-graph) &&
394 zero_pos=${4:-${orig_size}} &&
382 - test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
383 - cp $objdir/info/commit-graph commit-graph-backup &&
395 printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
396 dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" count=0 &&
397 generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
387 - test_must_fail git commit-graph verify 2>test_err &&
388 - grep -v "^+" test_err >err &&
389 - test_i18ngrep "$grepstr" err
398 + corrupt_graph_verify "$grepstr"
399 +
400 }
401
402 test_expect_success 'detect bad signature' '