t / t4054-diff-bogus-tree.shon commit t: use test_expect_code instead of hand-rolled comparison (c21fc9d)
   1#!/bin/sh
   2
   3test_description='test diff with a bogus tree containing the null sha1'
   4. ./test-lib.sh
   5
   6empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
   7
   8test_expect_success 'create bogus tree' '
   9        bogus_tree=$(
  10                printf "100644 fooQQQQQQQQQQQQQQQQQQQQQ" |
  11                q_to_nul |
  12                git hash-object -w --stdin -t tree
  13        )
  14'
  15
  16test_expect_success 'create tree with matching file' '
  17        echo bar >foo &&
  18        git add foo &&
  19        good_tree=$(git write-tree) &&
  20        blob=$(git rev-parse :foo)
  21'
  22
  23test_expect_success 'raw diff shows null sha1 (addition)' '
  24        echo ":000000 100644 $_z40 $_z40 A      foo" >expect &&
  25        git diff-tree $empty_tree $bogus_tree >actual &&
  26        test_cmp expect actual
  27'
  28
  29test_expect_success 'raw diff shows null sha1 (removal)' '
  30        echo ":100644 000000 $_z40 $_z40 D      foo" >expect &&
  31        git diff-tree $bogus_tree $empty_tree >actual &&
  32        test_cmp expect actual
  33'
  34
  35test_expect_success 'raw diff shows null sha1 (modification)' '
  36        echo ":100644 100644 $blob $_z40 M      foo" >expect &&
  37        git diff-tree $good_tree $bogus_tree >actual &&
  38        test_cmp expect actual
  39'
  40
  41test_expect_success 'raw diff shows null sha1 (other direction)' '
  42        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  43        git diff-tree $bogus_tree $good_tree >actual &&
  44        test_cmp expect actual
  45'
  46
  47test_expect_success 'raw diff shows null sha1 (reverse)' '
  48        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  49        git diff-tree -R $good_tree $bogus_tree >actual &&
  50        test_cmp expect actual
  51'
  52
  53test_expect_success 'raw diff shows null sha1 (index)' '
  54        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  55        git diff-index $bogus_tree >actual &&
  56        test_cmp expect actual
  57'
  58
  59test_expect_success 'patch fails due to bogus sha1 (addition)' '
  60        test_must_fail git diff-tree -p $empty_tree $bogus_tree
  61'
  62
  63test_expect_success 'patch fails due to bogus sha1 (removal)' '
  64        test_must_fail git diff-tree -p $bogus_tree $empty_tree
  65'
  66
  67test_expect_success 'patch fails due to bogus sha1 (modification)' '
  68        test_must_fail git diff-tree -p $good_tree $bogus_tree
  69'
  70
  71test_expect_success 'patch fails due to bogus sha1 (other direction)' '
  72        test_must_fail git diff-tree -p $bogus_tree $good_tree
  73'
  74
  75test_expect_success 'patch fails due to bogus sha1 (reverse)' '
  76        test_must_fail git diff-tree -R -p $good_tree $bogus_tree
  77'
  78
  79test_expect_success 'patch fails due to bogus sha1 (index)' '
  80        test_must_fail git diff-index -p $bogus_tree
  81'
  82
  83test_done