t / t6030-bisect-porcelain.shon commit Merge branch 'maint' (34c6dbd)
   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# We want to automatically find the commit that
  75# introduced "Another" into hello.
  76test_expect_success \
  77    '"git bisect run" simple case' \
  78    'echo "#"\!"/bin/sh" > test_script.sh &&
  79     echo "grep Another hello > /dev/null" >> test_script.sh &&
  80     echo "test \$? -ne 0" >> test_script.sh &&
  81     chmod +x test_script.sh &&
  82     git bisect start &&
  83     git bisect good $HASH1 &&
  84     git bisect bad $HASH4 &&
  85     git bisect run ./test_script.sh > my_bisect_log.txt &&
  86     grep "$HASH3 is first bad commit" my_bisect_log.txt &&
  87     git bisect reset'
  88
  89# We want to automatically find the commit that
  90# introduced "Ciao" into hello.
  91test_expect_success \
  92    '"git bisect run" with more complex "git bisect start"' \
  93    'echo "#"\!"/bin/sh" > test_script.sh &&
  94     echo "grep Ciao hello > /dev/null" >> test_script.sh &&
  95     echo "test \$? -ne 0" >> test_script.sh &&
  96     chmod +x test_script.sh &&
  97     git bisect start $HASH4 $HASH1 &&
  98     git bisect run ./test_script.sh > my_bisect_log.txt &&
  99     grep "$HASH4 is first bad commit" my_bisect_log.txt &&
 100     git bisect reset'
 101
 102#
 103#
 104test_done