t / t6030-bisect-porcelain.shon commit Merge branch 'ds/maint-deflatebound' (0380074)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Christian Couder
   4#
   5test_description='Tests git-bisect functionality'
   6
   7exec </dev/null
   8
   9. ./test-lib.sh
  10
  11add_line_into_file()
  12{
  13    _line=$1
  14    _file=$2
  15
  16    if [ -f "$_file" ]; then
  17        echo "$_line" >> $_file || return $?
  18        MSG="Add <$_line> into <$_file>."
  19    else
  20        echo "$_line" > $_file || return $?
  21        git add $_file || return $?
  22        MSG="Create file <$_file> with <$_line> inside."
  23    fi
  24
  25    test_tick
  26    git-commit --quiet -m "$MSG" $_file
  27}
  28
  29HASH1=
  30HASH2=
  31HASH3=
  32HASH4=
  33
  34test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
  35     add_line_into_file "1: Hello World" hello &&
  36     HASH1=$(git rev-parse --verify HEAD) &&
  37     add_line_into_file "2: A new day for git" hello &&
  38     HASH2=$(git rev-parse --verify HEAD) &&
  39     add_line_into_file "3: Another new day for git" hello &&
  40     HASH3=$(git rev-parse --verify HEAD) &&
  41     add_line_into_file "4: Ciao for now" hello &&
  42     HASH4=$(git rev-parse --verify HEAD)
  43'
  44
  45test_expect_success 'bisect starts with only one bad' '
  46        git bisect reset &&
  47        git bisect start &&
  48        git bisect bad $HASH4 &&
  49        git bisect next
  50'
  51
  52test_expect_success 'bisect does not start with only one good' '
  53        git bisect reset &&
  54        git bisect start &&
  55        git bisect good $HASH1 || return 1
  56
  57        if git bisect next
  58        then
  59                echo Oops, should have failed.
  60                false
  61        else
  62                :
  63        fi
  64'
  65
  66test_expect_success 'bisect start with one bad and good' '
  67        git bisect reset &&
  68        git bisect start &&
  69        git bisect good $HASH1 &&
  70        git bisect bad $HASH4 &&
  71        git bisect next
  72'
  73
  74# $HASH1 is good, $HASH4 is bad, we skip $HASH3
  75# but $HASH2 is bad,
  76# so we should find $HASH2 as the first bad commit
  77test_expect_success 'bisect skip: successfull result' '
  78        git bisect reset &&
  79        git bisect start $HASH4 $HASH1 &&
  80        git bisect skip &&
  81        git bisect bad > my_bisect_log.txt &&
  82        grep "$HASH2 is first bad commit" my_bisect_log.txt &&
  83        git bisect reset
  84'
  85
  86# $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
  87# so we should not be able to tell the first bad commit
  88# among $HASH2, $HASH3 and $HASH4
  89test_expect_success 'bisect skip: cannot tell between 3 commits' '
  90        git bisect start $HASH4 $HASH1 &&
  91        git bisect skip || return 1
  92
  93        if git bisect skip > my_bisect_log.txt
  94        then
  95                echo Oops, should have failed.
  96                false
  97        else
  98                test $? -eq 2 &&
  99                grep "first bad commit could be any of" my_bisect_log.txt &&
 100                ! grep $HASH1 my_bisect_log.txt &&
 101                grep $HASH2 my_bisect_log.txt &&
 102                grep $HASH3 my_bisect_log.txt &&
 103                grep $HASH4 my_bisect_log.txt &&
 104                git bisect reset
 105        fi
 106'
 107
 108# $HASH1 is good, $HASH4 is bad, we skip $HASH3
 109# but $HASH2 is good,
 110# so we should not be able to tell the first bad commit
 111# among $HASH3 and $HASH4
 112test_expect_success 'bisect skip: cannot tell between 2 commits' '
 113        git bisect start $HASH4 $HASH1 &&
 114        git bisect skip || return 1
 115
 116        if git bisect good > my_bisect_log.txt
 117        then
 118                echo Oops, should have failed.
 119                false
 120        else
 121                test $? -eq 2 &&
 122                grep "first bad commit could be any of" my_bisect_log.txt &&
 123                ! grep $HASH1 my_bisect_log.txt &&
 124                ! grep $HASH2 my_bisect_log.txt &&
 125                grep $HASH3 my_bisect_log.txt &&
 126                grep $HASH4 my_bisect_log.txt &&
 127                git bisect reset
 128        fi
 129'
 130
 131# We want to automatically find the commit that
 132# introduced "Another" into hello.
 133test_expect_success \
 134    '"git bisect run" simple case' \
 135    'echo "#"\!"/bin/sh" > test_script.sh &&
 136     echo "grep Another hello > /dev/null" >> test_script.sh &&
 137     echo "test \$? -ne 0" >> test_script.sh &&
 138     chmod +x test_script.sh &&
 139     git bisect start &&
 140     git bisect good $HASH1 &&
 141     git bisect bad $HASH4 &&
 142     git bisect run ./test_script.sh > my_bisect_log.txt &&
 143     grep "$HASH3 is first bad commit" my_bisect_log.txt &&
 144     git bisect reset'
 145
 146# We want to automatically find the commit that
 147# introduced "Ciao" into hello.
 148test_expect_success \
 149    '"git bisect run" with more complex "git bisect start"' \
 150    'echo "#"\!"/bin/sh" > test_script.sh &&
 151     echo "grep Ciao hello > /dev/null" >> test_script.sh &&
 152     echo "test \$? -ne 0" >> test_script.sh &&
 153     chmod +x test_script.sh &&
 154     git bisect start $HASH4 $HASH1 &&
 155     git bisect run ./test_script.sh > my_bisect_log.txt &&
 156     grep "$HASH4 is first bad commit" my_bisect_log.txt &&
 157     git bisect reset'
 158
 159# $HASH1 is good, $HASH5 is bad, we skip $HASH3
 160# but $HASH4 is good,
 161# so we should find $HASH5 as the first bad commit
 162HASH5=
 163test_expect_success 'bisect skip: add line and then a new test' '
 164        add_line_into_file "5: Another new line." hello &&
 165        HASH5=$(git rev-parse --verify HEAD) &&
 166        git bisect start $HASH5 $HASH1 &&
 167        git bisect skip &&
 168        git bisect good > my_bisect_log.txt &&
 169        grep "$HASH5 is first bad commit" my_bisect_log.txt &&
 170        git bisect log > log_to_replay.txt
 171        git bisect reset
 172'
 173
 174test_expect_success 'bisect skip and bisect replay' '
 175        git bisect replay log_to_replay.txt > my_bisect_log.txt &&
 176        grep "$HASH5 is first bad commit" my_bisect_log.txt &&
 177        git bisect reset
 178'
 179
 180HASH6=
 181test_expect_success 'bisect run & skip: cannot tell between 2' '
 182        add_line_into_file "6: Yet a line." hello &&
 183        HASH6=$(git rev-parse --verify HEAD) &&
 184        echo "#"\!"/bin/sh" > test_script.sh &&
 185        echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
 186        echo "grep line hello > /dev/null" >> test_script.sh &&
 187        echo "test \$? -ne 0" >> test_script.sh &&
 188        chmod +x test_script.sh &&
 189        git bisect start $HASH6 $HASH1 &&
 190        if git bisect run ./test_script.sh > my_bisect_log.txt
 191        then
 192                echo Oops, should have failed.
 193                false
 194        else
 195                test $? -eq 2 &&
 196                grep "first bad commit could be any of" my_bisect_log.txt &&
 197                ! grep $HASH3 my_bisect_log.txt &&
 198                ! grep $HASH6 my_bisect_log.txt &&
 199                grep $HASH4 my_bisect_log.txt &&
 200                grep $HASH5 my_bisect_log.txt
 201        fi
 202'
 203
 204HASH7=
 205test_expect_success 'bisect run & skip: find first bad' '
 206        git bisect reset &&
 207        add_line_into_file "7: Should be the last line." hello &&
 208        HASH7=$(git rev-parse --verify HEAD) &&
 209        echo "#"\!"/bin/sh" > test_script.sh &&
 210        echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
 211        echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh &&
 212        echo "grep Yet hello > /dev/null" >> test_script.sh &&
 213        echo "test \$? -ne 0" >> test_script.sh &&
 214        chmod +x test_script.sh &&
 215        git bisect start $HASH7 $HASH1 &&
 216        git bisect run ./test_script.sh > my_bisect_log.txt &&
 217        grep "$HASH6 is first bad commit" my_bisect_log.txt
 218'
 219
 220#
 221#
 222test_done