]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6030-bisect-run.sh
t6030: add a bit more tests to git-bisect
[thirdparty/git.git] / t / t6030-bisect-run.sh
CommitLineData
a17c4101
CC
1#!/bin/sh
2#
3# Copyright (c) 2007 Christian Couder
4#
4f506716 5test_description='Tests git-bisect functionality'
a17c4101
CC
6
7. ./test-lib.sh
8
9add_line_into_file()
10{
11 _line=$1
12 _file=$2
13
14 if [ -f "$_file" ]; then
15 echo "$_line" >> $_file || return $?
16 MSG="Add <$_line> into <$_file>."
17 else
18 echo "$_line" > $_file || return $?
19 git add $_file || return $?
20 MSG="Create file <$_file> with <$_line> inside."
21 fi
22
23 git-commit -m "$MSG" $_file
24}
25
26HASH1=
27HASH3=
28HASH4=
29
30test_expect_success \
31 'set up basic repo with 1 file (hello) and 4 commits' \
32 'add_line_into_file "1: Hello World" hello &&
33 add_line_into_file "2: A new day for git" hello &&
34 add_line_into_file "3: Another new day for git" hello &&
35 add_line_into_file "4: Ciao for now" hello &&
36 HASH1=$(git rev-list HEAD | tail -1) &&
37 HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
38 HASH4=$(git rev-list HEAD | head -1)'
39
4f506716
JH
40test_expect_success 'bisect does not start with only one bad' '
41 git bisect reset &&
42 git bisect start &&
43 git bisect bad $HASH4 || return 1
44
45 if git bisect next
46 then
47 echo Oops, should have failed.
48 false
49 else
50 :
51 fi
52'
53
54test_expect_success 'bisect does not start with only one good' '
55 git bisect reset &&
56 git bisect start &&
57 git bisect good $HASH1 || return 1
58
59 if git bisect next
60 then
61 echo Oops, should have failed.
62 false
63 else
64 :
65 fi
66'
67
68test_expect_success 'bisect start with one bad and good' '
69 git bisect reset &&
70 git bisect start &&
71 git bisect good $HASH1 &&
72 git bisect bad $HASH4 &&
73 git bisect next
74'
75
a17c4101
CC
76# We want to automatically find the commit that
77# introduced "Another" into hello.
78test_expect_success \
38a47fd6
CC
79 '"git bisect run" simple case' \
80 'echo "#"\!"/bin/sh" > test_script.sh &&
a17c4101
CC
81 echo "grep Another hello > /dev/null" >> test_script.sh &&
82 echo "test \$? -ne 0" >> test_script.sh &&
83 chmod +x test_script.sh &&
84 git bisect start &&
85 git bisect good $HASH1 &&
86 git bisect bad $HASH4 &&
87 git bisect run ./test_script.sh > my_bisect_log.txt &&
38a47fd6
CC
88 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
89 git bisect reset'
90
91# We want to automatically find the commit that
92# introduced "Ciao" into hello.
93test_expect_success \
94 '"git bisect run" with more complex "git bisect start"' \
95 'echo "#"\!"/bin/sh" > test_script.sh &&
96 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
97 echo "test \$? -ne 0" >> test_script.sh &&
98 chmod +x test_script.sh &&
99 git bisect start $HASH4 $HASH1 &&
100 git bisect run ./test_script.sh > my_bisect_log.txt &&
101 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
102 git bisect reset'
a17c4101
CC
103
104#
105#
106test_done
107